From 1420904ffb95f83205f4a0ef060a67a79a5b18b0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 10:52:09 -0300 Subject: [PATCH 1/8] extracting is_space is_sign fucntions from argv_validation --- program_to_test/headers/push_swap.h | 3 +- program_to_test/src/ft_argv_utils.c | 27 +++++++++++ program_to_test/src/ft_argv_validation.c | 58 ++++++++++++------------ 3 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 program_to_test/src/ft_argv_utils.c diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 6f49d22..3ea7191 100644 --- a/program_to_test/headers/push_swap.h +++ b/program_to_test/headers/push_swap.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/08 15:23:33 by umeneses #+# #+# */ -/* Updated: 2024/06/26 12:21:53 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 10:54:56 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ bool ft_is_sign(int c); bool ft_is_space(int c); bool ft_argv_is_duplicated(char **argv); int ft_argv_size(char **argv); +bool ft_argv_signs_and_nbrs(char **argv); bool ft_argv_validation(char **argv); /* new functions for push_swap to be added in LIBFT */ diff --git a/program_to_test/src/ft_argv_utils.c b/program_to_test/src/ft_argv_utils.c new file mode 100644 index 0000000..c8f7154 --- /dev/null +++ b/program_to_test/src/ft_argv_utils.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_argv_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: umeneses +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/26 15:35:16 by umeneses #+# #+# */ +/* Updated: 2024/06/26 15:35:26 by umeneses ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +bool ft_is_sign(int c) +{ + if (c == '-' || c == '+') + return (true); + return (false); +} + +bool ft_is_space(int c) +{ + if (c == ' ') + return (true); + return (false); +} diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 9f56ebb..4f9c436 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,26 +6,12 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/06 18:33:04 by umeneses ### ########.fr */ +/* Updated: 2024/06/26 15:52:13 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -bool ft_is_sign(int c) -{ - if (c == '-' || c == '+') - return (true); - return (false); -} - -bool ft_is_space(int c) -{ - if (c == ' ') - return (true); - return (false); -} - int ft_argv_size(char **argv) { int size; @@ -62,30 +48,46 @@ bool ft_argv_is_duplicated(char **argv) return (false); } -bool ft_argv_validation(char **argv) +bool ft_argv_signs_and_nbrs(char **argv) { int index; index = 0; while (argv[++index] != NULL) - { + { if (ft_is_sign(*argv[index]) || ft_is_space(*argv[index])) - index++; - if (!ft_isdigit(*argv[index])) + index++; + if (!ft_isdigit(*argv[index])) + { + ft_error_msg("User's input must be numbers only\n"); + return (false); + } + } + return (true); +} + +bool ft_argv_validation(char **argv) +{ + int index; + int nbr; + + index = 0; + if (ft_argv_signs_and_nbrs(argv) == true) + { + while (argv[++index] != NULL) { - ft_error_msg("User's input must be numbers only\n"); - return (false); + nbr = ft_atoi(argv[index]); + if (nbr < INT_MIN || nbr > INT_MAX) + { + ft_error_msg("Number outside limits of 32-bit system\n"); + return (false); + } } - if (ft_atoi(argv[index]) < INT_MIN || ft_atoi(argv[index]) > INT_MAX) + if (ft_argv_is_duplicated(argv)) { - ft_error_msg("Number outside limits of 32-bit system\n"); + ft_error_msg("Duplicated items detected!\n"); return (false); } } - if (ft_argv_is_duplicated(argv)) - { - ft_error_msg("Duplicated items detected!\n"); - return (false); - } return (true); } From b9027dd54c589aac63f95a862809372590de28d6 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 12:58:36 -0300 Subject: [PATCH 2/8] redefining argv_validation structure --- program_to_test/src/ft_argv_validation.c | 48 +++++++++++------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 4f9c436..0ff9a44 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,11 +6,12 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/26 15:52:13 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 12:58:08 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" +#include int ft_argv_size(char **argv) { @@ -25,7 +26,7 @@ int ft_argv_size(char **argv) return (size - 1); } -bool ft_argv_is_duplicated(char **argv) +bool ft_argv_is_not_duplicated(char **argv) { int after_atoi; int index; @@ -42,10 +43,10 @@ bool ft_argv_is_duplicated(char **argv) while ((++future_pos <= ft_argv_size(argv)) && (future_pos != index)) { if (ft_atoi(compare[future_pos]) == after_atoi) - return (true); + return (false); } } - return (false); + return (true); } bool ft_argv_signs_and_nbrs(char **argv) @@ -57,37 +58,30 @@ bool ft_argv_signs_and_nbrs(char **argv) { if (ft_is_sign(*argv[index]) || ft_is_space(*argv[index])) index++; - if (!ft_isdigit(*argv[index])) - { - ft_error_msg("User's input must be numbers only\n"); + if (!ft_isdigit_long(*argv[index])) return (false); - } } return (true); } + + bool ft_argv_validation(char **argv) { - int index; - int nbr; - - index = 0; - if (ft_argv_signs_and_nbrs(argv) == true) + if (!ft_argv_signs_and_nbrs(argv)) { - while (argv[++index] != NULL) - { - nbr = ft_atoi(argv[index]); - if (nbr < INT_MIN || nbr > INT_MAX) - { - ft_error_msg("Number outside limits of 32-bit system\n"); - return (false); - } - } - if (ft_argv_is_duplicated(argv)) - { - ft_error_msg("Duplicated items detected!\n"); - return (false); - } + ft_error_msg("User's input must be numbers only\n"); + return (false); + } + if (!ft_argv_inside_range_intmin_intmax(argv)) + { + ft_error_msg("Number outside limits of 32-bit system\n"); + return (false); + } + if (!ft_argv_is_not_duplicated(argv)) + { + ft_error_msg("Duplicated items detected!\n"); + return (false); } return (true); } From 40487552115329bd028d376da857ab135a6638b7 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 14:34:17 -0300 Subject: [PATCH 3/8] adding ft_atoi for long int --- program_to_test/src/ft_argv_utils.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_argv_utils.c b/program_to_test/src/ft_argv_utils.c index c8f7154..f45d708 100644 --- a/program_to_test/src/ft_argv_utils.c +++ b/program_to_test/src/ft_argv_utils.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/26 15:35:16 by umeneses #+# #+# */ -/* Updated: 2024/06/26 15:35:26 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 14:33:27 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,3 +25,30 @@ bool ft_is_space(int c) return (true); return (false); } + +long int ft_atoi_long_int(const char *str) +{ + long int result; + int signal; + char *string; + + signal = 1; + string = (char *)str; + while (((*string >= 9 && *string <= 13) || *string == 32)) + string++; + while ((*string == '-') || (*string == '+')) + { + if (*(string + 1) == '-' || *(string + 1) == '+') + return (0); + if (*string == '-') + signal = signal * -1; + string++; + } + result = 0; + while (*string >= '0' && *string <= '9') + { + result = (result * 10) + (*string - '0'); + string++; + } + return (result * signal); +} From e26e3ba6e5d23a476dca7fc0664dacab0b8c57af Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 14:34:41 -0300 Subject: [PATCH 4/8] adding INT MAX validation --- program_to_test/src/ft_argv_validation.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 0ff9a44..5dde5cc 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,12 +6,11 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/27 12:58:08 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 14:33:32 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -#include int ft_argv_size(char **argv) { @@ -64,7 +63,24 @@ bool ft_argv_signs_and_nbrs(char **argv) return (true); } +bool ft_argv_inside_range_intmin_intmax(char **argv) +{ + long int index; + long int long_nbr; + char *long_nbr_as_str; + index = 0; + while (argv[++index] != NULL) + { + long_nbr = ft_atoi_long_int(argv[index]); + long_nbr_as_str = ft_itoa(long_nbr); + if (ft_strlen(argv[index]) != ft_strlen(long_nbr_as_str)) + return (false); + if (long_nbr < INT_MIN || long_nbr > INT_MAX) + return (false); + } + return (true); +} bool ft_argv_validation(char **argv) { From be5ec2da87d8cac2111e8c06aa9a0507697ccb32 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 14:47:25 -0300 Subject: [PATCH 5/8] adding atoi_long_int and fixing identation --- program_to_test/headers/push_swap.h | 136 ++++++++++++++-------------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 3ea7191..03b31ec 100644 --- a/program_to_test/headers/push_swap.h +++ b/program_to_test/headers/push_swap.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/08 15:23:33 by umeneses #+# #+# */ -/* Updated: 2024/06/27 10:54:56 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 14:17:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,84 +29,86 @@ typedef struct s_stack struct s_stack *next; } t_stack; -t_stack *ft_lst_init(int value); -t_stack *ft_lst_goto_end(t_stack *stack); -t_stack *ft_lst_goto_head(t_stack *stack); -t_stack *ft_lst_goto_before_end(t_stack *stack); -t_stack *ft_lst_addto_end(t_stack **stack, t_stack *new); -t_stack *ft_lst_addto_begin(t_stack **stack, t_stack *new); -t_stack *ft_lst_delat_begin(t_stack *stack); -t_stack *ft_lst_delat_end(t_stack *stack); -void ft_lstclear_double_ptr(t_stack **stack); -void ft_lstclear_single_ptr(t_stack *stack); -void ft_lst_printf_data_content(char *msg, t_stack *stack); -t_stack *ft_lts_buildstack_argv(t_stack **stack, char **argv); -bool ft_is_sign(int c); -bool ft_is_space(int c); -bool ft_argv_is_duplicated(char **argv); -int ft_argv_size(char **argv); -bool ft_argv_signs_and_nbrs(char **argv); -bool ft_argv_validation(char **argv); +t_stack *ft_lst_init(int value); +t_stack *ft_lst_goto_end(t_stack *stack); +t_stack *ft_lst_goto_head(t_stack *stack); +t_stack *ft_lst_goto_before_end(t_stack *stack); +t_stack *ft_lst_addto_end(t_stack **stack, t_stack *new); +t_stack *ft_lst_addto_begin(t_stack **stack, t_stack *new); +t_stack *ft_lst_delat_begin(t_stack *stack); +t_stack *ft_lst_delat_end(t_stack *stack); +void ft_lstclear_double_ptr(t_stack **stack); +void ft_lstclear_single_ptr(t_stack *stack); +void ft_lst_printf_data_content(char *msg, t_stack *stack); +t_stack *ft_lts_buildstack_argv(t_stack **stack, char **argv); +bool ft_is_sign(int c); +bool ft_is_space(int c); +bool ft_argv_is_not_duplicated(char **argv); +int ft_argv_size(char **argv); +bool ft_argv_signs_and_nbrs(char **argv); +long int ft_atoi_long_int(const char *str); +bool ft_argv_inside_range_intmin_intmax(char **argv); +bool ft_argv_validation(char **argv); /* new functions for push_swap to be added in LIBFT */ -int ft_lst_size(t_stack *stack); -void ft_swap(t_stack **stack); -void ft_swap_ab(t_stack **stack_a, t_stack **stack_b); -void ft_push_a(t_stack **stack_a, t_stack **stack_b); -void ft_push_b(t_stack **stack_a, t_stack **stack_b); -void ft_rotate(t_stack **stack); -void ft_rotate_ab(t_stack **stack_a, t_stack **stack_b); -void ft_reverse_rotate(t_stack **stack); -void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); +int ft_lst_size(t_stack *stack); +void ft_swap(t_stack **stack); +void ft_swap_ab(t_stack **stack_a, t_stack **stack_b); +void ft_push_a(t_stack **stack_a, t_stack **stack_b); +void ft_push_b(t_stack **stack_a, t_stack **stack_b); +void ft_rotate(t_stack **stack); +void ft_rotate_ab(t_stack **stack_a, t_stack **stack_b); +void ft_reverse_rotate(t_stack **stack); +void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); /* basic push_swap functions */ -bool ft_is_sorted(t_stack *stack); +bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ -int ft_lst_map_highest_pos(t_stack *list); -void ft_do_sort(t_stack **stack_a, t_stack **stack_b); -t_stack *ft_sort_two_nbrs(t_stack **stack); -t_stack *ft_sort_three_nbrs(t_stack **stack); +int ft_lst_map_highest_pos(t_stack *list); +void ft_do_sort(t_stack **stack_a, t_stack **stack_b); +t_stack *ft_sort_two_nbrs(t_stack **stack); +t_stack *ft_sort_three_nbrs(t_stack **stack); /* sorting functions if list has until 3 numbers */ -void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b); -void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b); -void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b); -int ft_lst_get_target(t_stack **stack_a, int b_end_pos, - int target_end_pos, int target_pos); -void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b); -void ft_lst_map_all_indexers(t_stack **stack); -void ft_lst_map_actual_position(t_stack **stack); -void ft_lst_map_final_pos(t_stack **stack, int stack_size); -int ft_lst_map_lowest_final_position(t_stack **stack); -void ft_lst_shift_stack(t_stack **stack_a); -void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b); -int abs_nbr(int nbr); -void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b); -void ft_do_move_after_cheapest(t_stack **stack_a, t_stack **stack_b, - int cost_a, int cost_b); +void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b); +void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b); +void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b); +int ft_lst_get_target(t_stack **stack_a, int b_end_pos, + int target_end_pos, int target_pos); +void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b); +void ft_lst_map_all_indexers(t_stack **stack); +void ft_lst_map_actual_position(t_stack **stack); +void ft_lst_map_final_pos(t_stack **stack, int stack_size); +int ft_lst_map_lowest_final_position(t_stack **stack); +void ft_lst_shift_stack(t_stack **stack_a); +void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b); +int abs_nbr(int nbr); +void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b); +void ft_do_move_after_cheapest(t_stack **stack_a, t_stack **stack_b, + int cost_a, int cost_b); /* sorting functions if list has 4 or more numbers */ -void ft_rev_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b, - int *cost_a, int *cost_b); -void ft_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b, - int *cost_a, int *cost_b); -void ft_rotate_a_with_cost(t_stack **stack_a, int *cost_a); -void ft_rotate_b_with_cost(t_stack **stack_b, int *cost_b); +void ft_rev_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b, + int *cost_a, int *cost_b); +void ft_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b, + int *cost_a, int *cost_b); +void ft_rotate_a_with_cost(t_stack **stack_a, int *cost_a); +void ft_rotate_b_with_cost(t_stack **stack_b, int *cost_b); /* sorting functions take takes the cheapest cost and do the move */ -void ft_do_swap_a(t_stack **stack); -void ft_do_swap_b(t_stack **stack); -void ft_do_swap_ab(t_stack **stack_a, t_stack **stack_b); -void ft_do_push_a(t_stack **stack_a, t_stack **stack_b); -void ft_do_push_b(t_stack **stack_a, t_stack **stack_b); -void ft_push(t_stack **source, t_stack **destiny); -void ft_do_rotate_a(t_stack **stack); -void ft_do_rotate_b(t_stack **stack); -void ft_do_rotate_ab(t_stack **stack_a, t_stack **stack_b); -void ft_do_reverse_rotate_a(t_stack **stack); -void ft_do_reverse_rotate_b(t_stack **stack); -void ft_do_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); +void ft_do_swap_a(t_stack **stack); +void ft_do_swap_b(t_stack **stack); +void ft_do_swap_ab(t_stack **stack_a, t_stack **stack_b); +void ft_do_push_a(t_stack **stack_a, t_stack **stack_b); +void ft_do_push_b(t_stack **stack_a, t_stack **stack_b); +void ft_push(t_stack **source, t_stack **destiny); +void ft_do_rotate_a(t_stack **stack); +void ft_do_rotate_b(t_stack **stack); +void ft_do_rotate_ab(t_stack **stack_a, t_stack **stack_b); +void ft_do_reverse_rotate_a(t_stack **stack); +void ft_do_reverse_rotate_b(t_stack **stack); +void ft_do_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); /* functions that call sorting and print the action on STDOUT */ #endif \ No newline at end of file From 89c0fb528b6e7844845b830398e1aa3635529b3c Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 16:59:16 -0300 Subject: [PATCH 6/8] fixing if negative numbers --- program_to_test/src/ft_argv_validation.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 5dde5cc..dd78b18 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/27 14:33:32 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 16:58:34 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,15 +50,18 @@ bool ft_argv_is_not_duplicated(char **argv) bool ft_argv_signs_and_nbrs(char **argv) { - int index; + int index; index = 0; while (argv[++index] != NULL) - { + { if (ft_is_sign(*argv[index]) || ft_is_space(*argv[index])) - index++; - if (!ft_isdigit_long(*argv[index])) + { + if (ft_is_sign(*(argv[index] + 1))) return (false); + if (!ft_isdigit(*(argv[index] + 1))) + return (false); + } } return (true); } From 451097c2cdd2006fee8c27a7aa2ee1aa8cb4a6ed Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 17:03:15 -0300 Subject: [PATCH 7/8] adding int-min and int-max tests --- _ci_tdd/Makefile | 4 +- _ci_tdd/test_files/test_main_miunit.c | 105 ++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 8 deletions(-) diff --git a/_ci_tdd/Makefile b/_ci_tdd/Makefile index 19f4c22..9009bbb 100644 --- a/_ci_tdd/Makefile +++ b/_ci_tdd/Makefile @@ -6,7 +6,7 @@ # By: umeneses +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/05/10 10:09:44 by umeneses #+# #+# # -# Updated: 2024/06/20 12:50:07 by umeneses ### ########.fr # +# Updated: 2024/06/27 17:02:35 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -75,7 +75,7 @@ COMP_EXE = $(CC) $(LDFLAGS) $(OBJ_FILES) $(LDLIBS) -o $(NAME) # **************************************************************************** # define arguments - 42 1 10 21 11 77 666 + 42 -2 10 -10 11 77 666 -2147483648 2147483647 endef define bonus diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 327297a..d3745f6 100644 --- a/_ci_tdd/test_files/test_main_miunit.c +++ b/_ci_tdd/test_files/test_main_miunit.c @@ -6,12 +6,13 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */ -/* Updated: 2024/06/26 14:06:06 by umeneses ### ########.fr */ +/* Updated: 2024/06/27 17:01:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "minunit.h" #include "push_swap.h" +#include "../../program_to_test/src/ft_argv_utils.c" #include "../../program_to_test/src/ft_argv_validation.c" #include "../../program_to_test/src/ft_lst_map_all.c" #include "../../program_to_test/src/ft_lst_map_indexers.c" @@ -36,7 +37,7 @@ // #include "minunit_utils.h" // TODO: -// make test for a list with 5 or more numbers +// make test for a list with 8 or more numbers // make test for negative numbers // make test for double or more signs (-- +++) @@ -961,6 +962,94 @@ MU_TEST(test_buildstack_argv) ft_array_clear(argv_simulation, expected_size); } +MU_TEST(test_argv_inside_range_intmin_intmax_outside_int_min) +{ + // ARRANGE + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int expected; + int result; + + // ACT + userinput = "./push_swap 1 4 3 2 -2147483649 12 9"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected = false; + + result = ft_argv_inside_range_intmin_intmax(argv_simulation); + + // ASSERT + mu_assert_int_eq(expected, result); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_argv_inside_range_intmin_intmax_inside_int_min) +{ + // ARRANGE + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int expected; + int result; + + // ACT + userinput = "./push_swap 1 4 3 2 -2147483648 12 9"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected = true; + + result = ft_argv_inside_range_intmin_intmax(argv_simulation); + + // ASSERT + mu_assert_int_eq(expected, result); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_argv_inside_range_intmin_intmax_outside_int_max) +{ + // ARRANGE + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int expected; + int result; + + // ACT + userinput = "./push_swap 1 4 3 2 2147483649 12 9"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected = false; + + result = ft_argv_inside_range_intmin_intmax(argv_simulation); + + // ASSERT + mu_assert_int_eq(expected, result); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_argv_inside_range_intmin_intmax_inside_int_max) +{ + // ARRANGE + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int expected; + int result; + + // ACT + userinput = "./push_swap 1 4 3 2 2147483647 12 9"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected = true; + + result = ft_argv_inside_range_intmin_intmax(argv_simulation); + + // ASSERT + mu_assert_int_eq(expected, result); + ft_array_clear(argv_simulation, expected_size); +} + MU_TEST(test_argv_is_duplicated_true) { // ARRANGE @@ -974,8 +1063,8 @@ MU_TEST(test_argv_is_duplicated_true) userinput = "./push_swap 1 2 3 4 5 6 7 8 2 9"; argv_simulation = ft_split(userinput, ' '); expected_size = ft_minunit_array_counter(argv_simulation); - actual_result = ft_argv_is_duplicated(argv_simulation); - expected_result = true; + actual_result = ft_argv_is_not_duplicated(argv_simulation); + expected_result = false; // ASSERT mu_assert_int_eq(expected_result, actual_result); @@ -995,8 +1084,8 @@ MU_TEST(test_argv_is_duplicated_false) userinput = "./push_swap 1 2 3 4 5 6 7 8"; argv_simulation = ft_split(userinput, ' '); expected_size = ft_minunit_array_counter(argv_simulation); - actual_result = ft_argv_is_duplicated(argv_simulation); - expected_result = false; + actual_result = ft_argv_is_not_duplicated(argv_simulation); + expected_result = true; // ASSERT mu_assert_int_eq(expected_result, actual_result); @@ -1697,6 +1786,10 @@ MU_TEST_SUITE(argv_tests) MU_RUN_TEST(test_argv_size); MU_RUN_TEST(test_argv_is_duplicated_false); MU_RUN_TEST(test_argv_is_duplicated_true); + MU_RUN_TEST(test_argv_inside_range_intmin_intmax_inside_int_min); + MU_RUN_TEST(test_argv_inside_range_intmin_intmax_outside_int_min); + MU_RUN_TEST(test_argv_inside_range_intmin_intmax_inside_int_max); + MU_RUN_TEST(test_argv_inside_range_intmin_intmax_outside_int_max); MU_RUN_TEST(test_buildstack_argv); MU_RUN_TEST(test_buildstack_non_nbr); } From f1f24a207e61f8574a6dc793487acc2b7a4822b7 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 27 Jun 2024 17:04:03 -0300 Subject: [PATCH 8/8] moving functions into argv_utils --- program_to_test/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/program_to_test/Makefile b/program_to_test/Makefile index 4bdaa79..d62d5ee 100644 --- a/program_to_test/Makefile +++ b/program_to_test/Makefile @@ -6,7 +6,7 @@ # By: umeneses +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/05/09 17:59:28 by umeneses #+# #+# # -# Updated: 2024/06/26 12:23:15 by umeneses ### ########.fr # +# Updated: 2024/06/26 15:35:39 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -45,6 +45,7 @@ LIBS = $(LIBFT) NAME = push_swap SRC_FILES = push_main.c +SRC_FILES += ft_argv_utils.c SRC_FILES += ft_argv_validation.c SRC_FILES += ft_do_sort.c SRC_FILES += ft_do_push_fts.c