Cub3D/libft/tests/ft_string/ft_str/test_atoi.c
2024-11-08 19:37:30 +01:00

42 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
/* Updated: 2024/05/26 11:45:29 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
int test_atoi(void)
{
size_t i;
const int t_cases[] = {
0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, -1, -9,
-10, -99, -100, -999, -1000, -9999, -10000
};
const char *t_str[] = {
"0", "1", "9", "10", "99", "100", "999", "1000",
"9999", "10000", "-1", "-9", "-10", "-99", "-100", "-999", "-1000",
"-9999", "-10000"
};
i = 0;
while (i < sizeof(t_cases) / sizeof(t_cases[0]))
{
if (ft_atoi(t_str[i]) != t_cases[i])
return (i + 1);
i++;
}
if (ft_atoi(" --99") != 99 || ft_atoi(" -0") != 0 || \
ft_atoi(" -++--1") != -1)
return (30);
if (ft_atoi("toto") != 0 || ft_atoi("-toto") != 0 || ft_atoi("toto-") \
!= 0 || ft_atoi("a") != 0 || ft_atoi("01234\t56789") != 1234)
return (31);
return (0);
}