finish ft_atoi_base
This commit is contained in:
31
test.c
31
test.c
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/29 19:53:58 by tomoron #+# #+# */
|
||||
/* Updated: 2025/03/31 16:42:55 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/04/02 02:35:57 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -44,6 +44,7 @@ int ft_strcmp(char *dest, char *src);
|
||||
ssize_t ft_write(int fd, const void *buffer, size_t count);
|
||||
ssize_t ft_read(int fd, void *buffer, size_t count);
|
||||
char *ft_strdup(char *src);
|
||||
int ft_atoi_base(char *nbr, char *base);
|
||||
|
||||
int test_strlen(void)
|
||||
{
|
||||
@ -180,17 +181,33 @@ int test_strdup(void)
|
||||
return(nb_tests == passed);
|
||||
}
|
||||
|
||||
size_t check_base(char *base);
|
||||
int tmp(void)
|
||||
int test_atoi_base(void)
|
||||
{
|
||||
int nb_tests;
|
||||
int passed;
|
||||
|
||||
nb_tests = 4;
|
||||
nb_tests = 14;
|
||||
passed = 0;
|
||||
|
||||
TEST("a", check_base("a") == 1);
|
||||
TEST("a", check_base("abcdef") == 1);
|
||||
|
||||
TEST("normal number base 10", ft_atoi_base("42", "0123456789") == 42);
|
||||
TEST("normal number base 16", ft_atoi_base("1A4", "0123456789ABCDEF") == 420);
|
||||
TEST("normal number base 2", ft_atoi_base("101", "01") == 5);
|
||||
|
||||
TEST("0", ft_atoi_base("0", "0123456789") == 0);
|
||||
TEST("leading zeros", ft_atoi_base("0001", "0123456789") == 1);
|
||||
TEST("max 16-bit hex", ft_atoi_base("FFFF", "0123456789ABCDEF") == 65535);
|
||||
|
||||
TEST("empty number", ft_atoi_base("", "0123456789") == 0);
|
||||
TEST("empty base", ft_atoi_base("123", "") == 0);
|
||||
TEST("invalid digit in base", ft_atoi_base("42abc", "0123456789") == 42);
|
||||
TEST("duplicate characters in base", ft_atoi_base("123", "01234566789") == 0);
|
||||
|
||||
TEST("large number within int range", ft_atoi_base("2147483647", "0123456789") == 2147483647);
|
||||
TEST("negative number", ft_atoi_base("-42", "0123456789") == -42);
|
||||
|
||||
TEST("non-standard base ordering", ft_atoi_base("123", "9876543210") == 876);
|
||||
TEST("base 3", ft_atoi_base("321", "123") == 21);
|
||||
|
||||
return(nb_tests == passed);
|
||||
}
|
||||
@ -209,5 +226,5 @@ int main(void)
|
||||
printf("\n\n");
|
||||
FNC_TEST("ft_strdup", test_strdup());
|
||||
printf("\n\n");
|
||||
FNC_TEST("tmp", tmp());
|
||||
FNC_TEST("atoi_base", test_atoi_base());
|
||||
}
|
||||
|
Reference in New Issue
Block a user