From 6255f5e0a30da40514e9f5d4b446b83fbfaa1e09 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 5 Sep 2025 11:36:07 +0200 Subject: [PATCH 1/5] style(test/char): adding the last '\n' - For the last return line --- test/char/test_isalnum.c | 3 ++- test/char/test_isalpha.c | 3 ++- test/char/test_isascii.c | 3 ++- test/char/test_isprint.c | 3 ++- test/char/test_tolower.c | 3 ++- test/char/test_toupper.c | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/char/test_isalnum.c b/test/char/test_isalnum.c index dc937b6..79eabad 100644 --- a/test/char/test_isalnum.c +++ b/test/char/test_isalnum.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/04 18:50:17 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:24:26 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } diff --git a/test/char/test_isalpha.c b/test/char/test_isalpha.c index 4bffcc9..4776df3 100644 --- a/test/char/test_isalpha.c +++ b/test/char/test_isalpha.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 18:41:04 by rparodi #+# #+# */ -/* Updated: 2025/09/04 18:49:58 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:23:32 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } diff --git a/test/char/test_isascii.c b/test/char/test_isascii.c index 6fcc91c..ab19982 100644 --- a/test/char/test_isascii.c +++ b/test/char/test_isascii.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/05 10:40:18 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:24:19 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } diff --git a/test/char/test_isprint.c b/test/char/test_isprint.c index 62b4cff..8760283 100644 --- a/test/char/test_isprint.c +++ b/test/char/test_isprint.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/05 10:43:55 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:23:32 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } diff --git a/test/char/test_tolower.c b/test/char/test_tolower.c index e813887..4ddf289 100644 --- a/test/char/test_tolower.c +++ b/test/char/test_tolower.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/05 10:35:53 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:23:53 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } diff --git a/test/char/test_toupper.c b/test/char/test_toupper.c index 52e96ea..cb88e6b 100644 --- a/test/char/test_toupper.c +++ b/test/char/test_toupper.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/05 10:37:26 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 11:23:46 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,5 @@ int main(void) printf("%s✔%s ", CLR_GREEN, RESET); c++; } + puts("\n"); } From 0988a2c8ab41035debd8046d2d857011e9f14a12 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 5 Sep 2025 15:09:35 +0200 Subject: [PATCH 2/5] fix(convert/atoi): atoi was now working with NULL parameters - Now fixed by the verification before --- convert/ft_atoi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/convert/ft_atoi.c b/convert/ft_atoi.c index d7eccaa..ba63e8d 100644 --- a/convert/ft_atoi.c +++ b/convert/ft_atoi.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/08 17:22:41 by rparodi #+# #+# */ -/* Updated: 2025/09/04 11:39:58 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 14:34:51 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,8 @@ int ft_atoi(const char *nptr) int sign; int number; + if (!nptr) + return (0); i = 0; sign = ft_check_sign(nptr, &i); number = 0; From f4cb339be7b3a8216ee0e0b3418f196c0840af52 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 5 Sep 2025 15:09:52 +0200 Subject: [PATCH 3/5] fix(convert/atoll): atoll was now working with NULL parameters - Now fixed by the verification before --- convert/ft_atoll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/convert/ft_atoll.c b/convert/ft_atoll.c index 69ae348..bce4af4 100644 --- a/convert/ft_atoll.c +++ b/convert/ft_atoll.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 15:12:07 by rparodi #+# #+# */ -/* Updated: 2025/09/01 16:32:11 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 14:54:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,8 @@ long long int ft_atoll(const char *nptr) int sign; long long int number; + if (!nptr) + return (0); i = 0; sign = ft_check_sign(nptr, &i); number = 0; From aa8544ba0230aeb81ca83a7bcda2b7ae19c73467 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 5 Sep 2025 15:10:54 +0200 Subject: [PATCH 4/5] build(test): now test is building the libft before test --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 48cebd0..4aae38c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/09/04 18:48:57 by rparodi ### ########.fr # +# Updated: 2025/09/05 15:10:23 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -163,15 +163,15 @@ TEST_SRCS := $(shell find test -type f -name '*.c' 2>/dev/null) TEST_BINS := $(patsubst test/%.c,.test/%,$(TEST_SRCS)) -test: all $(LIB_NAME) $(TEST_BINS) test-run footer +test: fclean $(NAME) $(TEST_BINS) test-run footer .test/%: test/%.c $(LIB_NAME) @mkdir -p $(dir $@) @$(CC) $(CFLAGS) $(CPPFLAGS) $< -L. -lft $(LDFLAGS) -o $@ test-run: - @set -e; \ - for t in $(TEST_BINS); do \ + @set -e + @for t in $(TEST_BINS); do \ printf "\n\n$(GREY)>> Running $(GOLD)$$t$(END)\n"; \ TERM=xterm $$t; \ done; \ From 18f174b2a2c77f7b80a6afb07925fbf9216f87d9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 5 Sep 2025 15:12:40 +0200 Subject: [PATCH 5/5] test(convert): adding test to convert - adding test for atoi / atoll / itoa - Maybe a futur update to test atost (array to size_t) --- test/convert/test_atoi.c | 41 +++++++++++++++++++++++++++++++++++++ test/convert/test_atoll.c | 41 +++++++++++++++++++++++++++++++++++++ test/convert/test_itoa.c | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 test/convert/test_atoi.c create mode 100644 test/convert/test_atoll.c create mode 100644 test/convert/test_itoa.c diff --git a/test/convert/test_atoi.c b/test/convert/test_atoi.c new file mode 100644 index 0000000..d065a80 --- /dev/null +++ b/test/convert/test_atoi.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ +/* Updated: 2025/09/05 15:05:21 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "color.h" +#include "convert.h" +#include +#include +#include + +int main(void) +{ + const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648", + "2147483647"}; + size_t i; + + i = 0; + while (i < 7) + { + if (ft_atoi(str[i]) != atoi(str[i])) + { + dprintf(2, "%s✘ Found %i, expected %i%s\n", CLR_RED, + ft_atoi(str[i]), atoi(str[i]), RESET); + exit(1); + } + else + printf("%s✔%s ", CLR_GREEN, RESET); + i++; + } + ft_atoi(NULL); + printf("%s✔%s", CLR_GREEN, RESET); + puts("\n"); +} diff --git a/test/convert/test_atoll.c b/test/convert/test_atoll.c new file mode 100644 index 0000000..323e6a5 --- /dev/null +++ b/test/convert/test_atoll.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_atoll.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ +/* Updated: 2025/09/05 15:05:31 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "color.h" +#include "convert.h" +#include +#include +#include + +int main(void) +{ + const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648", + "2147483647", "9223372036854775807", "-9223372036854775808"}; + size_t i; + + i = 0; + while (i < 7) + { + if (ft_atoll(str[i]) != atoll(str[i])) + { + dprintf(2, "%s✘ Found %lli, expected %lli%s\n", CLR_RED, + ft_atoll(str[i]), atoll(str[i]), RESET); + exit(1); + } + else + printf("%s✔%s ", CLR_GREEN, RESET); + i++; + } + ft_atoll(NULL); + printf("%s✔%s", CLR_GREEN, RESET); + puts("\n"); +} diff --git a/test/convert/test_itoa.c b/test/convert/test_itoa.c new file mode 100644 index 0000000..8b1190c --- /dev/null +++ b/test/convert/test_itoa.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ +/* Updated: 2025/09/05 15:08:52 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "color.h" +#include "convert.h" +#include +#include +#include +#include + +int main(void) +{ + const int integer[] = {0, 42, -42, +-42, -2147483648, 2147483647}; + char result[1024]; + size_t i; + + i = 0; + while (i < 7) + { + sprintf(result, "%d", integer[i]); + if (strcmp(ft_itoa(integer[i]), result)) + { + dprintf(2, "%s✘ Found %s, expected %s%s\n", CLR_RED, + ft_itoa(integer[i]), result, RESET); + exit(1); + } + else + printf("%s✔%s ", CLR_GREEN, RESET); + i++; + } + ft_atoi(NULL); + printf("%s✔%s", CLR_GREEN, RESET); + puts("\n"); +}