82 lines
1.9 KiB
C
82 lines
1.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi_test.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/10/07 18:36:33 by lalgarra #+# #+# */
|
|
/* Updated: 2025/10/07 18:49:30 by lalgarra ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static void test(char *prefix, char buff[])
|
|
{
|
|
int res;
|
|
int fd;
|
|
|
|
fd = STDOUT_FILENO;
|
|
ft_putstr_fd(prefix, fd);
|
|
ft_putstr_fd("buff:[", fd);
|
|
ft_putstr_fd(buff, fd);
|
|
res = ft_atoi(buff);
|
|
ft_putstr_fd("], result:[", fd);
|
|
ft_putnbr_fd(res, fd);
|
|
ft_putendl_fd("]", fd);
|
|
}
|
|
|
|
static void zero(char buff[])
|
|
{
|
|
ft_bzero(buff, 128);
|
|
}
|
|
|
|
static void do_test1(char buff[])
|
|
{
|
|
zero(buff);
|
|
ft_strlcpy(buff, "+350", 4);
|
|
test("test 1: ", buff);
|
|
}
|
|
|
|
static void do_test2(char buff[])
|
|
{
|
|
zero(buff);
|
|
ft_strlcpy(buff, "+-50", 5);
|
|
test("test 2: ", buff);
|
|
}
|
|
|
|
static void do_test3(char buff[])
|
|
{
|
|
zero(buff);
|
|
ft_strlcpy(buff, " -3", 5);
|
|
test("test 3: ", buff);
|
|
}
|
|
|
|
static void do_test4(char buff[])
|
|
{
|
|
zero(buff);
|
|
ft_strlcpy(buff, " \t\v\f\r\n +1367442", 20);
|
|
test("test 4: ", buff);
|
|
}
|
|
|
|
static void do_test5(char buff[])
|
|
{
|
|
zero(buff);
|
|
ft_strlcpy(buff, " -+50", 5);
|
|
test("test 5: ", buff);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char buff[128];
|
|
|
|
do_test1(buff);
|
|
do_test2(buff);
|
|
do_test3(buff);
|
|
do_test4(buff);
|
|
do_test5(buff);
|
|
return (0);
|
|
}
|