diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 8b59734..b30e413 100644 --- a/_ci_tdd/test_files/test_main_miunit.c +++ b/_ci_tdd/test_files/test_main_miunit.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */ -/* Updated: 2024/07/01 11:14:31 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:47:24 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -459,7 +459,7 @@ MU_TEST(test_3rd_miastep_get_cost) actual_size = ft_lst_size(stack_a); ft_lst_map_all_indexers(&stack_a); ft_push_b_all_but_three(&stack_a, &stack_b); - ft_sort_three_nbrs(&stack_a); + ft_sort_a_with_three_nbrs(&stack_a); ft_lst_get_cost(&stack_a, &stack_b); actual_top_a = ft_lst_goto_head(stack_a)->nbr; actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; @@ -505,7 +505,7 @@ MU_TEST(test_3rd_miastep_map_get_target_position) expected_target_pos = 2; // should be stack_b->target actual_size = ft_lst_size(stack_a); ft_push_b_all_but_three(&stack_a, &stack_b); - ft_sort_three_nbrs(&stack_a); + ft_sort_a_with_three_nbrs(&stack_a); ft_lst_get_target_position(&stack_a, &stack_b); actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; @@ -815,7 +815,7 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_a) actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; ft_push_b_all_but_three(&stack_a, &stack_b); - ft_sort_three_nbrs(&stack_a); + ft_sort_a_with_three_nbrs(&stack_a); expected_top_a_after_push = ft_atoi(argv_simulation[6]); expected_bottom_a_after_push = ft_atoi(argv_simulation[5]); @@ -1021,7 +1021,7 @@ MU_TEST(test_sort_3_nbrs_already_sorted) expected_sorted_bottom = ft_atoi(argv_simulation[3]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; @@ -1056,7 +1056,7 @@ MU_TEST(test_sort_3_nbrs_highest_last) expected_sorted_bottom = ft_atoi(argv_simulation[3]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; @@ -1091,7 +1091,7 @@ MU_TEST(test_sort_3_nbrs_highest_first_v2) expected_sorted_bottom = ft_atoi(argv_simulation[1]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; @@ -1126,7 +1126,7 @@ MU_TEST(test_sort_3_nbrs_highest_first) expected_sorted_bottom = ft_atoi(argv_simulation[1]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; @@ -1161,7 +1161,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle_v2) expected_sorted_bottom = ft_atoi(argv_simulation[2]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; stack = ft_lst_goto_head(stack); @@ -1197,7 +1197,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle) expected_sorted_bottom = ft_atoi(argv_simulation[2]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); ft_lst_map_all_indexers(&stack); - stack = ft_sort_three_nbrs(&stack); + stack = ft_sort_a_with_three_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index dbdaea2..38c70a6 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/28 17:20:40 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:46:32 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,7 +69,7 @@ bool ft_is_sorted(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); +t_stack *ft_sort_a_with_three_nbrs(t_stack **stack_a); /* sorting functions if list has until 3 numbers */ void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b); diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 07d9918..bee417d 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/07/01 11:11:25 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:36:11 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,11 @@ bool ft_argv_valid_sign_and_not_alpha(char **argv) if (ft_isalpha(*(argv[index] + c_counter))) return (false); if (ft_is_sign(*(argv[index] + c_counter))) - if (ft_is_sign(*(argv[index] + c_counter + 1))) + { + if (ft_is_sign(*(argv[index] + c_counter + 1)) + || (*(argv[index] + c_counter + 1) == '\0')) return (false); + } c_counter++; } } diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index a6b0e79..5d40351 100644 --- a/program_to_test/src/ft_do_sort.c +++ b/program_to_test/src/ft_do_sort.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/06 18:46:55 by umeneses #+# #+# */ -/* Updated: 2024/06/26 14:01:57 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 11:58:52 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) if (stack_size == 2) ft_sort_two_nbrs(stack_a); else if (stack_size == 3) - ft_sort_three_nbrs(stack_a); + ft_sort_a_with_three_nbrs(stack_a); else { ft_sort_five_or_more_nbr(stack_a, stack_b); diff --git a/program_to_test/src/ft_sort_5_or_more.c b/program_to_test/src/ft_sort_5_or_more.c index 5d7778a..7671525 100644 --- a/program_to_test/src/ft_sort_5_or_more.c +++ b/program_to_test/src/ft_sort_5_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/26 14:01:00 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:46:58 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b) { ft_push_b_all_but_three(stack_a, stack_b); - ft_sort_three_nbrs(stack_a); + ft_sort_a_with_three_nbrs(stack_a); while (*stack_b) { ft_lst_get_target_position(stack_a, stack_b); diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index da99c2f..ad8f7c1 100644 --- a/program_to_test/src/ft_sort_until3.c +++ b/program_to_test/src/ft_sort_until3.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 12:19:14 by umeneses #+# #+# */ -/* Updated: 2024/06/26 14:02:16 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:46:17 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,21 +33,21 @@ t_stack *ft_sort_two_nbrs(t_stack **list) return (*list); } -t_stack *ft_sort_three_nbrs(t_stack **list) +t_stack *ft_sort_a_with_three_nbrs(t_stack **stack_a) { int highest_pos; - *list = ft_lst_goto_head(*list); - if (ft_is_sorted(*list)) - return (*list); - highest_pos = ft_lst_map_highest_pos(*list); - if ((*list)->final_pos == highest_pos) - ft_do_rotate_a(list); - else if ((*list)->next->final_pos == highest_pos) - ft_do_reverse_rotate_a(list); - if ((*list)->final_pos > (*list)->next->final_pos) - ft_do_swap_a(list); - return (*list); + *stack_a = ft_lst_goto_head(*stack_a); + if (ft_is_sorted(*stack_a)) + return (*stack_a); + highest_pos = ft_lst_map_highest_pos(*stack_a); + if ((*stack_a)->final_pos == highest_pos) + ft_do_rotate_a(stack_a); + else if ((*stack_a)->next->final_pos == highest_pos) + ft_do_reverse_rotate_a(stack_a); + if ((*stack_a)->final_pos > (*stack_a)->next->final_pos) + ft_do_swap_a(stack_a); + return (*stack_a); } int ft_lst_map_highest_pos(t_stack *list) diff --git a/program_to_test/src/ft_sort_until4.c b/program_to_test/src/ft_sort_until4.c index 115651c..761d898 100644 --- a/program_to_test/src/ft_sort_until4.c +++ b/program_to_test/src/ft_sort_until4.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/26 13:47:22 by umeneses ### ########.fr */ +/* Updated: 2024/07/01 12:46:21 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b) int highest_pos_b; ft_push_b_all_but_three(stack_a, stack_b); - ft_sort_three_nbrs(stack_a); + ft_sort_a_with_three_nbrs(stack_a); highest_pos_b = ft_lst_map_highest_pos(*stack_b); if ((*stack_b)->final_pos == highest_pos_b) {