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; \ 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; 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; 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"); } 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"); +}