diff --git a/Makefile b/Makefile index b29157b..19d7f0e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: lalgarra +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # -# Updated: 2025/10/07 18:08:12 by lalgarra ### ########.fr # +# Updated: 2025/10/07 18:46:48 by lalgarra ### ########.fr # # # # **************************************************************************** # @@ -22,7 +22,7 @@ TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \ ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test \ ft_memmove_test ft_strlcpy_test ft_strlcat_test ft_strchr_test \ ft_strrchr_test ft_strncmp_test ft_memcmp_test ft_strnstr_test \ - + ft_atoi_test %_test : %_test.c $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test diff --git a/ft_atoi_expected.output b/ft_atoi_expected.output new file mode 100644 index 0000000..81d4ad6 --- /dev/null +++ b/ft_atoi_expected.output @@ -0,0 +1,6 @@ +test 1: buff:[+35], result:[35] +test 2: buff:[+-50], result:[0] +test 3: buff:[ -3], result:[-3] +test 4: buff:[ + +1367442], result:[1367442] +test 5: buff:[ -+5], result:[0] diff --git a/ft_atoi_test.c b/ft_atoi_test.c new file mode 100644 index 0000000..1d17d5a --- /dev/null +++ b/ft_atoi_test.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_test.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lalgarra +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/07 18:36:33 by lalgarra #+# #+# */ +/* Updated: 2025/10/07 18:49:30 by lalgarra ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +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); +}