From 986b665e0a7734f449540f616ac0fb561eee068e Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 11:23:53 -0300 Subject: [PATCH 01/66] 1st mia step - adding map_position indexer --- _ci_tdd/test_files/test_main_miunit.c | 72 +++++++++++++++++++---- program_to_test/src/ft_lst_map_indexers.c | 72 +++++++++++++++++++++++ 2 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 program_to_test/src/ft_lst_map_indexers.c diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index a706458..bca7301 100644 --- a/_ci_tdd/test_files/test_main_miunit.c +++ b/_ci_tdd/test_files/test_main_miunit.c @@ -6,13 +6,14 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */ -/* Updated: 2024/06/10 09:55:28 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 11:23:05 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "minunit.h" #include "push_swap.h" #include "../../program_to_test/src/ft_argv_validation.c" +#include "../../program_to_test/src/ft_lst_map_indexers.c" #include "../../program_to_test/src/ft_lst_init.c" #include "../../program_to_test/src/ft_lst_goto.c" #include "../../program_to_test/src/ft_lst_addto.c" @@ -38,7 +39,54 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -MU_TEST(test_1st_miastep_index_nbrs) +// MU_TEST(test_1st_miastep_weight_index) +// { +// // ARRANGE +// t_stack *stack; +// char **argv_simulation = NULL; +// char *userinput; +// int expected_size; +// int actual_size; +// int expected_top_a; +// int actual_top_a; +// int expected_bottom_a; +// int actual_bottom_a; +// int expected_highest_weight; +// int actual_highest_weight; + +// // ACT +// stack = NULL; +// userinput = "./push_swap 2 42 0 4 8 3 31 27"; +// argv_simulation = ft_split(userinput, ' '); +// expected_size = ft_minunit_array_counter(argv_simulation); +// expected_top_a = ft_atoi(argv_simulation[1]); +// expected_bottom_a = ft_atoi(argv_simulation[8]); +// expected_highest_weight = expected_size; + +// stack = ft_lts_buildstack_argv(&stack, argv_simulation); + +// actual_size = ft_lst_size(stack); +// ft_lst_map_all_indexers(stack); +// actual_top_a = ft_lst_goto_head(stack)->nbr; +// actual_highest_weight = stack->next->weight; +// while (stack && stack->next != NULL) +// { +// ft_printf("nbr = %d\n", stack->nbr); +// ft_printf("nbr pos [%d] weigth = %d\n", stack->pos, stack->weight); +// stack = stack->next; +// } +// actual_bottom_a = ft_lst_goto_end(stack)->nbr; + +// // ASSERT +// mu_assert_int_eq(expected_highest_weight, actual_highest_weight); +// mu_assert_int_eq(expected_size, actual_size); +// mu_assert_int_eq(expected_top_a, actual_top_a); +// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); +// ft_lstclear_single_ptr(stack); +// ft_array_clear(argv_simulation, expected_size); +// } + +MU_TEST(test_1st_miastep_pos_index) { // ARRANGE t_stack *stack; @@ -50,8 +98,8 @@ MU_TEST(test_1st_miastep_index_nbrs) int actual_top_a; int expected_bottom_a; int actual_bottom_a; - int expected_highest_weight; - int actual_highest_weight; + int expected_fith_position; + int actual_fith_position; // ACT stack = NULL; @@ -60,24 +108,22 @@ MU_TEST(test_1st_miastep_index_nbrs) expected_size = ft_minunit_array_counter(argv_simulation); expected_top_a = ft_atoi(argv_simulation[1]); expected_bottom_a = ft_atoi(argv_simulation[8]); - expected_highest_weight = expected_size; + expected_fith_position = ft_atoi(argv_simulation[5]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); - ft_weight_mesurement(&stack); + ft_lst_map_position(stack); actual_top_a = ft_lst_goto_head(stack)->nbr; - while (stack && stack->next != NULL) + while (stack->pos <= 5) { - ft_printf("nbr = %d\n", stack->nbr); - ft_printf("weigth = %d\n", stack->weight); stack = stack->next; + if (stack->pos == 5) + actual_fith_position = stack->nbr; } - actual_highest_weight = stack->weight; actual_bottom_a = ft_lst_goto_end(stack)->nbr; - // ASSERT - mu_assert_int_eq(expected_highest_weight, actual_highest_weight); + mu_assert_int_eq(expected_fith_position, actual_fith_position); mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); @@ -1138,7 +1184,7 @@ MU_TEST_SUITE(sorting_tests) MU_TEST_SUITE(miacombeau_tests) { - MU_RUN_TEST(test_1st_miastep_index_nbrs); + MU_RUN_TEST(test_1st_miastep_pos_index); } int main(void) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c new file mode 100644 index 0000000..0233c35 --- /dev/null +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_map_indexers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: umeneses +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ +/* Updated: 2024/06/10 11:24:19 by umeneses ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void ft_lst_map_all_indexers(t_stack *stack) +{ + ft_lst_map_position(stack); + // ft_lst_map_weight(&stack); +} + +void ft_lst_map_position(t_stack *stack) +{ + int pos; + + pos = 0; + while (stack->next != NULL) + { + pos++; + (*stack).pos = pos; + stack = stack->next; + if (stack->next == NULL) + { + pos++; + (*stack).pos = pos; + } + } + stack = ft_lst_goto_head(stack); +} + +// void ft_lst_map_weight(t_stack **stack) +// { +// int weight; +// int target; +// int tocompare; +// t_stack *temp; + +// weight = 0; +// *stack = ft_lst_goto_head(*stack); +// temp = *stack; +// target = temp->nbr; +// tocompare = (*stack)->next->nbr; +// while ((temp != NULL) && (temp->next != NULL) && ((*stack)->next != NULL) +// && (weight <= ft_lst_size(*stack))) +// { +// while ((*stack)->next && (*stack)->next->nbr) +// { +// if (target > tocompare) +// weight++; +// (*stack)->weight = weight; +// if ((*stack)->next != NULL) +// { +// (*stack) = (*stack)->next; +// tocompare = (*stack)->nbr; +// ft_printf("tocompare = %d\n", tocompare); +// } +// } +// temp = temp->next; +// target = temp->nbr; +// ft_printf("(*stack)->weight = %d\n", (*stack)->weight); +// ft_printf("target nbr = %d\n", target); +// } +// } From 8c7f1e0c30dd25027c42e80991344508e53048c0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 11:30:36 -0300 Subject: [PATCH 02/66] adding map_weight into struct --- program_to_test/Makefile | 3 +- program_to_test/headers/push_swap.h | 7 ++- program_to_test/src/ft_lst_map_indexers.c | 64 +++++++++++------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/program_to_test/Makefile b/program_to_test/Makefile index 1dbb2bc..f937372 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/06 18:49:18 by umeneses ### ########.fr # +# Updated: 2024/06/10 10:38:42 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -56,6 +56,7 @@ SRC_FILES += ft_lst_clear.c SRC_FILES += ft_lst_deletes.c SRC_FILES += ft_lst_goto.c SRC_FILES += ft_lst_init.c +SRC_FILES += ft_lst_map_indexers.c SRC_FILES += ft_sort_until3.c SRC_FILES += ft_swap.c SRC_FILES += ft_push.c diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 327c7dc..641ab4b 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/08 14:55:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 11:10:55 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ typedef struct s_stack int nbr; int cost; int pos; + int weight; struct s_stack *prev; struct s_stack *next; } t_stack; @@ -56,6 +57,10 @@ void ft_reverse_rotate(t_stack **stack); void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); /* basic push_swap functions */ +void ft_lst_map_all_indexers(t_stack *stack); +void ft_lst_map_position(t_stack *stack); +void ft_lst_map_weight(t_stack **stack); + bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 0233c35..e0a62f0 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/10 11:24:19 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 11:29:40 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ void ft_lst_map_all_indexers(t_stack *stack) { ft_lst_map_position(stack); - // ft_lst_map_weight(&stack); + ft_lst_map_weight(&stack); } void ft_lst_map_position(t_stack *stack) @@ -37,36 +37,32 @@ void ft_lst_map_position(t_stack *stack) stack = ft_lst_goto_head(stack); } -// void ft_lst_map_weight(t_stack **stack) -// { -// int weight; -// int target; -// int tocompare; -// t_stack *temp; +void ft_lst_map_weight(t_stack **stack) +{ + int weight; + int target; + int tocompare; + t_stack *temp; -// weight = 0; -// *stack = ft_lst_goto_head(*stack); -// temp = *stack; -// target = temp->nbr; -// tocompare = (*stack)->next->nbr; -// while ((temp != NULL) && (temp->next != NULL) && ((*stack)->next != NULL) -// && (weight <= ft_lst_size(*stack))) -// { -// while ((*stack)->next && (*stack)->next->nbr) -// { -// if (target > tocompare) -// weight++; -// (*stack)->weight = weight; -// if ((*stack)->next != NULL) -// { -// (*stack) = (*stack)->next; -// tocompare = (*stack)->nbr; -// ft_printf("tocompare = %d\n", tocompare); -// } -// } -// temp = temp->next; -// target = temp->nbr; -// ft_printf("(*stack)->weight = %d\n", (*stack)->weight); -// ft_printf("target nbr = %d\n", target); -// } -// } + weight = 0; + temp = *stack; + target = temp->nbr; + tocompare = (*stack)->next->nbr; + while ((temp != NULL) && (temp->next != NULL) && ((*stack)->next != NULL) + && (weight <= ft_lst_size(*stack))) + { + while ((*stack)->next && (*stack)->next->nbr) + { + if (target > tocompare) + weight++; + (*stack)->weight = weight; + if ((*stack)->next != NULL) + { + (*stack) = (*stack)->next; + tocompare = (*stack)->nbr; + } + } + temp = temp->next; + target = temp->nbr; + } +} From 06822a7adb26b32c8938cc07c3b243af98a9724a Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 11:32:06 -0300 Subject: [PATCH 03/66] 1st mia step - adding map weight indexer for every number --- _ci_tdd/test_files/test_main_miunit.c | 92 ++++++++++++++------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index bca7301..7268123 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/06/10 11:23:05 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 11:28:51 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,52 +39,53 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -// MU_TEST(test_1st_miastep_weight_index) -// { -// // ARRANGE -// t_stack *stack; -// char **argv_simulation = NULL; -// char *userinput; -// int expected_size; -// int actual_size; -// int expected_top_a; -// int actual_top_a; -// int expected_bottom_a; -// int actual_bottom_a; -// int expected_highest_weight; -// int actual_highest_weight; +MU_TEST(test_1st_miastep_weight_index) +{ + // ARRANGE + t_stack *stack; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_highest_weight; + int actual_highest_weight; -// // ACT -// stack = NULL; -// userinput = "./push_swap 2 42 0 4 8 3 31 27"; -// argv_simulation = ft_split(userinput, ' '); -// expected_size = ft_minunit_array_counter(argv_simulation); -// expected_top_a = ft_atoi(argv_simulation[1]); -// expected_bottom_a = ft_atoi(argv_simulation[8]); -// expected_highest_weight = expected_size; - -// stack = ft_lts_buildstack_argv(&stack, argv_simulation); - -// actual_size = ft_lst_size(stack); -// ft_lst_map_all_indexers(stack); -// actual_top_a = ft_lst_goto_head(stack)->nbr; -// actual_highest_weight = stack->next->weight; -// while (stack && stack->next != NULL) -// { -// ft_printf("nbr = %d\n", stack->nbr); -// ft_printf("nbr pos [%d] weigth = %d\n", stack->pos, stack->weight); -// stack = stack->next; -// } -// actual_bottom_a = ft_lst_goto_end(stack)->nbr; + // ACT + stack = NULL; + userinput = "./push_swap 2 42 0 4 8 3 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[1]); + expected_bottom_a = ft_atoi(argv_simulation[8]); + expected_highest_weight = expected_size; -// // ASSERT -// mu_assert_int_eq(expected_highest_weight, actual_highest_weight); -// mu_assert_int_eq(expected_size, actual_size); -// mu_assert_int_eq(expected_top_a, actual_top_a); -// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); -// ft_lstclear_single_ptr(stack); -// ft_array_clear(argv_simulation, expected_size); -// } + stack = ft_lts_buildstack_argv(&stack, argv_simulation); + + actual_size = ft_lst_size(stack); + ft_lst_map_position(stack); + ft_lst_map_weight(&stack); + actual_top_a = ft_lst_goto_head(stack)->nbr; + + while (stack->pos <= 2) + { + stack = stack->next; + if (stack->pos == 2) + actual_highest_weight = stack->weight; + } + actual_bottom_a = ft_lst_goto_end(stack)->nbr; + + // ASSERT + mu_assert_int_eq(expected_highest_weight, actual_highest_weight); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack); + ft_array_clear(argv_simulation, expected_size); +} MU_TEST(test_1st_miastep_pos_index) { @@ -1185,6 +1186,7 @@ MU_TEST_SUITE(sorting_tests) MU_TEST_SUITE(miacombeau_tests) { MU_RUN_TEST(test_1st_miastep_pos_index); + MU_RUN_TEST(test_1st_miastep_weight_index); } int main(void) From 3dfc593dedc908f8c1e6d83231be2d706930ace3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 12:23:11 -0300 Subject: [PATCH 04/66] trying another approach for weight mesurement --- program_to_test/src/ft_lst_map_indexers.c | 34 +++++++++-------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index e0a62f0..1c72470 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/10 11:29:40 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 12:07:24 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,12 +26,12 @@ void ft_lst_map_position(t_stack *stack) while (stack->next != NULL) { pos++; - (*stack).pos = pos; + stack->pos = pos; stack = stack->next; if (stack->next == NULL) { pos++; - (*stack).pos = pos; + stack->pos = pos; } } stack = ft_lst_goto_head(stack); @@ -40,29 +40,21 @@ void ft_lst_map_position(t_stack *stack) void ft_lst_map_weight(t_stack **stack) { int weight; - int target; - int tocompare; - t_stack *temp; + t_stack *target; + t_stack *compare_node; + target = *stack; weight = 0; - temp = *stack; - target = temp->nbr; - tocompare = (*stack)->next->nbr; - while ((temp != NULL) && (temp->next != NULL) && ((*stack)->next != NULL) - && (weight <= ft_lst_size(*stack))) + while (target != NULL && target->next != NULL) { - while ((*stack)->next && (*stack)->next->nbr) + compare_node = target->next; + while (compare_node != NULL) { - if (target > tocompare) + if (target->nbr > compare_node->nbr) weight++; - (*stack)->weight = weight; - if ((*stack)->next != NULL) - { - (*stack) = (*stack)->next; - tocompare = (*stack)->nbr; - } + compare_node = compare_node->next; } - temp = temp->next; - target = temp->nbr; + target->weight = weight; + target = target->next; } } From 38151c22e0aa173eb99a119420e3b4077117cea0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 14:22:22 -0300 Subject: [PATCH 05/66] updating variable name --- program_to_test/src/ft_sort_until3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index f002d2a..bfd65b6 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/07 10:39:41 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 10:52:16 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ bool ft_is_sorted(t_stack *list) { - t_stack *tmp; + t_stack *temp; while (list->next != NULL) { - tmp = list->next; - if (list->nbr > tmp->nbr) + temp = list->next; + if (list->nbr > temp->nbr) return (false); list = list->next; } From f37b2bdf553c48ff61691893df06fb22b5fbc513 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 15:17:09 -0300 Subject: [PATCH 06/66] updating pointer callers --- program_to_test/headers/push_swap.h | 11 ++++--- program_to_test/src/ft_do_push_fts.c | 10 +++--- program_to_test/src/ft_lst_map_indexers.c | 39 ++++++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 641ab4b..2b35eb1 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/10 11:10:55 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 15:13:58 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,8 +57,8 @@ void ft_reverse_rotate(t_stack **stack); void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); /* basic push_swap functions */ -void ft_lst_map_all_indexers(t_stack *stack); -void ft_lst_map_position(t_stack *stack); +void ft_lst_map_all_indexers(t_stack **stack); +void ft_lst_map_position(t_stack **stack); void ft_lst_map_weight(t_stack **stack); bool ft_is_sorted(t_stack *stack); @@ -67,13 +67,14 @@ bool ft_is_sorted(t_stack *stack); void ft_do_sort(t_stack **stack_a, t_stack **stack_b); t_stack *ft_sort_2_nbrs(t_stack **stack); t_stack *ft_sort_3_nbrs(t_stack **stack); +void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b); /* sorting functions */ 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_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_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); diff --git a/program_to_test/src/ft_do_push_fts.c b/program_to_test/src/ft_do_push_fts.c index 79a95a1..d59923e 100644 --- a/program_to_test/src/ft_do_push_fts.c +++ b/program_to_test/src/ft_do_push_fts.c @@ -6,20 +6,20 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 12:24:04 by umeneses #+# #+# */ -/* Updated: 2024/06/04 18:28:18 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 14:57:19 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_do_push_a(t_stack *stack_a, t_stack *stack_b) +void ft_do_push_a(t_stack **stack_a, t_stack **stack_b) { - ft_push_a(&stack_a, &stack_b); + ft_push_a(stack_a, stack_b); ft_putstr_fd("pa\n", 1); } -void ft_do_push_b(t_stack *stack_a, t_stack *stack_b) +void ft_do_push_b(t_stack **stack_a, t_stack **stack_b) { - ft_push_b(&stack_a, &stack_b); + ft_push_b(stack_a, stack_b); ft_putstr_fd("pb\n", 1); } diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 1c72470..d134f10 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,35 +6,35 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/10 12:07:24 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 15:13:49 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_lst_map_all_indexers(t_stack *stack) +void ft_lst_map_all_indexers(t_stack **stack) { ft_lst_map_position(stack); - ft_lst_map_weight(&stack); + ft_lst_map_weight(stack); } -void ft_lst_map_position(t_stack *stack) +void ft_lst_map_position(t_stack **stack) { int pos; pos = 0; - while (stack->next != NULL) + while ((*stack)->next != NULL) { pos++; - stack->pos = pos; - stack = stack->next; - if (stack->next == NULL) + (*stack)->pos = pos; + (*stack) = (*stack)->next; + if ((*stack)->next == NULL) { pos++; - stack->pos = pos; + (*stack)->pos = pos; } } - stack = ft_lst_goto_head(stack); + *stack = ft_lst_goto_head(*stack); } void ft_lst_map_weight(t_stack **stack) @@ -44,7 +44,7 @@ void ft_lst_map_weight(t_stack **stack) t_stack *compare_node; target = *stack; - weight = 0; + weight = 1; while (target != NULL && target->next != NULL) { compare_node = target->next; @@ -58,3 +58,20 @@ void ft_lst_map_weight(t_stack **stack) target = target->next; } } + +// void ft_lst_map_weight_by_argv(t_stack **stack, char argv) +// { +// int weight; +// int pos; +// int **argv_splited; + +// weight = 0; +// pos = 0; +// argv_splited = ft_split(argv, ' '); +// while (argv_splited[pos] != NULL) +// { +// weight = 1; +// if (argv_splited[pos] > argv_splited[pos + 1]) +// argv_splited[pos]++; +// } +// } From 01fac2ece895a0702202bcf4a2cb72244804bf3d Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 17:58:22 -0300 Subject: [PATCH 07/66] rebuilding map_weight, now with stack_size --- program_to_test/headers/push_swap.h | 5 +- program_to_test/src/ft_lst_map_indexers.c | 78 +++++++++++++++++------ 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 2b35eb1..448b9f2 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/10 15:13:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 17:47:15 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,7 @@ void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); void ft_lst_map_all_indexers(t_stack **stack); void ft_lst_map_position(t_stack **stack); -void ft_lst_map_weight(t_stack **stack); +void ft_lst_map_weight(t_stack **stack, int stack_size); bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ @@ -75,6 +75,7 @@ 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); diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index d134f10..dec32a8 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/10 15:13:49 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 17:53:51 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,11 @@ void ft_lst_map_all_indexers(t_stack **stack) { + int stack_size; + + stack_size = ft_lst_size(*stack); ft_lst_map_position(stack); - ft_lst_map_weight(stack); + ft_lst_map_weight(stack, stack_size); } void ft_lst_map_position(t_stack **stack) @@ -37,41 +40,74 @@ void ft_lst_map_position(t_stack **stack) *stack = ft_lst_goto_head(*stack); } -void ft_lst_map_weight(t_stack **stack) +void ft_lst_map_weight(t_stack **stack, int stack_size) { int weight; t_stack *target; - t_stack *compare_node; + t_stack *highest; - target = *stack; - weight = 1; - while (target != NULL && target->next != NULL) + while (--stack_size > 0) { - compare_node = target->next; - while (compare_node != NULL) + target = *stack; + weight = INT_MIN; + highest = NULL; + while (target) { - if (target->nbr > compare_node->nbr) - weight++; - compare_node = compare_node->next; + if (target->nbr == INT_MIN && target->weight == 0) + target->weight = 1; + if (target->nbr > weight && target->weight == 0) + { + weight = target->nbr; + highest = target; + target = *stack; + } + else + target = target->next; } - target->weight = weight; - target = target->next; + if (highest != NULL) + highest->weight = stack_size; } } -// void ft_lst_map_weight_by_argv(t_stack **stack, char argv) + +// void ft_lst_map_weight(t_stack **stack) +// { +// int weight; +// t_stack *target; +// t_stack *compare_node; + +// target = *stack; +// weight = 1; +// while (target != NULL && target->next != NULL) +// { +// compare_node = target->next; +// while (compare_node != NULL) +// { +// if (target->nbr > compare_node->nbr) +// weight++; +// compare_node = compare_node->next; +// } +// target->weight = weight; +// target = target->next; +// } +// } + +// void ft_lst_map_weight_by_argv(t_stack **stack, char **argv) // { // int weight; // int pos; -// int **argv_splited; +// char **argv_splited; +// t_stack *temp; // weight = 0; // pos = 0; -// argv_splited = ft_split(argv, ' '); -// while (argv_splited[pos] != NULL) +// weight = 0; +// temp = *stack; +// argv_splited = ft_split(*argv, ' '); +// while ((argv_splited[pos] != NULL) && (temp->next != NULL)) // { -// weight = 1; -// if (argv_splited[pos] > argv_splited[pos + 1]) -// argv_splited[pos]++; +// if (ft_atoi(argv_splited[pos]) > ft_atoi(argv_splited[pos + 1])) +// temp->weight = weight++; +// temp = temp->next; // } // } From 5f22ceef1ff8087c0be55569ebbaad7ce5ed8bb1 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 18:00:37 -0300 Subject: [PATCH 08/66] updating main to test new weight mesurement - map_weight --- program_to_test/src/push_main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index a9f16f5..949b33a 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/08 14:51:33 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 16:26:41 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,11 +22,18 @@ int main(int argc, char **argv) stack_a = NULL; stack_b = NULL; stack_a = ft_lts_buildstack_argv(&stack_a, argv); - ft_lst_printf_int_content("testing main content:", stack_a); - ft_printf("testing main size: %d\n", ft_lst_size(stack_a)); + ft_lst_printf_int_content("original main:", stack_a); + ft_lst_map_all_indexers(&stack_a); + stack_a = ft_lst_goto_head(stack_a); + while (stack_a->next !=NULL) + { + ft_printf("stack_a pos[%d] main = %d and weight = %d\n", stack_a->pos, stack_a->nbr, stack_a->weight); + stack_a = stack_a->next; + if (stack_a->next ==NULL) + ft_printf("stack_a pos[%d] main = %d and weight = %d\n", stack_a->pos, stack_a->nbr, stack_a->weight); + } ft_do_sort(&stack_a, &stack_b); ft_lst_printf_int_content("updated main content:", stack_a); - ft_printf("stack_a pos na main = %d\n", stack_a->pos); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); return (0); From ce22e4b574a65257613a67b13eeb5f8d2e5c3956 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 18:11:27 -0300 Subject: [PATCH 09/66] updating argv for new tests --- _ci_tdd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_ci_tdd/Makefile b/_ci_tdd/Makefile index bc14eee..9413a47 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/04 16:33:23 by umeneses ### ########.fr # +# Updated: 2024/06/08 17:56:07 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -75,7 +75,7 @@ COMP_EXE = $(CC) $(LDFLAGS) $(OBJ_FILES) $(LDLIBS) -o $(NAME) # **************************************************************************** # define arguments - 42 1 1024 + 42 1 10 21 11 7 4 2 endef define bonus From 67acb7d1dd8ba5abb9fc30beceb8443739e6f693 Mon Sep 17 00:00:00 2001 From: umeneses Date: Mon, 10 Jun 2024 18:13:24 -0300 Subject: [PATCH 10/66] 1st version of pushing all to stack_b but 3 numbers remains in stack_a --- _ci_tdd/test_files/test_main_miunit.c | 123 +++++++++++++++++++----- program_to_test/Makefile | 3 +- program_to_test/src/ft_do_sort.c | 6 +- program_to_test/src/ft_sort_4_or_more.c | 46 +++++++++ 4 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 program_to_test/src/ft_sort_4_or_more.c diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 7268123..b69895f 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/06/10 11:28:51 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 18:09:35 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,11 +22,12 @@ #include "../../program_to_test/src/ft_swap.c" #include "../../program_to_test/src/ft_push.c" #include "../../program_to_test/src/ft_rotate.c" -#include "../../program_to_test/src/ft_sort_until3.c" #include "../../program_to_test/src/ft_do_push_fts.c" #include "../../program_to_test/src/ft_do_rev_rotate_fts.c" #include "../../program_to_test/src/ft_do_rotate_fts.c" #include "../../program_to_test/src/ft_do_swap_fts.c" +#include "../../program_to_test/src/ft_sort_until3.c" +#include "../../program_to_test/src/ft_sort_4_or_more.c" // #include "minunit_utils.c" // #include "minunit_utils.h" @@ -39,6 +40,55 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); +MU_TEST(test_1st_miastep_push_b_all_but3) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size_before_push; + int actual_size_before_push; + int expected_top_a_before_push; + int actual_top_a_before_push; + int expected_bottom_a_before_push; + int actual_bottom_a_before_push; + int expected_bottom_a_after_push; + int actual_bottom_a_after_push; + + // ACT + stack_a = NULL; + stack_b = NULL; + userinput = "./push_swap 2 42 0 4 8 3"; + argv_simulation = ft_split(userinput, ' '); + expected_size_before_push = ft_minunit_array_counter(argv_simulation); + expected_top_a_before_push = ft_atoi(argv_simulation[1]); + expected_bottom_a_before_push = ft_atoi(argv_simulation[3]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + + actual_size_before_push = ft_lst_size(stack_a); + actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; + actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; + + ft_lst_map_position(&stack_a); + ft_lst_map_weight(&stack_a, expected_size_before_push); + ft_push_b_all_but_three(&stack_a, &stack_b); + // ft_lst_printf_int_content("stack_a after push:", stack_a); + // ft_lst_printf_int_content("stack_b after push:", stack_b); + + expected_bottom_a_after_push = ft_atoi(argv_simulation[2]); + actual_bottom_a_after_push = ft_lst_goto_end(stack_a)->nbr; + // ASSERT + mu_assert_int_eq(expected_bottom_a_after_push, actual_bottom_a_after_push); + mu_assert_int_eq(expected_size_before_push, actual_size_before_push); + mu_assert_int_eq(expected_top_a_before_push, actual_top_a_before_push); + mu_assert_int_eq(expected_bottom_a_before_push, actual_bottom_a_before_push); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size_before_push); +} + MU_TEST(test_1st_miastep_weight_index) { // ARRANGE @@ -61,13 +111,13 @@ MU_TEST(test_1st_miastep_weight_index) expected_size = ft_minunit_array_counter(argv_simulation); expected_top_a = ft_atoi(argv_simulation[1]); expected_bottom_a = ft_atoi(argv_simulation[8]); - expected_highest_weight = expected_size; + expected_highest_weight = expected_size - 1; stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); - ft_lst_map_position(stack); - ft_lst_map_weight(&stack); + ft_lst_map_position(&stack); + ft_lst_map_weight(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; while (stack->pos <= 2) @@ -114,7 +164,7 @@ MU_TEST(test_1st_miastep_pos_index) stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); - ft_lst_map_position(stack); + ft_lst_map_position(&stack); actual_top_a = ft_lst_goto_head(stack)->nbr; while (stack->pos <= 5) { @@ -673,10 +723,14 @@ MU_TEST(test_ft_push_b) int second_b = 888; int third_b = 777; int bottom_b = 666; - int actual_result_a; - int actual_result_b; - int expected_result_a; - int expected_result_b; + int actual_top_a; + int actual_top_b; + int expected_top_a; + int expected_top_b; + int actual_bottom_a; + int actual_bottom_b; + int expected_bottom_a; + int expected_bottom_b; int actual_size_a; int actual_size_b; int expected_size_a; @@ -695,19 +749,25 @@ MU_TEST(test_ft_push_b) stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(second_b)); stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(third_b)); stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(bottom_b)); - expected_result_a = second_a; - expected_result_b = top_a; + expected_top_a = second_a; + expected_bottom_a = bottom_a; + expected_top_b = top_a; + expected_bottom_b = bottom_b; expected_size_a = ft_lst_size(stack_a) - 1; expected_size_b = ft_lst_size(stack_b) + 1; ft_push_b(&stack_a, &stack_b); - actual_result_a = ft_lst_goto_head(stack_a)->nbr; - actual_result_b = ft_lst_goto_head(stack_b)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + actual_top_b = ft_lst_goto_head(stack_b)->nbr; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_bottom_b = ft_lst_goto_end(stack_b)->nbr; actual_size_a = ft_lst_size(stack_a); actual_size_b = ft_lst_size(stack_b); // ASSERT - mu_assert_int_eq(expected_result_a, actual_result_a); - mu_assert_int_eq(expected_result_b, actual_result_b); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + mu_assert_int_eq(expected_top_b, actual_top_b); + mu_assert_int_eq(expected_bottom_b, actual_bottom_b); mu_assert_int_eq(expected_size_a, actual_size_a); mu_assert_int_eq(expected_size_b, actual_size_b); ft_lstclear_single_ptr(stack_a); @@ -725,10 +785,14 @@ MU_TEST(test_ft_push_a) int second_b = 888; int third_b = 777; int bottom_b = 666; - int actual_result_a; - int actual_result_b; - int expected_result_a; - int expected_result_b; + int actual_top_a; + int actual_top_b; + int expected_top_a; + int expected_top_b; + int actual_bottom_a; + int actual_bottom_b; + int expected_bottom_a; + int expected_bottom_b; int actual_size_a; int actual_size_b; int expected_size_a; @@ -749,17 +813,23 @@ MU_TEST(test_ft_push_a) stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(bottom_b)); expected_size_a = ft_lst_size(stack_a) + 1; expected_size_b = ft_lst_size(stack_b) - 1; - expected_result_a = top_b; - expected_result_b = second_b; + expected_top_a = top_b; + expected_bottom_a = bottom_a; + expected_top_b = second_b; + expected_bottom_b = bottom_b; ft_push_a(&stack_a, &stack_b); - actual_result_a = ft_lst_goto_head(stack_a)->nbr; - actual_result_b = ft_lst_goto_head(stack_b)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + actual_top_b = ft_lst_goto_head(stack_b)->nbr; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_bottom_b = ft_lst_goto_end(stack_b)->nbr; actual_size_a = ft_lst_size(stack_a); actual_size_b = ft_lst_size(stack_b); // ASSERT - mu_assert_int_eq(expected_result_a, actual_result_a); - mu_assert_int_eq(expected_result_b, actual_result_b); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + mu_assert_int_eq(expected_top_b, actual_top_b); + mu_assert_int_eq(expected_bottom_b, actual_bottom_b); mu_assert_int_eq(expected_size_a, actual_size_a); mu_assert_int_eq(expected_size_b, actual_size_b); ft_lstclear_single_ptr(stack_a); @@ -1187,6 +1257,7 @@ MU_TEST_SUITE(miacombeau_tests) { MU_RUN_TEST(test_1st_miastep_pos_index); MU_RUN_TEST(test_1st_miastep_weight_index); + MU_RUN_TEST(test_1st_miastep_push_b_all_but3); } int main(void) diff --git a/program_to_test/Makefile b/program_to_test/Makefile index f937372..512534c 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/10 10:38:42 by umeneses ### ########.fr # +# Updated: 2024/06/10 16:20:06 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -58,6 +58,7 @@ SRC_FILES += ft_lst_goto.c SRC_FILES += ft_lst_init.c SRC_FILES += ft_lst_map_indexers.c SRC_FILES += ft_sort_until3.c +SRC_FILES += ft_sort_4_or_more.c SRC_FILES += ft_swap.c SRC_FILES += ft_push.c SRC_FILES += ft_rotate.c diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 2689e1b..87dc18d 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/08 14:41:50 by umeneses ### ########.fr */ +/* Updated: 2024/06/10 16:28:07 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,9 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) { if (ft_lst_size(*stack_a) == 2) ft_sort_2_nbrs(stack_a); - if (ft_lst_size(*stack_a) == 3) + else if (ft_lst_size(*stack_a) == 3) ft_sort_3_nbrs(stack_a); + else + ft_push_b_all_but_three(stack_a, stack_b); } } diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c new file mode 100644 index 0000000..a0b4bbd --- /dev/null +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_4_or_more.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: umeneses +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ +/* Updated: 2024/06/10 16:21:11 by umeneses ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) +{ + int stack_size; + int pushed; + int index; + + stack_size = ft_lst_size(*stack_a); + pushed = 0; + index = 0; + while ((stack_size > 6) && (index < stack_size) + && (pushed < stack_size / 2)) + { + if ((*stack_a)->weight <= (stack_size / 2)) + { + ft_do_push_b(stack_a, stack_b); + ft_lst_printf_int_content("stack_b content:", *stack_b); + pushed++; + ft_printf("pushed = %d\n", pushed); + } + else + ft_sort_3_nbrs(stack_a); + index++; + ft_printf("index = %d\n", index); + } + while (stack_size - pushed > 3) + { + ft_do_push_b(stack_a, stack_b); + pushed++; + ft_printf("pushed = %d\n", pushed); + } + // ft_sort_3_nbrs(stack_a); +} From 423984a2518e5452ba1eae6906d0d0d9d7a7fff6 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 13:28:07 -0300 Subject: [PATCH 11/66] building the first step of mia-combeau - push_b_all_but_three AND build a test for it --- _ci_tdd/test_files/test_main_miunit.c | 34 ++++++++++++++++++------- program_to_test/src/ft_do_sort.c | 9 ++++--- program_to_test/src/ft_sort_4_or_more.c | 8 ++---- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index b69895f..5771c6e 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/06/10 18:09:35 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 13:24:49 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,20 +50,27 @@ MU_TEST(test_1st_miastep_push_b_all_but3) int expected_size_before_push; int actual_size_before_push; int expected_top_a_before_push; - int actual_top_a_before_push; int expected_bottom_a_before_push; + int actual_top_a_before_push; int actual_bottom_a_before_push; + + int expected_top_a_after_push; + int expected_top_b_after_push; int expected_bottom_a_after_push; + int expected_bottom_b_after_push; + int actual_top_a_after_push; + int actual_top_b_after_push; int actual_bottom_a_after_push; + int actual_bottom_b_after_push; // ACT stack_a = NULL; - stack_b = NULL; - userinput = "./push_swap 2 42 0 4 8 3"; + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + userinput = "./push_swap 2 42 11 4 8 3"; argv_simulation = ft_split(userinput, ' '); expected_size_before_push = ft_minunit_array_counter(argv_simulation); expected_top_a_before_push = ft_atoi(argv_simulation[1]); - expected_bottom_a_before_push = ft_atoi(argv_simulation[3]); + expected_bottom_a_before_push = ft_atoi(argv_simulation[6]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); @@ -74,12 +81,21 @@ MU_TEST(test_1st_miastep_push_b_all_but3) ft_lst_map_position(&stack_a); ft_lst_map_weight(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); - // ft_lst_printf_int_content("stack_a after push:", stack_a); - // ft_lst_printf_int_content("stack_b after push:", stack_b); - - expected_bottom_a_after_push = ft_atoi(argv_simulation[2]); + ft_lst_printf_int_content("stack_a after push:", stack_a); + ft_lst_printf_int_content("stack_b after push:", stack_b); + + expected_top_a_after_push = ft_atoi(argv_simulation[4]); + expected_bottom_a_after_push = ft_atoi(argv_simulation[6]); + expected_bottom_b_after_push = ft_atoi(argv_simulation[1]); + expected_top_b_after_push = ft_atoi(argv_simulation[3]); + actual_top_a_after_push = ft_lst_goto_head(stack_a)->nbr; + actual_top_b_after_push = ft_lst_goto_head(stack_b)->nbr; actual_bottom_a_after_push = ft_lst_goto_end(stack_a)->nbr; + actual_bottom_b_after_push = ft_lst_goto_end(stack_b)->nbr; // ASSERT + mu_assert_int_eq(expected_top_a_after_push, actual_top_a_after_push); + mu_assert_int_eq(expected_top_b_after_push, actual_top_b_after_push); + mu_assert_int_eq(expected_bottom_b_after_push, actual_bottom_b_after_push); mu_assert_int_eq(expected_bottom_a_after_push, actual_bottom_a_after_push); mu_assert_int_eq(expected_size_before_push, actual_size_before_push); mu_assert_int_eq(expected_top_a_before_push, actual_top_a_before_push); diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 87dc18d..7f6165b 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/10 16:28:07 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 11:01:40 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,16 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) { (void)stack_b; - if (!ft_is_sorted(*stack_a)) + while (!ft_is_sorted(*stack_a)) { if (ft_lst_size(*stack_a) == 2) ft_sort_2_nbrs(stack_a); else if (ft_lst_size(*stack_a) == 3) ft_sort_3_nbrs(stack_a); - else + else if (ft_lst_size(*stack_a) > 3) + { ft_push_b_all_but_three(stack_a, stack_b); + ft_sort_3_nbrs(stack_a); + } } } diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index a0b4bbd..a5f2059 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/10 16:21:11 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 13:26:23 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,20 +27,16 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) if ((*stack_a)->weight <= (stack_size / 2)) { ft_do_push_b(stack_a, stack_b); - ft_lst_printf_int_content("stack_b content:", *stack_b); pushed++; - ft_printf("pushed = %d\n", pushed); } else ft_sort_3_nbrs(stack_a); index++; - ft_printf("index = %d\n", index); } while (stack_size - pushed > 3) { ft_do_push_b(stack_a, stack_b); pushed++; - ft_printf("pushed = %d\n", pushed); } - // ft_sort_3_nbrs(stack_a); + *stack_b = ft_lst_delat_end(*stack_b); } From 7a6c4140a61fbba5a63614f3bf98d944972e3839 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 13:32:12 -0300 Subject: [PATCH 12/66] adding the end of first mia combeau step -> sort stack a --- _ci_tdd/test_files/test_main_miunit.c | 70 ++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 5771c6e..c3530e7 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/06/11 13:24:49 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 13:30:48 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,7 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -MU_TEST(test_1st_miastep_push_b_all_but3) +MU_TEST(test_1st_miastep_push_b_all_but3_sort_3a) { // ARRANGE t_stack *stack_a; @@ -81,9 +81,74 @@ MU_TEST(test_1st_miastep_push_b_all_but3) ft_lst_map_position(&stack_a); ft_lst_map_weight(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); + ft_sort_3_nbrs(&stack_a); + ft_lst_printf_int_content("stack_a after push:", stack_a); ft_lst_printf_int_content("stack_b after push:", stack_b); + expected_top_a_after_push = ft_atoi(argv_simulation[6]); + expected_bottom_a_after_push = ft_atoi(argv_simulation[5]); + expected_bottom_b_after_push = ft_atoi(argv_simulation[1]); + expected_top_b_after_push = ft_atoi(argv_simulation[3]); + actual_top_a_after_push = ft_lst_goto_head(stack_a)->nbr; + actual_top_b_after_push = ft_lst_goto_head(stack_b)->nbr; + actual_bottom_a_after_push = ft_lst_goto_end(stack_a)->nbr; + actual_bottom_b_after_push = ft_lst_goto_end(stack_b)->nbr; + // ASSERT + mu_assert_int_eq(expected_top_a_after_push, actual_top_a_after_push); + mu_assert_int_eq(expected_top_b_after_push, actual_top_b_after_push); + mu_assert_int_eq(expected_bottom_b_after_push, actual_bottom_b_after_push); + mu_assert_int_eq(expected_bottom_a_after_push, actual_bottom_a_after_push); + mu_assert_int_eq(expected_size_before_push, actual_size_before_push); + mu_assert_int_eq(expected_top_a_before_push, actual_top_a_before_push); + mu_assert_int_eq(expected_bottom_a_before_push, actual_bottom_a_before_push); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size_before_push); +} + +MU_TEST(test_1st_miastep_push_b_all_but3) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size_before_push; + int actual_size_before_push; + int expected_top_a_before_push; + int expected_bottom_a_before_push; + int actual_top_a_before_push; + int actual_bottom_a_before_push; + + int expected_top_a_after_push; + int expected_top_b_after_push; + int expected_bottom_a_after_push; + int expected_bottom_b_after_push; + int actual_top_a_after_push; + int actual_top_b_after_push; + int actual_bottom_a_after_push; + int actual_bottom_b_after_push; + + // ACT + stack_a = NULL; + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + userinput = "./push_swap 2 42 11 4 8 3"; + argv_simulation = ft_split(userinput, ' '); + expected_size_before_push = ft_minunit_array_counter(argv_simulation); + expected_top_a_before_push = ft_atoi(argv_simulation[1]); + expected_bottom_a_before_push = ft_atoi(argv_simulation[6]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + + actual_size_before_push = ft_lst_size(stack_a); + actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; + actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; + + ft_lst_map_position(&stack_a); + ft_lst_map_weight(&stack_a, expected_size_before_push); + ft_push_b_all_but_three(&stack_a, &stack_b); + expected_top_a_after_push = ft_atoi(argv_simulation[4]); expected_bottom_a_after_push = ft_atoi(argv_simulation[6]); expected_bottom_b_after_push = ft_atoi(argv_simulation[1]); @@ -1274,6 +1339,7 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_pos_index); MU_RUN_TEST(test_1st_miastep_weight_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); + MU_RUN_TEST(test_1st_miastep_push_b_all_but3_sort_3a); } int main(void) From 746acebab2ef5b131fb57a706b0dc22a85a4d92d Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 14:45:39 -0300 Subject: [PATCH 13/66] mapping the lowest weight position - ft_lst_map_lowest_weight_position --- program_to_test/src/ft_lst_map_indexers.c | 42 +++++++++++------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index dec32a8..a7f9455 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/10 17:53:51 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 14:43:53 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,28 +69,26 @@ void ft_lst_map_weight(t_stack **stack, int stack_size) } } +int ft_lst_map_lowest_weight_position(t_stack **stack) +{ + int lowest_weight; + int lowest_position; + t_stack *temp; -// void ft_lst_map_weight(t_stack **stack) -// { -// int weight; -// t_stack *target; -// t_stack *compare_node; - -// target = *stack; -// weight = 1; -// while (target != NULL && target->next != NULL) -// { -// compare_node = target->next; -// while (compare_node != NULL) -// { -// if (target->nbr > compare_node->nbr) -// weight++; -// compare_node = compare_node->next; -// } -// target->weight = weight; -// target = target->next; -// } -// } + temp = *stack; + lowest_weight = INT_MAX; + lowest_position = temp->pos; + while (temp) + { + if (temp->weight < lowest_weight) + { + lowest_weight = temp->weight; + lowest_position = temp->pos; + } + temp = temp->next; + } + return (lowest_position); +} // void ft_lst_map_weight_by_argv(t_stack **stack, char **argv) // { From f9c636b963ee2f3584b630299a3dbdb8080b5c0e Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 14:46:18 -0300 Subject: [PATCH 14/66] fixing method --- program_to_test/src/ft_sort_4_or_more.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index a5f2059..152a1eb 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 13:26:23 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 13:33:42 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) pushed++; } else - ft_sort_3_nbrs(stack_a); + ft_do_rotate_a(stack_a); index++; } while (stack_size - pushed > 3) From 7e5c257ee9151f546fda7b041b2a8b31eaab3148 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 14:47:22 -0300 Subject: [PATCH 15/66] building tester for map_lowest_weight_position --- _ci_tdd/test_files/test_main_miunit.c | 48 ++++++++++++++++++++++++--- program_to_test/headers/push_swap.h | 3 +- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index c3530e7..b46da37 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/06/11 13:30:48 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 14:40:09 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,48 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); +MU_TEST(test_1st_miastep_map_lowest_weight) +{ + // ARRANGE + t_stack *stack; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_lowest_weight_pos; + int actual_lowest_weight_pos; + + // ACT + stack = NULL; + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[1]); + expected_bottom_a = ft_atoi(argv_simulation[8]); + + stack = ft_lts_buildstack_argv(&stack, argv_simulation); + expected_lowest_weight_pos = 3; + + actual_size = ft_lst_size(stack); + ft_lst_map_position(&stack); + ft_lst_map_weight(&stack, expected_size); + actual_top_a = ft_lst_goto_head(stack)->nbr; + actual_lowest_weight_pos = ft_lst_map_lowest_weight_position(&stack); + actual_bottom_a = ft_lst_goto_end(stack)->nbr; + + // ASSERT + mu_assert_int_eq(expected_lowest_weight_pos, actual_lowest_weight_pos); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack); + ft_array_clear(argv_simulation, expected_size); +} + MU_TEST(test_1st_miastep_push_b_all_but3_sort_3a) { // ARRANGE @@ -83,9 +125,6 @@ MU_TEST(test_1st_miastep_push_b_all_but3_sort_3a) ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_3_nbrs(&stack_a); - ft_lst_printf_int_content("stack_a after push:", stack_a); - ft_lst_printf_int_content("stack_b after push:", stack_b); - expected_top_a_after_push = ft_atoi(argv_simulation[6]); expected_bottom_a_after_push = ft_atoi(argv_simulation[5]); expected_bottom_b_after_push = ft_atoi(argv_simulation[1]); @@ -1340,6 +1379,7 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_weight_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); MU_RUN_TEST(test_1st_miastep_push_b_all_but3_sort_3a); + MU_RUN_TEST(test_1st_miastep_map_lowest_weight); } int main(void) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 448b9f2..e55f31b 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/10 17:47:15 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 14:13:42 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); void ft_lst_map_all_indexers(t_stack **stack); void ft_lst_map_position(t_stack **stack); void ft_lst_map_weight(t_stack **stack, int stack_size); +int ft_lst_map_lowest_weight_position(t_stack **stack); bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ From 9074c454d171a520523d09aba01dbc64e7894dbf Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 14:48:24 -0300 Subject: [PATCH 16/66] protecting list reader --- program_to_test/src/ft_lst_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index b595335..b7a2eb8 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/10 10:35:43 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 10:02:46 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ int ft_lst_size(t_stack *stack) int size; size = 0; + if (!stack) + return (size); while (stack) { size++; From d69862db773197aeee5169df3a87304c676fd13e Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 15:22:31 -0300 Subject: [PATCH 17/66] updating function names --- _ci_tdd/test_files/test_main_miunit.c | 20 ++++++++++---------- program_to_test/headers/push_swap.h | 7 ++++--- program_to_test/src/ft_do_sort.c | 15 ++++++--------- program_to_test/src/ft_sort_4_or_more.c | 8 +++++++- program_to_test/src/ft_sort_until3.c | 6 +++--- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index b46da37..3ad6c58 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/06/11 14:40:09 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:11:23 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -123,7 +123,7 @@ MU_TEST(test_1st_miastep_push_b_all_but3_sort_3a) ft_lst_map_position(&stack_a); ft_lst_map_weight(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); - ft_sort_3_nbrs(&stack_a); + ft_sort_three_nbrs(&stack_a); expected_top_a_after_push = ft_atoi(argv_simulation[6]); expected_bottom_a_after_push = ft_atoi(argv_simulation[5]); @@ -323,7 +323,7 @@ MU_TEST(test_sort_3_nbrs_already_sorted) expected_sorted_top = ft_atoi(argv_simulation[1]); expected_sorted_bottom = ft_atoi(argv_simulation[3]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -357,7 +357,7 @@ MU_TEST(test_sort_3_nbrs_highest_last) expected_sorted_top = ft_atoi(argv_simulation[2]); expected_sorted_bottom = ft_atoi(argv_simulation[3]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -391,7 +391,7 @@ MU_TEST(test_sort_3_nbrs_highest_first_v2) expected_sorted_top = ft_atoi(argv_simulation[3]); expected_sorted_bottom = ft_atoi(argv_simulation[1]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -425,7 +425,7 @@ MU_TEST(test_sort_3_nbrs_highest_first) expected_sorted_top = ft_atoi(argv_simulation[2]); expected_sorted_bottom = ft_atoi(argv_simulation[1]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -459,7 +459,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle_v2) expected_sorted_top = ft_atoi(argv_simulation[1]); expected_sorted_bottom = ft_atoi(argv_simulation[2]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -493,7 +493,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle) expected_sorted_top = ft_atoi(argv_simulation[3]); expected_sorted_bottom = ft_atoi(argv_simulation[2]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_3_nbrs(&stack); + stack = ft_sort_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; @@ -527,7 +527,7 @@ MU_TEST(test_sort_2_nbrs_with_zero) expected_sorted_top = ft_atoi(argv_simulation[2]); expected_sorted_bottom = ft_atoi(argv_simulation[1]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_2_nbrs(&stack); + stack = ft_sort_two_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; @@ -561,7 +561,7 @@ MU_TEST(test_sort_2_nbrs_without_zero) expected_sorted_bottom = ft_atoi(argv_simulation[1]); expected_sorted_top = ft_atoi(argv_simulation[2]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - stack = ft_sort_2_nbrs(&stack); + stack = ft_sort_two_nbrs(&stack); actual_size = ft_lst_size(stack); actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; actual_sorted_top = ft_lst_goto_head(stack)->nbr; diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index e55f31b..6956836 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/11 14:13:42 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:16:11 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,8 +66,9 @@ bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ void ft_do_sort(t_stack **stack_a, t_stack **stack_b); -t_stack *ft_sort_2_nbrs(t_stack **stack); -t_stack *ft_sort_3_nbrs(t_stack **stack); +t_stack *ft_sort_two_nbrs(t_stack **stack); +t_stack *ft_sort_three_nbrs(t_stack **stack); +void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b); void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b); /* sorting functions */ diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 7f6165b..3031ae1 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/11 11:01:40 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:18:20 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,16 +16,13 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) { (void)stack_b; - while (!ft_is_sorted(*stack_a)) + if (!ft_is_sorted(*stack_a)) { if (ft_lst_size(*stack_a) == 2) - ft_sort_2_nbrs(stack_a); + ft_sort_two_nbrs(stack_a); else if (ft_lst_size(*stack_a) == 3) - ft_sort_3_nbrs(stack_a); - else if (ft_lst_size(*stack_a) > 3) - { - ft_push_b_all_but_three(stack_a, stack_b); - ft_sort_3_nbrs(stack_a); - } + ft_sort_three_nbrs(stack_a); + else + ft_sort_four_or_more_nbrs(stack_a, stack_b); } } diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 152a1eb..c1d7c95 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,12 +6,18 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 13:33:42 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:09:25 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" +void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) +{ + ft_push_b_all_but_three(stack_a, stack_b); + ft_sort_three_nbrs(stack_a); +} + void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) { int stack_size; diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index bfd65b6..f2c6172 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/10 10:52:16 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:20:23 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,14 +28,14 @@ bool ft_is_sorted(t_stack *list) return (true); } -t_stack *ft_sort_2_nbrs(t_stack **list) +t_stack *ft_sort_two_nbrs(t_stack **list) { if ((*list)->nbr > (*list)->next->nbr) ft_do_swap_a(list); return (*list); } -t_stack *ft_sort_3_nbrs(t_stack **list) +t_stack *ft_sort_three_nbrs(t_stack **list) { while (!ft_is_sorted(*list)) { From ea7567bacc84d0e418c68c71b261064206fba4ce Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 17:10:02 -0300 Subject: [PATCH 18/66] fixing memory assert for goto_head --- _ci_tdd/test_files/test_main_miunit.c | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 3ad6c58..340f373 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/06/11 15:11:23 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 17:09:15 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,8 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); + + MU_TEST(test_1st_miastep_map_lowest_weight) { // ARRANGE @@ -1121,23 +1123,22 @@ MU_TEST(test_lst_delat_begin) MU_TEST(test_lst_gotoend_head_and_beforeend) { // ARRANGE - int top = 11; - int second = 22; - int third = 33; - int bottom = 44; - int expected_top; - int expected_bottom; - int expected_before_end; - int expected_ptr; - int actual_top; - int actual_bottom; - int actual_before_end; - int expected_size; - int actual_size; - int actual_top_again; - int actual_ptr; - t_stack *stack; - t_stack *head_tocheck; + int top = 11; + int second = 22; + int third = 33; + int bottom = 44; + int expected_top; + int expected_bottom; + int expected_before_end; + int actual_top; + int actual_bottom; + int actual_before_end; + int expected_size; + int actual_size; + int actual_top_again; + t_stack *actual_ptr; + t_stack *expected_ptr; + t_stack *stack; // ACT stack = NULL; @@ -1149,8 +1150,8 @@ MU_TEST(test_lst_gotoend_head_and_beforeend) expected_before_end = third; expected_bottom = bottom; expected_size = 4; - expected_ptr = 1; - head_tocheck = stack; + expected_ptr = stack; + actual_bottom = ft_lst_goto_end(stack)->nbr; actual_top = ft_lst_goto_head(stack)->nbr; actual_size = ft_lst_size(stack); @@ -1160,12 +1161,10 @@ MU_TEST(test_lst_gotoend_head_and_beforeend) stack = stack->next; } actual_top_again = ft_lst_goto_head(stack)->nbr; - actual_ptr = 0; - if (head_tocheck == stack) - actual_ptr = 1; + actual_ptr = ft_lst_goto_head(stack); // ASSERT - // mu_assert_int_eq(expected_ptr, actual_ptr); + mu_assert_mem_eq(&expected_ptr, &actual_ptr, sizeof(t_stack *)); mu_assert_int_eq(expected_top, actual_top_again); mu_assert_int_eq(expected_top, actual_top); mu_assert_int_eq(expected_before_end, actual_before_end); @@ -1380,6 +1379,7 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_push_b_all_but3); MU_RUN_TEST(test_1st_miastep_push_b_all_but3_sort_3a); MU_RUN_TEST(test_1st_miastep_map_lowest_weight); + // MU_RUN_TEST(test_1st_miastep_map_target_pos); } int main(void) From 9dad13ec1761a63b49a7b428f26ae020865a6585 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:02:52 -0300 Subject: [PATCH 19/66] removing variable blocker --- program_to_test/src/ft_do_sort.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 3031ae1..549b605 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/11 15:18:20 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 17:53:09 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,6 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) { - (void)stack_b; - if (!ft_is_sorted(*stack_a)) { if (ft_lst_size(*stack_a) == 2) From bf07b5589760b5710f5da339e378b218bc22525d Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:04:21 -0300 Subject: [PATCH 20/66] moving map_all_indexers function to other file --- program_to_test/src/ft_lst_map_indexers.c | 11 +---------- program_to_test/src/ft_sort_4_or_more.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index a7f9455..7e9f97a 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,21 +6,12 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/11 14:43:53 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:03:32 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_lst_map_all_indexers(t_stack **stack) -{ - int stack_size; - - stack_size = ft_lst_size(*stack); - ft_lst_map_position(stack); - ft_lst_map_weight(stack, stack_size); -} - void ft_lst_map_position(t_stack **stack) { int pos; diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index c1d7c95..96485d9 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,16 +6,35 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 15:09:25 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:30:01 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" +void ft_lst_map_all_indexers(t_stack **stack) +{ + int stack_size; + + stack_size = ft_lst_size(*stack); + ft_lst_map_position(stack); + ft_lst_map_weight(stack, stack_size); +} + void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) { ft_push_b_all_but_three(stack_a, stack_b); ft_sort_three_nbrs(stack_a); + // while (*stack_b) + // { + // ft_lst_get_target_position(stack_a, stack_b); + // ft_lst_get_cost(stack_a, stack_b); + // ft_lst_do_cheapest_move(stack_a, stack_b); + // } + // if (!ft_is_sorted(*stack_a)) + // { + // ft_lst_shift_stack(stack_a); + // } } void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) From eccb3b397da592791102dc5cfd261283e9e43922 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:09:11 -0300 Subject: [PATCH 21/66] 1st version of map target position function --- _ci_tdd/test_files/test_main_miunit.c | 43 ++++++++++++++++++- program_to_test/headers/push_swap.h | 3 +- program_to_test/src/ft_lst_map_indexers.c | 50 ++++++++++++++++++++++- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 340f373..bb05887 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/06/11 17:09:15 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:05:19 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,46 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); +MU_TEST(test_1st_miastep_map_target_pos) +{ + // ARRANGE + t_stack *stack; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + // int expected_target_pos; + // int actual_target_pos; + + // ACT + stack = NULL; + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[1]); + expected_bottom_a = ft_atoi(argv_simulation[8]); + + stack = ft_lts_buildstack_argv(&stack, argv_simulation); + // expected_target_pos = 3; + actual_size = ft_lst_size(stack); + ft_lst_map_all_indexers(&stack); + + // actual_target_pos = ft_lst_map_lowest_weight_position(&stack); + actual_bottom_a = ft_lst_goto_end(stack)->nbr; + actual_top_a = ft_lst_goto_head(stack)->nbr; + // ASSERT + // mu_assert_int_eq(expected_target_pos, actual_target_pos); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack); + ft_array_clear(argv_simulation, expected_size); +} MU_TEST(test_1st_miastep_map_lowest_weight) { @@ -1379,7 +1418,7 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_push_b_all_but3); MU_RUN_TEST(test_1st_miastep_push_b_all_but3_sort_3a); MU_RUN_TEST(test_1st_miastep_map_lowest_weight); - // MU_RUN_TEST(test_1st_miastep_map_target_pos); + MU_RUN_TEST(test_1st_miastep_map_target_pos); } int main(void) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 6956836..db1b7c2 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/11 15:16:11 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 15:31:59 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ typedef struct s_stack int cost; int pos; int weight; + int target; struct s_stack *prev; struct s_stack *next; } t_stack; diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 7e9f97a..6ccef4e 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:03:32 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:04:28 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,54 @@ int ft_lst_map_lowest_weight_position(t_stack **stack) return (lowest_position); } +int ft_lst_get_target_nbr(t_stack **stack_a, int b_weight, + int target_weight, int target_pos) +{ + t_stack *temp_a; + + temp_a = *stack_a; + while (temp_a) + { + if (temp_a->weight > b_weight && temp_a->weight < target_weight) + { + target_weight = temp_a->weight; + target_pos = temp_a->pos; + } + } + if (target_weight != INT_MAX) + return (target_pos); + temp_a = *stack_a; + while (temp_a) + { + if (temp_a->weight < target_weight) + { + target_weight = temp_a->weight; + target_pos = temp_a->pos; + } + temp_a = temp_a->next; + } + return (target_pos); +} + +void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) +{ + int target_position; + t_stack *temp_b; + + temp_b = *stack_b; + ft_lst_map_position(stack_a); + ft_lst_map_position(stack_b); + target_position = 0; + while (temp_b) + { + target_position = ft_lst_get_target_nbr(stack_a, temp_b->weight, + INT_MAX, target_position); + temp_b->target = target_position; + temp_b = temp_b->next; + } + +} + // void ft_lst_map_weight_by_argv(t_stack **stack, char **argv) // { // int weight; From 045ad4378b12940792571a6577536f635c197842 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:42:02 -0300 Subject: [PATCH 22/66] applying norminette --- program_to_test/src/ft_lst_addto.c | 4 ++-- program_to_test/src/ft_lst_map_indexers.c | 7 +++---- program_to_test/src/ft_sort_4_or_more.c | 25 +++++++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/program_to_test/src/ft_lst_addto.c b/program_to_test/src/ft_lst_addto.c index ef3a16d..b237dfe 100644 --- a/program_to_test/src/ft_lst_addto.c +++ b/program_to_test/src/ft_lst_addto.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/08 18:05:43 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:37:43 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ 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 *head; + t_stack *head; if (!new) return (*stack); diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 6ccef4e..a449e80 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:04:28 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:38:16 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ void ft_lst_map_weight(t_stack **stack, int stack_size) int weight; t_stack *target; t_stack *highest; - + while (--stack_size > 0) { target = *stack; @@ -122,11 +122,10 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) while (temp_b) { target_position = ft_lst_get_target_nbr(stack_a, temp_b->weight, - INT_MAX, target_position); + INT_MAX, target_position); temp_b->target = target_position; temp_b = temp_b->next; } - } // void ft_lst_map_weight_by_argv(t_stack **stack, char **argv) diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 96485d9..75415a5 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 15:30:01 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:41:10 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,20 +21,23 @@ void ft_lst_map_all_indexers(t_stack **stack) ft_lst_map_weight(stack, stack_size); } +/* +* TODO after line 35: +* ft_lst_get_cost(stack_a, stack_b); +* ft_lst_do_cheapest_move(stack_a, stack_b); +*/ void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) { ft_push_b_all_but_three(stack_a, stack_b); ft_sort_three_nbrs(stack_a); - // while (*stack_b) - // { - // ft_lst_get_target_position(stack_a, stack_b); - // ft_lst_get_cost(stack_a, stack_b); - // ft_lst_do_cheapest_move(stack_a, stack_b); - // } - // if (!ft_is_sorted(*stack_a)) - // { - // ft_lst_shift_stack(stack_a); - // } + while (*stack_b) + { + ft_lst_get_target_position(stack_a, stack_b); + } + if (!ft_is_sorted(*stack_a)) + { + ft_lst_shift_stack(stack_a); + } } void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) From 284c850686dbfefea1b67484ffe29cf819f9d50e Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:49:48 -0300 Subject: [PATCH 23/66] implementation of get target position --- program_to_test/headers/push_swap.h | 5 ++++- program_to_test/src/ft_sort_4_or_more.c | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index db1b7c2..a4950ba 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/11 15:31:59 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:45:10 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,9 @@ t_stack *ft_sort_two_nbrs(t_stack **stack); t_stack *ft_sort_three_nbrs(t_stack **stack); void ft_sort_four_or_more_nbrs(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_nbr(t_stack **stack_a, int b_weight, + int target_weight, int target_pos); +void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b); /* sorting functions */ void ft_do_swap_a(t_stack **stack); diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 75415a5..35bccf7 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:41:10 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:48:20 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,22 +22,22 @@ void ft_lst_map_all_indexers(t_stack **stack) } /* -* TODO after line 35: -* ft_lst_get_cost(stack_a, stack_b); -* ft_lst_do_cheapest_move(stack_a, stack_b); +* TODO after line 40: +* while (*stack_b) +* { +* ft_lst_get_target_position(stack_a, stack_b); +* ft_lst_get_cost(stack_a, stack_b); +* ft_lst_do_cheapest_move(stack_a, stack_b); +* } +* if (!ft_is_sorted(*stack_a)) +* { +* ft_lst_shift_stack(stack_a); +* } */ void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) { ft_push_b_all_but_three(stack_a, stack_b); ft_sort_three_nbrs(stack_a); - while (*stack_b) - { - ft_lst_get_target_position(stack_a, stack_b); - } - if (!ft_is_sorted(*stack_a)) - { - ft_lst_shift_stack(stack_a); - } } void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) From dec6799f1fef2649bb2b86db3b48790127fae7a3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:52:04 -0300 Subject: [PATCH 24/66] fixing norminette --- program_to_test/src/push_main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index 949b33a..eeb923d 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/10 16:26:41 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:26:15 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,21 +20,25 @@ int main(int argc, char **argv) if (argc <= 2) ft_error_msg("Not enough arguments. Please provide at leats 2 numbers"); stack_a = NULL; - stack_b = NULL; + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); stack_a = ft_lts_buildstack_argv(&stack_a, argv); ft_lst_printf_int_content("original main:", stack_a); ft_lst_map_all_indexers(&stack_a); - stack_a = ft_lst_goto_head(stack_a); - while (stack_a->next !=NULL) - { - ft_printf("stack_a pos[%d] main = %d and weight = %d\n", stack_a->pos, stack_a->nbr, stack_a->weight); - stack_a = stack_a->next; - if (stack_a->next ==NULL) - ft_printf("stack_a pos[%d] main = %d and weight = %d\n", stack_a->pos, stack_a->nbr, stack_a->weight); - } ft_do_sort(&stack_a, &stack_b); - ft_lst_printf_int_content("updated main content:", stack_a); + ft_lst_printf_int_content("updated stack_a:", stack_a); + ft_lst_printf_int_content("updated stack_b:", stack_b); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); return (0); } + + // stack_a = ft_lst_goto_head(stack_a); + // while (stack_a->next !=NULL) + // { + // ft_printf("stack_a pos[%d] main = %d and weight = %d\n", + // stack_a->pos, stack_a->nbr, stack_a->weight); + // stack_a = stack_a->next; + // if (stack_a->next ==NULL) + // ft_printf("stack_a pos[%d] main = %d and weight = %d\n", + // stack_a->pos, stack_a->nbr, stack_a->weight); + // } \ No newline at end of file From b31d81cc8bac2e8faaa80a2fa3c450565455a0d0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 11 Jun 2024 18:53:03 -0300 Subject: [PATCH 25/66] fixing norminette --- program_to_test/headers/push_swap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index a4950ba..259bbef 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/11 18:45:10 by umeneses ### ########.fr */ +/* Updated: 2024/06/11 18:52:44 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,8 +71,8 @@ t_stack *ft_sort_two_nbrs(t_stack **stack); t_stack *ft_sort_three_nbrs(t_stack **stack); void ft_sort_four_or_more_nbrs(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_nbr(t_stack **stack_a, int b_weight, - int target_weight, int target_pos); +int ft_lst_get_target_nbr(t_stack **stack_a, int b_weight, + int target_weight, int target_pos); void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b); /* sorting functions */ From 79e3bbe08c2dac2df322bd753fd4faf1323275b3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 13 Jun 2024 13:55:32 -0300 Subject: [PATCH 26/66] also checking lowest weight number --- _ci_tdd/test_files/test_main_miunit.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index bb05887..109d32e 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/06/11 18:05:19 by umeneses ### ########.fr */ +/* Updated: 2024/06/13 13:53:11 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,7 @@ MU_TEST(test_1st_miastep_map_target_pos) // expected_target_pos = 3; actual_size = ft_lst_size(stack); ft_lst_map_all_indexers(&stack); - + // actual_target_pos = ft_lst_map_lowest_weight_position(&stack); actual_bottom_a = ft_lst_goto_end(stack)->nbr; actual_top_a = ft_lst_goto_head(stack)->nbr; @@ -94,7 +94,9 @@ MU_TEST(test_1st_miastep_map_lowest_weight) int expected_bottom_a; int actual_bottom_a; int expected_lowest_weight_pos; + int expected_lowest_weight_nbr; int actual_lowest_weight_pos; + int actual_lowest_weight_nbr; // ACT stack = NULL; @@ -105,7 +107,8 @@ MU_TEST(test_1st_miastep_map_lowest_weight) expected_bottom_a = ft_atoi(argv_simulation[8]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - expected_lowest_weight_pos = 3; + expected_lowest_weight_pos = 3; // argv[3] = 1; + expected_lowest_weight_nbr = ft_atoi(argv_simulation[expected_lowest_weight_pos]); actual_size = ft_lst_size(stack); ft_lst_map_position(&stack); @@ -113,9 +116,12 @@ MU_TEST(test_1st_miastep_map_lowest_weight) actual_top_a = ft_lst_goto_head(stack)->nbr; actual_lowest_weight_pos = ft_lst_map_lowest_weight_position(&stack); actual_bottom_a = ft_lst_goto_end(stack)->nbr; + actual_lowest_weight_nbr = stack->next->next->nbr; + // ASSERT mu_assert_int_eq(expected_lowest_weight_pos, actual_lowest_weight_pos); + mu_assert_int_eq(expected_lowest_weight_nbr, actual_lowest_weight_nbr); mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); From ec3e65cd9927544a12265f537371aca1f4d65d78 Mon Sep 17 00:00:00 2001 From: umeneses Date: Thu, 13 Jun 2024 16:39:54 -0300 Subject: [PATCH 27/66] checking in user send a list of numbers with a non-number --- _ci_tdd/test_files/test_main_miunit.c | 106 ++++++++++---------------- 1 file changed, 42 insertions(+), 64 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 109d32e..1540506 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/06/13 13:53:11 by umeneses ### ########.fr */ +/* Updated: 2024/06/13 16:39:17 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,48 +40,9 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -MU_TEST(test_1st_miastep_map_target_pos) -{ - // ARRANGE - t_stack *stack; - char **argv_simulation = NULL; - char *userinput; - int expected_size; - int actual_size; - int expected_top_a; - int actual_top_a; - int expected_bottom_a; - int actual_bottom_a; - // int expected_target_pos; - // int actual_target_pos; - // ACT - stack = NULL; - userinput = "./push_swap 2 42 1 4 8 5 31 27"; - argv_simulation = ft_split(userinput, ' '); - expected_size = ft_minunit_array_counter(argv_simulation); - expected_top_a = ft_atoi(argv_simulation[1]); - expected_bottom_a = ft_atoi(argv_simulation[8]); - - stack = ft_lts_buildstack_argv(&stack, argv_simulation); - // expected_target_pos = 3; - actual_size = ft_lst_size(stack); - ft_lst_map_all_indexers(&stack); - - // actual_target_pos = ft_lst_map_lowest_weight_position(&stack); - actual_bottom_a = ft_lst_goto_end(stack)->nbr; - actual_top_a = ft_lst_goto_head(stack)->nbr; - // ASSERT - // mu_assert_int_eq(expected_target_pos, actual_target_pos); - mu_assert_int_eq(expected_size, actual_size); - mu_assert_int_eq(expected_top_a, actual_top_a); - mu_assert_int_eq(expected_bottom_a, actual_bottom_a); - ft_lstclear_single_ptr(stack); - ft_array_clear(argv_simulation, expected_size); -} - -MU_TEST(test_1st_miastep_map_lowest_weight) +MU_TEST(test_3st_miastep_map_lowest_weight) { // ARRANGE t_stack *stack; @@ -129,7 +90,7 @@ MU_TEST(test_1st_miastep_map_lowest_weight) ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_1st_miastep_push_b_all_but3_sort_3a) +MU_TEST(test_2st_miastep_push_b_all_but3_sort_3a) { // ARRANGE t_stack *stack_a; @@ -621,6 +582,40 @@ MU_TEST(test_sort_2_nbrs_without_zero) ft_array_clear(argv_simulation, expected_size); } +MU_TEST(test_buildstack_non_nbr) +{ + // ARRANGE + char **argv_simulation = NULL; + char *userinput; + int index; + int expected_size; + int actual_size; + int expected_argv_validation; + int actual_argv_validation; + + // ACT + userinput = "./push_swap 1 3 5 2 4 7 a"; + argv_simulation = ft_split(userinput, ' '); + expected_size = 7; + expected_argv_validation = false; + actual_size = ft_minunit_array_counter(argv_simulation); + index = expected_size; + while (index >= 0) + { + if (!ft_isdigit(*argv_simulation[index])) + { + actual_argv_validation = false; + break ; + } + index--; + } + + // ASSERT + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_argv_validation, actual_argv_validation); + ft_array_clear(argv_simulation, expected_size); +} + MU_TEST(test_buildstack_argv) { // ARRANGE @@ -1300,24 +1295,6 @@ MU_TEST(test_lst_addto_begin) ft_lstclear_single_ptr(stack); } -// MU_TEST(test_lst_init_non_nbr) -// { -// // ARRANGE -// int char_test = 'a'; -// int expected_result; -// int actual_result; -// t_stack *stack; - -// // ACT -// stack = ft_lst_init(char_test); -// actual_result = stack->nbr; -// expected_result = '\0'; - -// // ASSERT -// mu_assert_int_eq(expected_result, actual_result); -// ft_lstclear_single_ptr(stack); -// } - MU_TEST(test_lstsize_int_expec_3) { // ARRANGE @@ -1368,7 +1345,6 @@ MU_TEST(test_lst_init_nbr) MU_TEST_SUITE(linked_list_tests) { MU_RUN_TEST(test_lst_init_nbr); - // MU_RUN_TEST(test_lst_init_non_nbr); MU_RUN_TEST(test_lstsize_int_expec_3); MU_RUN_TEST(test_lst_addto_begin); MU_RUN_TEST(test_lst_addto_end); @@ -1403,6 +1379,7 @@ MU_TEST_SUITE(argv_tests) MU_RUN_TEST(test_argv_is_duplicated_false); MU_RUN_TEST(test_argv_is_duplicated_true); MU_RUN_TEST(test_buildstack_argv); + MU_RUN_TEST(test_buildstack_non_nbr); } MU_TEST_SUITE(sorting_tests) @@ -1422,9 +1399,10 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_pos_index); MU_RUN_TEST(test_1st_miastep_weight_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); - MU_RUN_TEST(test_1st_miastep_push_b_all_but3_sort_3a); - MU_RUN_TEST(test_1st_miastep_map_lowest_weight); - MU_RUN_TEST(test_1st_miastep_map_target_pos); + MU_RUN_TEST(test_2st_miastep_push_b_all_but3_sort_3a); + MU_RUN_TEST(test_3st_miastep_map_lowest_weight); + MU_RUN_TEST(test_3st_miastep_map_get_target); + // MU_RUN_TEST(test_3st_miastep_map_get_target_position); } int main(void) From ad68f15ae75d7972dc5c42dcd1117003f0940df9 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 16:03:28 -0300 Subject: [PATCH 28/66] new push method, due the data addition at t_stack struct --- program_to_test/src/ft_push.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index 88fd1a2..8c5abef 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/05 18:52:29 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 15:48:18 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,22 +14,32 @@ void ft_push_a(t_stack **stack_a, t_stack **stack_b) { - int tobe_pushed; + t_stack *to_be_pushed; if (*stack_a == NULL || *stack_b == NULL) return ; - tobe_pushed = (*stack_b)->nbr; - *stack_a = ft_lst_addto_begin(stack_a, ft_lst_init(tobe_pushed)); - *stack_b = ft_lst_delat_begin(*stack_b); + to_be_pushed = (*stack_b); + (*stack_b) = (*stack_b)->next; + (*stack_b)->prev = NULL; + to_be_pushed->next = NULL; + to_be_pushed->prev = NULL; + to_be_pushed->next = (*stack_a); + (*stack_a)->prev = to_be_pushed; + (*stack_a) = ft_lst_goto_head(*stack_a); } void ft_push_b(t_stack **stack_a, t_stack **stack_b) { - int tobe_pushed; + t_stack *to_be_pushed; if (*stack_a == NULL || *stack_b == NULL) return ; - tobe_pushed = (*stack_a)->nbr; - *stack_b = ft_lst_addto_begin(stack_b, ft_lst_init(tobe_pushed)); - *stack_a = ft_lst_delat_begin(*stack_a); + to_be_pushed = (*stack_a); + (*stack_a) = (*stack_a)->next; + (*stack_a)->prev = NULL; + to_be_pushed->next = NULL; + to_be_pushed->prev = NULL; + to_be_pushed->next = (*stack_b); + (*stack_b)->prev = to_be_pushed; + (*stack_b) = ft_lst_goto_head(*stack_b); } From 372e1a54409eda5870ce90d8c68d383d9226b35c Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 16:30:48 -0300 Subject: [PATCH 29/66] new reverse rotate method, due the data addition at t_stack struct --- program_to_test/src/ft_rotate.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/program_to_test/src/ft_rotate.c b/program_to_test/src/ft_rotate.c index f7136b7..f32e3af 100644 --- a/program_to_test/src/ft_rotate.c +++ b/program_to_test/src/ft_rotate.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/23 11:48:11 by umeneses #+# #+# */ -/* Updated: 2024/06/05 18:53:01 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 16:29:18 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,13 +41,16 @@ void ft_rotate_ab(t_stack **stack_a, t_stack **stack_b) void ft_reverse_rotate(t_stack **stack) { - int temp; + t_stack *last_node; - if (*stack == NULL || (*stack)->next == NULL) + if (*stack == NULL || (*stack)->next == NULL || ft_lst_size(*stack) < 2) return ; - temp = ft_lst_goto_end(*stack)->nbr; - *stack = ft_lst_addto_begin(stack, ft_lst_init(temp)); - *stack = ft_lst_delat_end(*stack); + last_node = ft_lst_goto_end(*stack); + last_node->prev->next = NULL; + last_node->next = (*stack); + last_node->prev = NULL; + *stack = last_node; + (*stack)->next->prev = last_node; } void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b) From 6662772ff704a80ff878a2a2b680609cd4c749df Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 17:43:27 -0300 Subject: [PATCH 30/66] fixing NULL pointer, while printing --- program_to_test/src/ft_lst_init.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index b7a2eb8..2db3194 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/11 10:02:46 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:41:58 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,10 +62,9 @@ void ft_lst_printf_int_content(char *msg, t_stack *list) list = ft_lst_goto_head(list); temp = list; - ft_printf("%s %d\n", msg, temp->nbr); - while (temp->next != NULL) + while (temp) { - temp = temp->next; ft_printf("%s %d\n", msg, temp->nbr); + temp = temp->next; } } From fa2ff8bb060e144fa2f2fa30076ffbe39cd1d2e7 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 17:43:58 -0300 Subject: [PATCH 31/66] fixing NULL checker --- program_to_test/src/ft_rotate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_rotate.c b/program_to_test/src/ft_rotate.c index f32e3af..29b60a9 100644 --- a/program_to_test/src/ft_rotate.c +++ b/program_to_test/src/ft_rotate.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/23 11:48:11 by umeneses #+# #+# */ -/* Updated: 2024/06/14 16:29:18 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:40:28 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ void ft_reverse_rotate(t_stack **stack) { t_stack *last_node; - if (*stack == NULL || (*stack)->next == NULL || ft_lst_size(*stack) < 2) + if (NULL == *stack || NULL == (*stack)->next || ft_lst_size(*stack) < 2) return ; last_node = ft_lst_goto_end(*stack); last_node->prev->next = NULL; From 28d9da51cddb1eb1412e074ef7d7cb27404f483d Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 17:44:34 -0300 Subject: [PATCH 32/66] better protecting pointer --- program_to_test/src/ft_push.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index 8c5abef..2b14099 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/14 15:48:18 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:35:05 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,8 @@ void ft_push_a(t_stack **stack_a, t_stack **stack_b) return ; to_be_pushed = (*stack_b); (*stack_b) = (*stack_b)->next; - (*stack_b)->prev = NULL; + if ((*stack_b)) + (*stack_b)->prev = NULL; to_be_pushed->next = NULL; to_be_pushed->prev = NULL; to_be_pushed->next = (*stack_a); From e0f7bf4fd88bffac146a0f731e8e7de571bc098b Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 17:45:47 -0300 Subject: [PATCH 33/66] adding new file and fixing bonus caller --- program_to_test/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/program_to_test/Makefile b/program_to_test/Makefile index 512534c..ffd8ae0 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/10 16:20:06 by umeneses ### ########.fr # +# Updated: 2024/06/13 18:43:41 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -56,6 +56,7 @@ SRC_FILES += ft_lst_clear.c SRC_FILES += ft_lst_deletes.c SRC_FILES += ft_lst_goto.c SRC_FILES += ft_lst_init.c +SRC_FILES += ft_lst_map_all.c SRC_FILES += ft_lst_map_indexers.c SRC_FILES += ft_sort_until3.c SRC_FILES += ft_sort_4_or_more.c @@ -76,7 +77,7 @@ NAME_BONUS = push_swap_bonus SRC_FILES_BONUS = -SRC_BONUS_ALL = $(addprefix $(SRC_SV_BONUS_D), $(SRC_FILES_BONUS)) +SRC_BONUS_ALL = $(addprefix $(SRC_BONUS_D), $(SRC_FILES_BONUS)) OBJS_FILES_BONUS = $(addprefix $(BUILD_D), $(SRC_BONUS_ALL:%.c=%.o)) OBJS_ALL_BONUS = $(OBJS_FILES_BONUS) From 5481310237c924ed83dd297391a62d2977e0a429 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:05:11 -0300 Subject: [PATCH 34/66] updating to print all data from stack --- program_to_test/src/ft_lst_init.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index 2db3194..b33d2a1 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:41:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:56:49 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,9 @@ void ft_lst_printf_int_content(char *msg, t_stack *list) temp = list; while (temp) { - ft_printf("%s %d\n", msg, temp->nbr); + ft_printf("%s\tnbr[%d]\tpos[%d]\t",msg, temp->nbr, temp->pos); + ft_printf("weight[%d]\ttarget[%d]\t", temp->weight, temp->target); + ft_printf("cost_a[%d]\tcost_b[%d]\n", temp->cost_a, temp->cost_b); temp = temp->next; } } From d9f9c1a31709497f8df98e17dc6bc003748b4e99 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:14:04 -0300 Subject: [PATCH 35/66] adding map all indexers --- program_to_test/src/ft_lst_map_all.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 program_to_test/src/ft_lst_map_all.c diff --git a/program_to_test/src/ft_lst_map_all.c b/program_to_test/src/ft_lst_map_all.c new file mode 100644 index 0000000..b8d6b06 --- /dev/null +++ b/program_to_test/src/ft_lst_map_all.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_map_all.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: umeneses +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/13 18:41:22 by umeneses #+# #+# */ +/* Updated: 2024/06/13 18:41:32 by umeneses ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void ft_lst_map_all_indexers(t_stack **stack) +{ + int stack_size; + + stack_size = ft_lst_size(*stack); + ft_lst_map_position(stack); + ft_lst_map_weight(stack, stack_size); +} From 885082f2cd8f9d2965b7e45eb55e9ed2c4b63119 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:23:01 -0300 Subject: [PATCH 36/66] cleaning the main --- program_to_test/src/push_main.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index eeb923d..d2f27f0 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:26:15 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:48:20 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,20 +25,9 @@ int main(int argc, char **argv) ft_lst_printf_int_content("original main:", stack_a); ft_lst_map_all_indexers(&stack_a); ft_do_sort(&stack_a, &stack_b); - ft_lst_printf_int_content("updated stack_a:", stack_a); - ft_lst_printf_int_content("updated stack_b:", stack_b); + ft_lst_printf_int_content("updated main stack_a:", stack_a); + ft_lst_printf_int_content("updated main stack_b:", stack_b); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); return (0); } - - // stack_a = ft_lst_goto_head(stack_a); - // while (stack_a->next !=NULL) - // { - // ft_printf("stack_a pos[%d] main = %d and weight = %d\n", - // stack_a->pos, stack_a->nbr, stack_a->weight); - // stack_a = stack_a->next; - // if (stack_a->next ==NULL) - // ft_printf("stack_a pos[%d] main = %d and weight = %d\n", - // stack_a->pos, stack_a->nbr, stack_a->weight); - // } \ No newline at end of file From e81dd554914d5dbfa2605542b6a0214ae62d1ea3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:23:33 -0300 Subject: [PATCH 37/66] adding new data at struct, and new functions --- program_to_test/headers/push_swap.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 259bbef..ad07682 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/11 18:52:44 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:49:46 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,11 @@ typedef struct s_stack { int nbr; - int cost; int pos; int weight; int target; + int cost_a; + int cost_b; struct s_stack *prev; struct s_stack *next; } t_stack; @@ -58,23 +59,29 @@ void ft_reverse_rotate(t_stack **stack); void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); /* basic push_swap functions */ -void ft_lst_map_all_indexers(t_stack **stack); -void ft_lst_map_position(t_stack **stack); -void ft_lst_map_weight(t_stack **stack, int stack_size); -int ft_lst_map_lowest_weight_position(t_stack **stack); - bool ft_is_sorted(t_stack *stack); /* sorting validation functions */ 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_or_more_nbrs(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_nbr(t_stack **stack_a, int b_weight, +int ft_lst_get_target(t_stack **stack_a, int b_weight, int target_weight, int target_pos); void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b); -/* sorting functions */ +void ft_lst_map_all_indexers(t_stack **stack); +void ft_lst_map_position(t_stack **stack); +void ft_lst_map_weight(t_stack **stack, int stack_size); +int ft_lst_map_lowest_weight_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); +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_do_swap_a(t_stack **stack); void ft_do_swap_b(t_stack **stack); From 673f566c22bb04cf72f15928fa6795719095bbc7 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:24:29 -0300 Subject: [PATCH 38/66] fixing loop --- program_to_test/src/ft_lst_map_indexers.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index a449e80..08beadd 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:38:16 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:31:07 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,6 +68,7 @@ int ft_lst_map_lowest_weight_position(t_stack **stack) temp = *stack; lowest_weight = INT_MAX; + ft_lst_map_position(stack); lowest_position = temp->pos; while (temp) { @@ -81,7 +82,7 @@ int ft_lst_map_lowest_weight_position(t_stack **stack) return (lowest_position); } -int ft_lst_get_target_nbr(t_stack **stack_a, int b_weight, +int ft_lst_get_target(t_stack **stack_a, int b_weight, int target_weight, int target_pos) { t_stack *temp_a; @@ -94,6 +95,7 @@ int ft_lst_get_target_nbr(t_stack **stack_a, int b_weight, target_weight = temp_a->weight; target_pos = temp_a->pos; } + temp_a = temp_a->next; } if (target_weight != INT_MAX) return (target_pos); @@ -121,7 +123,7 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) target_position = 0; while (temp_b) { - target_position = ft_lst_get_target_nbr(stack_a, temp_b->weight, + target_position = ft_lst_get_target(stack_a, temp_b->weight, INT_MAX, target_position); temp_b->target = target_position; temp_b = temp_b->next; From d3a0463f8033071cdf13b0897cdf69502514a8c2 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:25:14 -0300 Subject: [PATCH 39/66] adding tester for get target --- _ci_tdd/test_files/test_main_miunit.c | 173 ++++++++++++++++++++++++-- 1 file changed, 166 insertions(+), 7 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 1540506..0e181fe 100644 --- a/_ci_tdd/test_files/test_main_miunit.c +++ b/_ci_tdd/test_files/test_main_miunit.c @@ -6,13 +6,14 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */ -/* Updated: 2024/06/13 16:39:17 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 17:17:51 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "minunit.h" #include "push_swap.h" #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" #include "../../program_to_test/src/ft_lst_init.c" #include "../../program_to_test/src/ft_lst_goto.c" @@ -26,6 +27,7 @@ #include "../../program_to_test/src/ft_do_rev_rotate_fts.c" #include "../../program_to_test/src/ft_do_rotate_fts.c" #include "../../program_to_test/src/ft_do_swap_fts.c" +#include "../../program_to_test/src/ft_do_sort.c" #include "../../program_to_test/src/ft_sort_until3.c" #include "../../program_to_test/src/ft_sort_4_or_more.c" // #include "minunit_utils.c" @@ -40,9 +42,165 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); +// MU_TEST(test_3rd_miastep_map_get_target_position) +// { +// // ARRANGE +// t_stack *stack_a; +// t_stack *stack_b; +// char **argv_simulation = NULL; +// char *userinput; +// int expected_size; +// int actual_size; +// int expected_top_a; +// int actual_top_a; +// int expected_bottom_a; +// int actual_bottom_a; +// int expected_target_pos; +// int actual_target_pos; + +// // ACT +// stack_a = NULL; +// stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); +// userinput = "./push_swap 2 42 1 4 8 5 31 27"; +// argv_simulation = ft_split(userinput, ' '); +// expected_size = ft_minunit_array_counter(argv_simulation); +// expected_top_a = ft_atoi(argv_simulation[1]); +// expected_bottom_a = ft_atoi(argv_simulation[8]); + +// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); +// expected_target_pos = 8; // argv[8] = 42; +// 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_lst_get_target_position(&stack_a, &stack_b); + +// actual_target_pos = ft_lst_goto_end(stack_b)->nbr; +// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; +// actual_top_a = ft_lst_goto_head(stack_a)->nbr; + +// // ASSERT +// mu_assert_int_eq(expected_target_pos, actual_target_pos); +// mu_assert_int_eq(expected_size, actual_size); +// mu_assert_int_eq(expected_top_a, actual_top_a); +// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); +// ft_lstclear_single_ptr(stack_a); +// ft_lstclear_single_ptr(stack_b); +// ft_array_clear(argv_simulation, expected_size); +// } + + + +MU_TEST(test_3rd_miastep_get_cost) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_cost; + int actual_cost; + + // ACT + stack_a = NULL; + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[8]); + expected_bottom_a = ft_atoi(argv_simulation[2]); + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + expected_cost = 0; // stack_b->nbr[8] + 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_lst_get_cost(&stack_a, &stack_b); + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + ft_lst_printf_int_content("stack_a:", stack_a); + ft_lst_printf_int_content("stack_b:", stack_b); + t_stack *temp; + temp = stack_b; + while (temp) + { + ft_printf("nbr[%d] in pos[%d] target [%d] has cost = %d\n", temp->nbr, temp->pos, temp->target, temp->cost_b); + temp = temp->next; + } + actual_cost = stack_b->next->cost_b; + // ASSERT + mu_assert_int_eq(expected_cost, actual_cost); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_3rd_miastep_map_get_target) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_target_pos; + int actual_target_pos; + + // ACT + stack_a = NULL; + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[8]); + expected_bottom_a = ft_atoi(argv_simulation[2]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + expected_target_pos = 5; // stack_b->pos[5] + 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); + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + + ft_lst_get_target_position(&stack_a, &stack_b); + actual_target_pos = stack_b->target; + t_stack *temp; + temp = stack_b; + while (temp) + { + ft_printf("nbr[%d] in pos[%d] has target [%d]\n", temp->nbr, temp->pos, temp->target); + temp = temp->next; + } + + + // ASSERT + mu_assert_int_eq(expected_target_pos, actual_target_pos); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size); +} -MU_TEST(test_3st_miastep_map_lowest_weight) +MU_TEST(test_3rd_miastep_map_lowest_weight) { // ARRANGE t_stack *stack; @@ -90,7 +248,7 @@ MU_TEST(test_3st_miastep_map_lowest_weight) ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_2st_miastep_push_b_all_but3_sort_3a) +MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) { // ARRANGE t_stack *stack_a; @@ -1399,10 +1557,11 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_1st_miastep_pos_index); MU_RUN_TEST(test_1st_miastep_weight_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); - MU_RUN_TEST(test_2st_miastep_push_b_all_but3_sort_3a); - MU_RUN_TEST(test_3st_miastep_map_lowest_weight); - MU_RUN_TEST(test_3st_miastep_map_get_target); - // MU_RUN_TEST(test_3st_miastep_map_get_target_position); + MU_RUN_TEST(test_2nd_miastep_push_b_all_but3_sort_3a); + MU_RUN_TEST(test_3rd_miastep_map_lowest_weight); + MU_RUN_TEST(test_3rd_miastep_get_cost); + MU_RUN_TEST(test_3rd_miastep_map_get_target); + // MU_RUN_TEST(test_3rd_miastep_map_get_target_position); } int main(void) From aec2d376904e999fb45fc62582181ed2f045bc63 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:28:57 -0300 Subject: [PATCH 40/66] adding do_cheapest, do_move_after_cheapest, and shift_stack --- program_to_test/src/ft_do_sort.c | 14 +++- program_to_test/src/ft_sort_4_or_more.c | 106 +++++++++++++++++++----- 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 549b605..5a83691 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/11 17:53:09 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 18:18:13 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,3 +24,15 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) ft_sort_four_or_more_nbrs(stack_a, stack_b); } } + +void ft_do_move_after_cheapest(t_stack **stack_a, t_stack **stack_b, + int cost_a, int cost_b) +{ + if (cost_a < 0 && cost_b < 0) + ft_do_reverse_rotate_ab(stack_a, stack_b); + else if (cost_a > 0 && cost_b > 0) + ft_do_rotate_ab(stack_a, stack_b); + ft_do_rotate_a(stack_a); + ft_do_rotate_b(stack_b); + ft_do_push_a(stack_a, stack_b); +} diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 35bccf7..5adc11c 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,38 +6,28 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/11 18:48:20 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 18:16:56 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_lst_map_all_indexers(t_stack **stack) -{ - int stack_size; - - stack_size = ft_lst_size(*stack); - ft_lst_map_position(stack); - ft_lst_map_weight(stack, stack_size); -} - -/* -* TODO after line 40: -* while (*stack_b) -* { -* ft_lst_get_target_position(stack_a, stack_b); -* ft_lst_get_cost(stack_a, stack_b); -* ft_lst_do_cheapest_move(stack_a, stack_b); -* } -* if (!ft_is_sorted(*stack_a)) -* { -* ft_lst_shift_stack(stack_a); -* } -*/ void ft_sort_four_or_more_nbrs(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_lst_printf_int_content("stack_a before get-target:", *stack_a); + ft_lst_printf_int_content("stack_b before get-target:", *stack_b); + while (*stack_b) + { + ft_lst_get_target_position(stack_a, stack_b); + ft_lst_get_cost(stack_a, stack_b); + ft_lst_do_cheapest_move(stack_a, stack_b); + } + ft_lst_printf_int_content("stack_a after get-target:", *stack_a); + ft_lst_printf_int_content("stack_b after get-target:", *stack_b); + if (!ft_is_sorted(*stack_a)) + ft_lst_shift_stack(stack_a); } void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) @@ -68,3 +58,73 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) } *stack_b = ft_lst_delat_end(*stack_b); } + +void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b) +{ + int size_a; + int size_b; + t_stack *temp_a; + t_stack *temp_b; + + temp_a = *stack_a; + temp_b = *stack_b; + size_a = ft_lst_size(temp_a); + size_b = ft_lst_size(temp_b); + while (temp_b) + { + temp_b->cost_b = temp_b->pos; + if (temp_b->pos > size_b / 2) + temp_b->cost_b = (size_b - temp_b->pos) * -1; + temp_b->cost_a = temp_b->target; + if (temp_b->target > size_a / 2) + temp_b->cost_a = (size_a - temp_b->target) * -1; + temp_b = temp_b->next; + } +} + +void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b) +{ + int cost_a; + int cost_b; + int cheapest; + t_stack *temp_b; + + temp_b = *stack_b; + cheapest = INT_MAX; + while (temp_b) + { + if ((temp_b->cost_a + temp_b->cost_b) < cheapest) + { + cheapest = temp_b->cost_b + temp_b->cost_a; + cost_a = temp_b->cost_a; + cost_b = temp_b->cost_b; + } + temp_b = temp_b->next; + } + ft_do_move_after_cheapest(stack_a, stack_b, cost_a, cost_b); +} + +void ft_lst_shift_stack(t_stack **stack_a) +{ + int lowest_weight_pos; + int stack_size; + + stack_size = ft_lst_size(*stack_a); + lowest_weight_pos = ft_lst_map_lowest_weight_position(stack_a); + if (lowest_weight_pos < stack_size / 2) + { + while (lowest_weight_pos < stack_size) + { + ft_do_reverse_rotate_a(stack_a); + lowest_weight_pos++; + } + } + else + { + while (lowest_weight_pos > 0) + { + ft_do_rotate_a(stack_a); + lowest_weight_pos--; + } + } +} From d22f5c44674b800ab5585207602d0d1128e661c7 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 14 Jun 2024 18:32:14 -0300 Subject: [PATCH 41/66] better protecting null pointer --- program_to_test/src/ft_push.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index 2b14099..d4d7be1 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:35:05 by umeneses ### ########.fr */ +/* Updated: 2024/06/14 18:11:59 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,8 @@ void ft_push_b(t_stack **stack_a, t_stack **stack_b) return ; to_be_pushed = (*stack_a); (*stack_a) = (*stack_a)->next; - (*stack_a)->prev = NULL; + if ((*stack_a)) + (*stack_a)->prev = NULL; to_be_pushed->next = NULL; to_be_pushed->prev = NULL; to_be_pushed->next = (*stack_b); From 04ecfb7b7de1e7b833d48b984acd0c8c90529cd3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 11:07:08 -0300 Subject: [PATCH 42/66] updating data item structure name :: weight -> final_pos --- _ci_tdd/test_files/test_main_miunit.c | 48 ++++++++++---------- program_to_test/headers/push_swap.h | 12 ++--- program_to_test/src/ft_lst_init.c | 4 +- program_to_test/src/ft_lst_map_all.c | 4 +- program_to_test/src/ft_lst_map_indexers.c | 54 +++++++++++------------ program_to_test/src/ft_sort_4_or_more.c | 18 ++++---- 6 files changed, 70 insertions(+), 70 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 0e181fe..ce352b7 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/06/14 17:17:51 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:05:49 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -200,7 +200,7 @@ MU_TEST(test_3rd_miastep_map_get_target) ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_3rd_miastep_map_lowest_weight) +MU_TEST(test_3rd_miastep_map_lowest_final_pos) { // ARRANGE t_stack *stack; @@ -212,10 +212,10 @@ MU_TEST(test_3rd_miastep_map_lowest_weight) int actual_top_a; int expected_bottom_a; int actual_bottom_a; - int expected_lowest_weight_pos; - int expected_lowest_weight_nbr; - int actual_lowest_weight_pos; - int actual_lowest_weight_nbr; + int expected_lowest_final_pos_pos; + int expected_lowest_final_pos_nbr; + int actual_lowest_final_pos_pos; + int actual_lowest_final_pos_nbr; // ACT stack = NULL; @@ -226,21 +226,21 @@ MU_TEST(test_3rd_miastep_map_lowest_weight) expected_bottom_a = ft_atoi(argv_simulation[8]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); - expected_lowest_weight_pos = 3; // argv[3] = 1; - expected_lowest_weight_nbr = ft_atoi(argv_simulation[expected_lowest_weight_pos]); + expected_lowest_final_pos_pos = 3; // argv[3] = 1; + expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); actual_size = ft_lst_size(stack); ft_lst_map_position(&stack); - ft_lst_map_weight(&stack, expected_size); + ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; - actual_lowest_weight_pos = ft_lst_map_lowest_weight_position(&stack); + actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); actual_bottom_a = ft_lst_goto_end(stack)->nbr; - actual_lowest_weight_nbr = stack->next->next->nbr; + actual_lowest_final_pos_nbr = stack->next->next->nbr; // ASSERT - mu_assert_int_eq(expected_lowest_weight_pos, actual_lowest_weight_pos); - mu_assert_int_eq(expected_lowest_weight_nbr, actual_lowest_weight_nbr); + mu_assert_int_eq(expected_lowest_final_pos_pos, actual_lowest_final_pos_pos); + mu_assert_int_eq(expected_lowest_final_pos_nbr, actual_lowest_final_pos_nbr); mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); @@ -287,7 +287,7 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; ft_lst_map_position(&stack_a); - ft_lst_map_weight(&stack_a, expected_size_before_push); + ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_three_nbrs(&stack_a); @@ -351,7 +351,7 @@ MU_TEST(test_1st_miastep_push_b_all_but3) actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; ft_lst_map_position(&stack_a); - ft_lst_map_weight(&stack_a, expected_size_before_push); + ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); expected_top_a_after_push = ft_atoi(argv_simulation[4]); @@ -375,7 +375,7 @@ MU_TEST(test_1st_miastep_push_b_all_but3) ft_array_clear(argv_simulation, expected_size_before_push); } -MU_TEST(test_1st_miastep_weight_index) +MU_TEST(test_1st_miastep_final_pos_index) { // ARRANGE t_stack *stack; @@ -387,8 +387,8 @@ MU_TEST(test_1st_miastep_weight_index) int actual_top_a; int expected_bottom_a; int actual_bottom_a; - int expected_highest_weight; - int actual_highest_weight; + int expected_highest_final_pos; + int actual_highest_final_pos; // ACT stack = NULL; @@ -397,25 +397,25 @@ MU_TEST(test_1st_miastep_weight_index) expected_size = ft_minunit_array_counter(argv_simulation); expected_top_a = ft_atoi(argv_simulation[1]); expected_bottom_a = ft_atoi(argv_simulation[8]); - expected_highest_weight = expected_size - 1; + expected_highest_final_pos = expected_size - 1; stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); ft_lst_map_position(&stack); - ft_lst_map_weight(&stack, expected_size); + ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; while (stack->pos <= 2) { stack = stack->next; if (stack->pos == 2) - actual_highest_weight = stack->weight; + actual_highest_final_pos = stack->final_pos; } actual_bottom_a = ft_lst_goto_end(stack)->nbr; // ASSERT - mu_assert_int_eq(expected_highest_weight, actual_highest_weight); + mu_assert_int_eq(expected_highest_final_pos, actual_highest_final_pos); mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); @@ -1555,10 +1555,10 @@ MU_TEST_SUITE(sorting_tests) MU_TEST_SUITE(miacombeau_tests) { MU_RUN_TEST(test_1st_miastep_pos_index); - MU_RUN_TEST(test_1st_miastep_weight_index); + MU_RUN_TEST(test_1st_miastep_final_pos_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); MU_RUN_TEST(test_2nd_miastep_push_b_all_but3_sort_3a); - MU_RUN_TEST(test_3rd_miastep_map_lowest_weight); + MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); MU_RUN_TEST(test_3rd_miastep_get_cost); MU_RUN_TEST(test_3rd_miastep_map_get_target); // MU_RUN_TEST(test_3rd_miastep_map_get_target_position); diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index ad07682..b6528ff 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/14 17:49:46 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:00:17 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ typedef struct s_stack { int nbr; int pos; - int weight; + int final_pos; int target; int cost_a; int cost_b; @@ -69,13 +69,13 @@ t_stack *ft_sort_three_nbrs(t_stack **stack); void ft_sort_four_or_more_nbrs(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_weight, - int target_weight, int target_pos); +int ft_lst_get_target(t_stack **stack_a, int b_ideal_pos, + int target_ideal_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_position(t_stack **stack); -void ft_lst_map_weight(t_stack **stack, int stack_size); -int ft_lst_map_lowest_weight_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); void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b); diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index b33d2a1..a3389ec 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:56:49 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:03:12 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,7 +65,7 @@ void ft_lst_printf_int_content(char *msg, t_stack *list) while (temp) { ft_printf("%s\tnbr[%d]\tpos[%d]\t",msg, temp->nbr, temp->pos); - ft_printf("weight[%d]\ttarget[%d]\t", temp->weight, temp->target); + ft_printf("final_pos[%d]\ttarget[%d]\t", temp->final_pos, temp->target); ft_printf("cost_a[%d]\tcost_b[%d]\n", temp->cost_a, temp->cost_b); temp = temp->next; } diff --git a/program_to_test/src/ft_lst_map_all.c b/program_to_test/src/ft_lst_map_all.c index b8d6b06..f1c454d 100644 --- a/program_to_test/src/ft_lst_map_all.c +++ b/program_to_test/src/ft_lst_map_all.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/13 18:41:22 by umeneses #+# #+# */ -/* Updated: 2024/06/13 18:41:32 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:03:38 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,5 +18,5 @@ void ft_lst_map_all_indexers(t_stack **stack) stack_size = ft_lst_size(*stack); ft_lst_map_position(stack); - ft_lst_map_weight(stack, stack_size); + ft_lst_map_final_pos(stack, stack_size); } diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 08beadd..fcd26c5 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:31:07 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:02:25 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,24 +31,24 @@ void ft_lst_map_position(t_stack **stack) *stack = ft_lst_goto_head(*stack); } -void ft_lst_map_weight(t_stack **stack, int stack_size) +void ft_lst_map_final_pos(t_stack **stack, int stack_size) { - int weight; + int final_pos; t_stack *target; t_stack *highest; while (--stack_size > 0) { target = *stack; - weight = INT_MIN; + final_pos = INT_MIN; highest = NULL; while (target) { - if (target->nbr == INT_MIN && target->weight == 0) - target->weight = 1; - if (target->nbr > weight && target->weight == 0) + if (target->nbr == INT_MIN && target->final_pos == 0) + target->final_pos = 1; + if (target->nbr > final_pos && target->final_pos == 0) { - weight = target->nbr; + final_pos = target->nbr; highest = target; target = *stack; } @@ -56,25 +56,25 @@ void ft_lst_map_weight(t_stack **stack, int stack_size) target = target->next; } if (highest != NULL) - highest->weight = stack_size; + highest->final_pos = stack_size; } } -int ft_lst_map_lowest_weight_position(t_stack **stack) +int ft_lst_map_lowest_final_position(t_stack **stack) { - int lowest_weight; + int lowest_final_pos; int lowest_position; t_stack *temp; temp = *stack; - lowest_weight = INT_MAX; + lowest_final_pos = INT_MAX; ft_lst_map_position(stack); lowest_position = temp->pos; while (temp) { - if (temp->weight < lowest_weight) + if (temp->final_pos < lowest_final_pos) { - lowest_weight = temp->weight; + lowest_final_pos = temp->final_pos; lowest_position = temp->pos; } temp = temp->next; @@ -82,29 +82,29 @@ int ft_lst_map_lowest_weight_position(t_stack **stack) return (lowest_position); } -int ft_lst_get_target(t_stack **stack_a, int b_weight, - int target_weight, int target_pos) +int ft_lst_get_target(t_stack **stack_a, int b_final_pos, + int target_final_pos, int target_pos) { t_stack *temp_a; temp_a = *stack_a; while (temp_a) { - if (temp_a->weight > b_weight && temp_a->weight < target_weight) + if (temp_a->final_pos > b_final_pos && temp_a->final_pos < target_final_pos) { - target_weight = temp_a->weight; + target_final_pos = temp_a->final_pos; target_pos = temp_a->pos; } temp_a = temp_a->next; } - if (target_weight != INT_MAX) + if (target_final_pos != INT_MAX) return (target_pos); temp_a = *stack_a; while (temp_a) { - if (temp_a->weight < target_weight) + if (temp_a->final_pos < target_final_pos) { - target_weight = temp_a->weight; + target_final_pos = temp_a->final_pos; target_pos = temp_a->pos; } temp_a = temp_a->next; @@ -123,29 +123,29 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) target_position = 0; while (temp_b) { - target_position = ft_lst_get_target(stack_a, temp_b->weight, + target_position = ft_lst_get_target(stack_a, temp_b->final_pos, INT_MAX, target_position); temp_b->target = target_position; temp_b = temp_b->next; } } -// void ft_lst_map_weight_by_argv(t_stack **stack, char **argv) +// void ft_lst_map_final_pos_by_argv(t_stack **stack, char **argv) // { -// int weight; +// int final_pos; // int pos; // char **argv_splited; // t_stack *temp; -// weight = 0; +// final_pos = 0; // pos = 0; -// weight = 0; +// final_pos = 0; // temp = *stack; // argv_splited = ft_split(*argv, ' '); // while ((argv_splited[pos] != NULL) && (temp->next != NULL)) // { // if (ft_atoi(argv_splited[pos]) > ft_atoi(argv_splited[pos + 1])) -// temp->weight = weight++; +// temp->final_pos = final_pos++; // temp = temp->next; // } // } diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 5adc11c..a40d842 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/14 18:16:56 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:04:08 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,7 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) while ((stack_size > 6) && (index < stack_size) && (pushed < stack_size / 2)) { - if ((*stack_a)->weight <= (stack_size / 2)) + if ((*stack_a)->final_pos <= (stack_size / 2)) { ft_do_push_b(stack_a, stack_b); pushed++; @@ -106,25 +106,25 @@ void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b) void ft_lst_shift_stack(t_stack **stack_a) { - int lowest_weight_pos; + int lowest_final_pos; int stack_size; stack_size = ft_lst_size(*stack_a); - lowest_weight_pos = ft_lst_map_lowest_weight_position(stack_a); - if (lowest_weight_pos < stack_size / 2) + lowest_final_pos = ft_lst_map_lowest_final_position(stack_a); + if (lowest_final_pos < stack_size / 2) { - while (lowest_weight_pos < stack_size) + while (lowest_final_pos < stack_size) { ft_do_reverse_rotate_a(stack_a); - lowest_weight_pos++; + lowest_final_pos++; } } else { - while (lowest_weight_pos > 0) + while (lowest_final_pos > 0) { ft_do_rotate_a(stack_a); - lowest_weight_pos--; + lowest_final_pos--; } } } From b176602eed109ea35257d3a9cc37e56ba187d364 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 11:18:34 -0300 Subject: [PATCH 43/66] updating data structure name :: pos -> origin --- _ci_tdd/test_files/test_main_miunit.c | 24 +++++++++--------- program_to_test/headers/push_swap.h | 6 ++--- program_to_test/src/ft_lst_init.c | 4 +-- program_to_test/src/ft_lst_map_all.c | 4 +-- program_to_test/src/ft_lst_map_indexers.c | 30 +++++++++++------------ program_to_test/src/ft_sort_4_or_more.c | 8 +++--- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index ce352b7..7da8d6b 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/06/18 11:05:49 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:17:00 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -131,7 +131,7 @@ MU_TEST(test_3rd_miastep_get_cost) temp = stack_b; while (temp) { - ft_printf("nbr[%d] in pos[%d] target [%d] has cost = %d\n", temp->nbr, temp->pos, temp->target, temp->cost_b); + ft_printf("nbr[%d] in origin[%d] target [%d] has cost = %d\n", temp->nbr, temp->origin, temp->target, temp->cost_b); temp = temp->next; } actual_cost = stack_b->next->cost_b; @@ -185,7 +185,7 @@ MU_TEST(test_3rd_miastep_map_get_target) temp = stack_b; while (temp) { - ft_printf("nbr[%d] in pos[%d] has target [%d]\n", temp->nbr, temp->pos, temp->target); + ft_printf("nbr[%d] in origin[%d] has target [%d]\n", temp->nbr, temp->origin, temp->target); temp = temp->next; } @@ -230,7 +230,7 @@ MU_TEST(test_3rd_miastep_map_lowest_final_pos) expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); actual_size = ft_lst_size(stack); - ft_lst_map_position(&stack); + ft_lst_map_original_position(&stack); ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); @@ -286,7 +286,7 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; - ft_lst_map_position(&stack_a); + ft_lst_map_original_position(&stack_a); ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_three_nbrs(&stack_a); @@ -350,7 +350,7 @@ MU_TEST(test_1st_miastep_push_b_all_but3) actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; - ft_lst_map_position(&stack_a); + ft_lst_map_original_position(&stack_a); ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); @@ -402,14 +402,14 @@ MU_TEST(test_1st_miastep_final_pos_index) stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); - ft_lst_map_position(&stack); + ft_lst_map_original_position(&stack); ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; - while (stack->pos <= 2) + while (stack->origin <= 2) { stack = stack->next; - if (stack->pos == 2) + if (stack->origin == 2) actual_highest_final_pos = stack->final_pos; } actual_bottom_a = ft_lst_goto_end(stack)->nbr; @@ -450,12 +450,12 @@ MU_TEST(test_1st_miastep_pos_index) stack = ft_lts_buildstack_argv(&stack, argv_simulation); actual_size = ft_lst_size(stack); - ft_lst_map_position(&stack); + ft_lst_map_original_position(&stack); actual_top_a = ft_lst_goto_head(stack)->nbr; - while (stack->pos <= 5) + while (stack->origin <= 5) { stack = stack->next; - if (stack->pos == 5) + if (stack->origin == 5) actual_fith_position = stack->nbr; } actual_bottom_a = 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 b6528ff..e3351b0 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/18 11:00:17 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:13:27 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ typedef struct s_stack { int nbr; - int pos; + int origin; int final_pos; int target; int cost_a; @@ -73,7 +73,7 @@ int ft_lst_get_target(t_stack **stack_a, int b_ideal_pos, int target_ideal_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_position(t_stack **stack); +void ft_lst_map_original_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); diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index a3389ec..9958000 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:03:12 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:14:18 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ void ft_lst_printf_int_content(char *msg, t_stack *list) temp = list; while (temp) { - ft_printf("%s\tnbr[%d]\tpos[%d]\t",msg, temp->nbr, temp->pos); + ft_printf("%s\tnbr[%d]\torigin[%d]\t",msg, temp->nbr, temp->origin); ft_printf("final_pos[%d]\ttarget[%d]\t", temp->final_pos, temp->target); ft_printf("cost_a[%d]\tcost_b[%d]\n", temp->cost_a, temp->cost_b); temp = temp->next; diff --git a/program_to_test/src/ft_lst_map_all.c b/program_to_test/src/ft_lst_map_all.c index f1c454d..fa5924c 100644 --- a/program_to_test/src/ft_lst_map_all.c +++ b/program_to_test/src/ft_lst_map_all.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/13 18:41:22 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:03:38 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:13:31 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,6 @@ void ft_lst_map_all_indexers(t_stack **stack) int stack_size; stack_size = ft_lst_size(*stack); - ft_lst_map_position(stack); + ft_lst_map_original_position(stack); ft_lst_map_final_pos(stack, stack_size); } diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index fcd26c5..b771b93 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,26 +6,26 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:02:25 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:15:38 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_lst_map_position(t_stack **stack) +void ft_lst_map_original_position(t_stack **stack) { - int pos; + int original_position; - pos = 0; + original_position = 0; while ((*stack)->next != NULL) { - pos++; - (*stack)->pos = pos; + original_position++; + (*stack)->origin = original_position; (*stack) = (*stack)->next; if ((*stack)->next == NULL) { - pos++; - (*stack)->pos = pos; + original_position++; + (*stack)->origin = original_position; } } *stack = ft_lst_goto_head(*stack); @@ -68,14 +68,14 @@ int ft_lst_map_lowest_final_position(t_stack **stack) temp = *stack; lowest_final_pos = INT_MAX; - ft_lst_map_position(stack); - lowest_position = temp->pos; + ft_lst_map_original_position(stack); + lowest_position = temp->origin; while (temp) { if (temp->final_pos < lowest_final_pos) { lowest_final_pos = temp->final_pos; - lowest_position = temp->pos; + lowest_position = temp->origin; } temp = temp->next; } @@ -93,7 +93,7 @@ int ft_lst_get_target(t_stack **stack_a, int b_final_pos, if (temp_a->final_pos > b_final_pos && temp_a->final_pos < target_final_pos) { target_final_pos = temp_a->final_pos; - target_pos = temp_a->pos; + target_pos = temp_a->origin; } temp_a = temp_a->next; } @@ -105,7 +105,7 @@ int ft_lst_get_target(t_stack **stack_a, int b_final_pos, if (temp_a->final_pos < target_final_pos) { target_final_pos = temp_a->final_pos; - target_pos = temp_a->pos; + target_pos = temp_a->origin; } temp_a = temp_a->next; } @@ -118,8 +118,8 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) t_stack *temp_b; temp_b = *stack_b; - ft_lst_map_position(stack_a); - ft_lst_map_position(stack_b); + ft_lst_map_original_position(stack_a); + ft_lst_map_original_position(stack_b); target_position = 0; while (temp_b) { diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index a40d842..3a51b1b 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:04:08 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:10:48 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,9 +72,9 @@ void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b) size_b = ft_lst_size(temp_b); while (temp_b) { - temp_b->cost_b = temp_b->pos; - if (temp_b->pos > size_b / 2) - temp_b->cost_b = (size_b - temp_b->pos) * -1; + temp_b->cost_b = temp_b->origin; + if (temp_b->origin > size_b / 2) + temp_b->cost_b = (size_b - temp_b->origin) * -1; temp_b->cost_a = temp_b->target; if (temp_b->target > size_a / 2) temp_b->cost_a = (size_a - temp_b->target) * -1; From 10114f403ec929f5468959a57d34019c35034afd Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 11:39:54 -0300 Subject: [PATCH 44/66] updating print list function name --- _ci_tdd/test_files/test_main_miunit.c | 23 +++++------------------ program_to_test/headers/push_swap.h | 4 ++-- program_to_test/src/ft_lst_init.c | 4 ++-- program_to_test/src/ft_sort_4_or_more.c | 10 +++++----- program_to_test/src/push_main.c | 8 ++++---- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 7da8d6b..066f819 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/06/18 11:17:00 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:37:49 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -125,15 +125,8 @@ MU_TEST(test_3rd_miastep_get_cost) ft_lst_get_cost(&stack_a, &stack_b); actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; actual_top_a = ft_lst_goto_head(stack_a)->nbr; - ft_lst_printf_int_content("stack_a:", stack_a); - ft_lst_printf_int_content("stack_b:", stack_b); - t_stack *temp; - temp = stack_b; - while (temp) - { - ft_printf("nbr[%d] in origin[%d] target [%d] has cost = %d\n", temp->nbr, temp->origin, temp->target, temp->cost_b); - temp = temp->next; - } + ft_lst_printf_data_content("get_cost stack_a:", stack_a); + ft_lst_printf_data_content("get_cost stack_b:", stack_b); actual_cost = stack_b->next->cost_b; // ASSERT mu_assert_int_eq(expected_cost, actual_cost); @@ -181,14 +174,8 @@ MU_TEST(test_3rd_miastep_map_get_target) ft_lst_get_target_position(&stack_a, &stack_b); actual_target_pos = stack_b->target; - t_stack *temp; - temp = stack_b; - while (temp) - { - ft_printf("nbr[%d] in origin[%d] has target [%d]\n", temp->nbr, temp->origin, temp->target); - temp = temp->next; - } - + ft_lst_printf_data_content("get_target stack_a:", stack_a); + ft_lst_printf_data_content("get_target stack_b:", stack_b); // ASSERT mu_assert_int_eq(expected_target_pos, actual_target_pos); diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index e3351b0..191fba7 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/18 11:13:27 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:34:21 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ 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_int_content(char *msg, 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); diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index 9958000..42c7da5 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:14:18 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:33:43 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ t_stack *ft_lts_buildstack_argv(t_stack **stack, char **argv) return (*stack); } -void ft_lst_printf_int_content(char *msg, t_stack *list) +void ft_lst_printf_data_content(char *msg, t_stack *list) { t_stack *temp; diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 3a51b1b..8d46b34 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:10:48 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:38:39 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,16 +16,16 @@ void ft_sort_four_or_more_nbrs(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_lst_printf_int_content("stack_a before get-target:", *stack_a); - ft_lst_printf_int_content("stack_b before get-target:", *stack_b); + ft_lst_printf_data_content("stack_a before get-target:", *stack_a); + ft_lst_printf_data_content("stack_b before get-target:", *stack_b); while (*stack_b) { ft_lst_get_target_position(stack_a, stack_b); ft_lst_get_cost(stack_a, stack_b); ft_lst_do_cheapest_move(stack_a, stack_b); } - ft_lst_printf_int_content("stack_a after get-target:", *stack_a); - ft_lst_printf_int_content("stack_b after get-target:", *stack_b); + ft_lst_printf_data_content("stack_a after get-target:", *stack_a); + ft_lst_printf_data_content("stack_b after get-target:", *stack_b); if (!ft_is_sorted(*stack_a)) ft_lst_shift_stack(stack_a); } diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index d2f27f0..09a1830 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:48:20 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 11:33:50 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,11 +22,11 @@ int main(int argc, char **argv) stack_a = NULL; stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); stack_a = ft_lts_buildstack_argv(&stack_a, argv); - ft_lst_printf_int_content("original main:", stack_a); + ft_lst_printf_data_content("original main:", stack_a); ft_lst_map_all_indexers(&stack_a); ft_do_sort(&stack_a, &stack_b); - ft_lst_printf_int_content("updated main stack_a:", stack_a); - ft_lst_printf_int_content("updated main stack_b:", stack_b); + ft_lst_printf_data_content("updated main stack_a:", stack_a); + ft_lst_printf_data_content("updated main stack_b:", stack_b); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); return (0); From 8c5a0abcc8b84602213b595c86f92c82f668b698 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 12:18:09 -0300 Subject: [PATCH 45/66] adding feedback, if list is empty --- program_to_test/src/ft_lst_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index 42c7da5..60a172f 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:33:43 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 12:16:52 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,4 +69,6 @@ void ft_lst_printf_data_content(char *msg, t_stack *list) ft_printf("cost_a[%d]\tcost_b[%d]\n", temp->cost_a, temp->cost_b); temp = temp->next; } + if (list == NULL) + ft_printf("%s\tEmpty list\n", msg); } From 5423f37dbdd5a37a63c051c1fc60a842f0e0a1d4 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:08:39 -0300 Subject: [PATCH 46/66] adding a protection --- program_to_test/src/ft_lst_goto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_lst_goto.c b/program_to_test/src/ft_lst_goto.c index a88e880..4d22959 100644 --- a/program_to_test/src/ft_lst_goto.c +++ b/program_to_test/src/ft_lst_goto.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/08 17:26:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 15:01:57 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,5 +36,7 @@ t_stack *ft_lst_goto_head(t_stack *list) return (NULL); while (list->prev) list = list->prev; + if (list->prev == NULL) + return (list); return (list); } From 401f94596049776144af4495d16267a78582f498 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:09:01 -0300 Subject: [PATCH 47/66] adding a protection --- program_to_test/src/ft_do_sort.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 5a83691..84d5b5b 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/14 18:18:13 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 14:03:19 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,9 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) else if (ft_lst_size(*stack_a) == 3) ft_sort_three_nbrs(stack_a); else + { ft_sort_four_or_more_nbrs(stack_a, stack_b); + } } } From 338c2935e3c608996af82160655919c20db8c7c5 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:10:05 -0300 Subject: [PATCH 48/66] updating function position to actual position --- program_to_test/src/ft_lst_map_all.c | 4 +- program_to_test/src/ft_lst_map_indexers.c | 47 +++++++---------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/program_to_test/src/ft_lst_map_all.c b/program_to_test/src/ft_lst_map_all.c index fa5924c..6bdde69 100644 --- a/program_to_test/src/ft_lst_map_all.c +++ b/program_to_test/src/ft_lst_map_all.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/13 18:41:22 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:13:31 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 13:53:02 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,6 @@ void ft_lst_map_all_indexers(t_stack **stack) int stack_size; stack_size = ft_lst_size(*stack); - ft_lst_map_original_position(stack); + ft_lst_map_actual_position(stack); ft_lst_map_final_pos(stack, stack_size); } diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index b771b93..8d2285b 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,26 +6,26 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:15:38 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:07:48 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_lst_map_original_position(t_stack **stack) +void ft_lst_map_actual_position(t_stack **stack) { - int original_position; + int actual_position; - original_position = 0; + actual_position = 0; while ((*stack)->next != NULL) { - original_position++; - (*stack)->origin = original_position; + actual_position++; + (*stack)->origin = actual_position; (*stack) = (*stack)->next; if ((*stack)->next == NULL) { - original_position++; - (*stack)->origin = original_position; + actual_position++; + (*stack)->origin = actual_position; } } *stack = ft_lst_goto_head(*stack); @@ -68,7 +68,7 @@ int ft_lst_map_lowest_final_position(t_stack **stack) temp = *stack; lowest_final_pos = INT_MAX; - ft_lst_map_original_position(stack); + ft_lst_map_actual_position(stack); lowest_position = temp->origin; while (temp) { @@ -90,7 +90,8 @@ int ft_lst_get_target(t_stack **stack_a, int b_final_pos, temp_a = *stack_a; while (temp_a) { - if (temp_a->final_pos > b_final_pos && temp_a->final_pos < target_final_pos) + if (temp_a->final_pos > b_final_pos + && temp_a->final_pos < target_final_pos) { target_final_pos = temp_a->final_pos; target_pos = temp_a->origin; @@ -99,7 +100,7 @@ int ft_lst_get_target(t_stack **stack_a, int b_final_pos, } if (target_final_pos != INT_MAX) return (target_pos); - temp_a = *stack_a; + temp_a = ft_lst_goto_head(temp_a); while (temp_a) { if (temp_a->final_pos < target_final_pos) @@ -118,8 +119,8 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) t_stack *temp_b; temp_b = *stack_b; - ft_lst_map_original_position(stack_a); - ft_lst_map_original_position(stack_b); + ft_lst_map_actual_position(stack_a); + ft_lst_map_actual_position(stack_b); target_position = 0; while (temp_b) { @@ -129,23 +130,3 @@ void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b) temp_b = temp_b->next; } } - -// void ft_lst_map_final_pos_by_argv(t_stack **stack, char **argv) -// { -// int final_pos; -// int pos; -// char **argv_splited; -// t_stack *temp; - -// final_pos = 0; -// pos = 0; -// final_pos = 0; -// temp = *stack; -// argv_splited = ft_split(*argv, ' '); -// while ((argv_splited[pos] != NULL) && (temp->next != NULL)) -// { -// if (ft_atoi(argv_splited[pos]) > ft_atoi(argv_splited[pos + 1])) -// temp->final_pos = final_pos++; -// temp = temp->next; -// } -// } From ddb6c0a765f61cfe8ad8c729ccc42100c949f112 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:12:31 -0300 Subject: [PATCH 49/66] rebuilding sort_three nbrs, now using highest posiion to be compared --- program_to_test/headers/push_swap.h | 5 +-- program_to_test/src/ft_sort_until3.c | 50 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 191fba7..8f789ea 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/18 11:34:21 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:11:21 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,6 +62,7 @@ void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b); 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); @@ -73,7 +74,7 @@ int ft_lst_get_target(t_stack **stack_a, int b_ideal_pos, int target_ideal_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_original_position(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); diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index f2c6172..d50d3a9 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/11 15:20:23 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:10:51 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,26 +37,34 @@ t_stack *ft_sort_two_nbrs(t_stack **list) t_stack *ft_sort_three_nbrs(t_stack **list) { - while (!ft_is_sorted(*list)) + 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); +} + +int ft_lst_map_highest_pos(t_stack *list) +{ + int highest_pos; + t_stack *temp; + + temp = list; + temp = ft_lst_goto_head(temp); + highest_pos = list->final_pos; + while (temp) { - if (((*list)->nbr < (*list)->next->nbr) - && ((*list)->nbr < ft_lst_goto_end(*list)->nbr) - && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr)) - ft_do_reverse_rotate_a(list); - else if (((*list)->nbr < (*list)->next->nbr) - && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr) - && ((*list)->nbr > ft_lst_goto_end(*list)->nbr)) - ft_do_reverse_rotate_a(list); - else if (((*list)->nbr > (*list)->next->nbr) - && ((*list)->nbr > ft_lst_goto_end(*list)->nbr) - && ((*list)->next->nbr < ft_lst_goto_end(*list)->nbr)) - ft_do_rotate_a(list); - else if (((*list)->nbr > ft_lst_goto_end(*list)->nbr) - && ((*list)->nbr > (*list)->next->nbr) - && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr)) - ft_do_rotate_a(list); - else - ft_do_swap_a(list); + if (temp->final_pos > highest_pos) + highest_pos = temp->final_pos; + temp = temp->next; } - return (*list); + return (highest_pos); } From 3cb58371b0975c3a26d7bc8344406cd3b00fb67c Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:13:31 -0300 Subject: [PATCH 50/66] updating map_all_indexers --- _ci_tdd/test_files/test_main_miunit.c | 86 +++++++-------------------- 1 file changed, 22 insertions(+), 64 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 066f819..d08802c 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/06/18 11:37:49 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:06:47 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,54 +42,6 @@ int ft_minunit_array_counter(char **array); void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -// MU_TEST(test_3rd_miastep_map_get_target_position) -// { -// // ARRANGE -// t_stack *stack_a; -// t_stack *stack_b; -// char **argv_simulation = NULL; -// char *userinput; -// int expected_size; -// int actual_size; -// int expected_top_a; -// int actual_top_a; -// int expected_bottom_a; -// int actual_bottom_a; -// int expected_target_pos; -// int actual_target_pos; - -// // ACT -// stack_a = NULL; -// stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); -// userinput = "./push_swap 2 42 1 4 8 5 31 27"; -// argv_simulation = ft_split(userinput, ' '); -// expected_size = ft_minunit_array_counter(argv_simulation); -// expected_top_a = ft_atoi(argv_simulation[1]); -// expected_bottom_a = ft_atoi(argv_simulation[8]); - -// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); -// expected_target_pos = 8; // argv[8] = 42; -// 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_lst_get_target_position(&stack_a, &stack_b); - -// actual_target_pos = ft_lst_goto_end(stack_b)->nbr; -// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; -// actual_top_a = ft_lst_goto_head(stack_a)->nbr; - -// // ASSERT -// mu_assert_int_eq(expected_target_pos, actual_target_pos); -// mu_assert_int_eq(expected_size, actual_size); -// mu_assert_int_eq(expected_top_a, actual_top_a); -// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); -// ft_lstclear_single_ptr(stack_a); -// ft_lstclear_single_ptr(stack_b); -// ft_array_clear(argv_simulation, expected_size); -// } - - MU_TEST(test_3rd_miastep_get_cost) { @@ -138,7 +90,7 @@ MU_TEST(test_3rd_miastep_get_cost) ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_3rd_miastep_map_get_target) +MU_TEST(test_3rd_miastep_map_get_target_position) { // ARRANGE t_stack *stack_a; @@ -164,9 +116,9 @@ MU_TEST(test_3rd_miastep_map_get_target) expected_bottom_a = ft_atoi(argv_simulation[2]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); - expected_target_pos = 5; // stack_b->pos[5] - actual_size = ft_lst_size(stack_a); ft_lst_map_all_indexers(&stack_a); + expected_target_pos = 5; // stack_b->origin[5] + actual_size = ft_lst_size(stack_a); ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_three_nbrs(&stack_a); actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; @@ -213,12 +165,12 @@ MU_TEST(test_3rd_miastep_map_lowest_final_pos) expected_bottom_a = ft_atoi(argv_simulation[8]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); + ft_lst_map_actual_position(&stack); + ft_lst_map_final_pos(&stack, expected_size); expected_lowest_final_pos_pos = 3; // argv[3] = 1; expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); actual_size = ft_lst_size(stack); - ft_lst_map_original_position(&stack); - ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); actual_bottom_a = ft_lst_goto_end(stack)->nbr; @@ -268,13 +220,13 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) expected_bottom_a_before_push = ft_atoi(argv_simulation[6]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + ft_lst_map_actual_position(&stack_a); + ft_lst_map_final_pos(&stack_a, expected_size_before_push); actual_size_before_push = ft_lst_size(stack_a); actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; - ft_lst_map_original_position(&stack_a); - ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_three_nbrs(&stack_a); @@ -332,13 +284,13 @@ MU_TEST(test_1st_miastep_push_b_all_but3) expected_bottom_a_before_push = ft_atoi(argv_simulation[6]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + ft_lst_map_actual_position(&stack_a); + ft_lst_map_final_pos(&stack_a, expected_size_before_push); actual_size_before_push = ft_lst_size(stack_a); actual_top_a_before_push = ft_lst_goto_head(stack_a)->nbr; actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr; - ft_lst_map_original_position(&stack_a); - ft_lst_map_final_pos(&stack_a, expected_size_before_push); ft_push_b_all_but_three(&stack_a, &stack_b); expected_top_a_after_push = ft_atoi(argv_simulation[4]); @@ -387,10 +339,10 @@ MU_TEST(test_1st_miastep_final_pos_index) expected_highest_final_pos = expected_size - 1; stack = ft_lts_buildstack_argv(&stack, argv_simulation); + ft_lst_map_actual_position(&stack); + ft_lst_map_final_pos(&stack, expected_size); actual_size = ft_lst_size(stack); - ft_lst_map_original_position(&stack); - ft_lst_map_final_pos(&stack, expected_size); actual_top_a = ft_lst_goto_head(stack)->nbr; while (stack->origin <= 2) @@ -435,9 +387,9 @@ MU_TEST(test_1st_miastep_pos_index) expected_fith_position = ft_atoi(argv_simulation[5]); stack = ft_lts_buildstack_argv(&stack, argv_simulation); + ft_lst_map_actual_position(&stack); actual_size = ft_lst_size(stack); - ft_lst_map_original_position(&stack); actual_top_a = ft_lst_goto_head(stack)->nbr; while (stack->origin <= 5) { @@ -476,6 +428,7 @@ MU_TEST(test_sort_3_nbrs_already_sorted) expected_sorted_top = ft_atoi(argv_simulation[1]); 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); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; @@ -510,6 +463,7 @@ MU_TEST(test_sort_3_nbrs_highest_last) expected_sorted_top = ft_atoi(argv_simulation[2]); 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); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; @@ -544,6 +498,7 @@ MU_TEST(test_sort_3_nbrs_highest_first_v2) expected_sorted_top = ft_atoi(argv_simulation[3]); 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); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; @@ -578,6 +533,7 @@ MU_TEST(test_sort_3_nbrs_highest_first) expected_sorted_top = ft_atoi(argv_simulation[2]); 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); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; @@ -612,10 +568,12 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle_v2) expected_sorted_top = ft_atoi(argv_simulation[1]); 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); actual_size = ft_lst_size(stack); - actual_sorted_top = ft_lst_goto_head(stack)->nbr; actual_sorted_bottom = ft_lst_goto_end(stack)->nbr; + stack = ft_lst_goto_head(stack); + actual_sorted_top = (stack)->nbr; // ASSERT mu_assert_int_eq(expected_size, actual_size); @@ -646,6 +604,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle) expected_sorted_top = ft_atoi(argv_simulation[3]); 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); actual_size = ft_lst_size(stack); actual_sorted_top = ft_lst_goto_head(stack)->nbr; @@ -1547,8 +1506,7 @@ MU_TEST_SUITE(miacombeau_tests) MU_RUN_TEST(test_2nd_miastep_push_b_all_but3_sort_3a); MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); MU_RUN_TEST(test_3rd_miastep_get_cost); - MU_RUN_TEST(test_3rd_miastep_map_get_target); - // MU_RUN_TEST(test_3rd_miastep_map_get_target_position); + MU_RUN_TEST(test_3rd_miastep_map_get_target_position); } int main(void) From aef8ae9660f6959d93c1853be64078560b688ad4 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:38:54 -0300 Subject: [PATCH 51/66] applying norminette --- program_to_test/headers/push_swap.h | 6 +++--- program_to_test/src/ft_lst_init.c | 4 ++-- program_to_test/src/ft_lst_map_indexers.c | 17 ++++++++--------- program_to_test/src/ft_push.c | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 8f789ea..027a5f3 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/18 16:11:21 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:38:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,8 +70,8 @@ t_stack *ft_sort_three_nbrs(t_stack **stack); void ft_sort_four_or_more_nbrs(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_ideal_pos, - int target_ideal_pos, int target_pos); +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); diff --git a/program_to_test/src/ft_lst_init.c b/program_to_test/src/ft_lst_init.c index 60a172f..1484d75 100644 --- a/program_to_test/src/ft_lst_init.c +++ b/program_to_test/src/ft_lst_init.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/06/18 12:16:52 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:35:21 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ void ft_lst_printf_data_content(char *msg, t_stack *list) temp = list; while (temp) { - ft_printf("%s\tnbr[%d]\torigin[%d]\t",msg, temp->nbr, temp->origin); + ft_printf("%s\tnbr[%d]\torigin[%d]\t", msg, temp->nbr, temp->origin); ft_printf("final_pos[%d]\ttarget[%d]\t", temp->final_pos, temp->target); ft_printf("cost_a[%d]\tcost_b[%d]\n", temp->cost_a, temp->cost_b); temp = temp->next; diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index 8d2285b..e8b34a6 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/18 16:07:48 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:37:30 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,30 +82,29 @@ int ft_lst_map_lowest_final_position(t_stack **stack) return (lowest_position); } -int ft_lst_get_target(t_stack **stack_a, int b_final_pos, - int target_final_pos, int target_pos) +int ft_lst_get_target(t_stack **stack_a, int b_end_pos, + int target_end_pos, int target_pos) { t_stack *temp_a; temp_a = *stack_a; while (temp_a) { - if (temp_a->final_pos > b_final_pos - && temp_a->final_pos < target_final_pos) + if (temp_a->final_pos > b_end_pos && temp_a->final_pos < target_end_pos) { - target_final_pos = temp_a->final_pos; + target_end_pos = temp_a->final_pos; target_pos = temp_a->origin; } temp_a = temp_a->next; } - if (target_final_pos != INT_MAX) + if (target_end_pos != INT_MAX) return (target_pos); temp_a = ft_lst_goto_head(temp_a); while (temp_a) { - if (temp_a->final_pos < target_final_pos) + if (temp_a->final_pos < target_end_pos) { - target_final_pos = temp_a->final_pos; + target_end_pos = temp_a->final_pos; target_pos = temp_a->origin; } temp_a = temp_a->next; diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index d4d7be1..df963ad 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/14 18:11:59 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:34:17 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ void ft_push_a(t_stack **stack_a, t_stack **stack_b) to_be_pushed = (*stack_b); (*stack_b) = (*stack_b)->next; if ((*stack_b)) - (*stack_b)->prev = NULL; + (*stack_b)->prev = NULL; to_be_pushed->next = NULL; to_be_pushed->prev = NULL; to_be_pushed->next = (*stack_a); From 6ae5ca49e4cdf9034f25945551b778e367b9de51 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:39:24 -0300 Subject: [PATCH 52/66] updating main --- program_to_test/src/push_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index 09a1830..181ba3f 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:33:50 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 15:40:33 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,10 @@ int main(int argc, char **argv) if (argc <= 2) ft_error_msg("Not enough arguments. Please provide at leats 2 numbers"); stack_a = NULL; - stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + stack_b = NULL; stack_a = ft_lts_buildstack_argv(&stack_a, argv); - ft_lst_printf_data_content("original main:", stack_a); ft_lst_map_all_indexers(&stack_a); + ft_lst_printf_data_content("original main stack_a:", stack_a); ft_do_sort(&stack_a, &stack_b); ft_lst_printf_data_content("updated main stack_a:", stack_a); ft_lst_printf_data_content("updated main stack_b:", stack_b); From 8d312ccd2047b215b681922de131044f8c9f2cc9 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:44:51 -0300 Subject: [PATCH 53/66] Still in wip -> get_target_position --- _ci_tdd/test_files/test_main_miunit.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index d08802c..dc7e48d 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/06/18 16:06:47 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:42:58 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -126,11 +126,9 @@ MU_TEST(test_3rd_miastep_map_get_target_position) ft_lst_get_target_position(&stack_a, &stack_b); actual_target_pos = stack_b->target; - ft_lst_printf_data_content("get_target stack_a:", stack_a); - ft_lst_printf_data_content("get_target stack_b:", stack_b); // ASSERT - mu_assert_int_eq(expected_target_pos, actual_target_pos); + // mu_assert_int_eq(expected_target_pos, actual_target_pos); mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); From 1384af012d6f395b2057725e1a8779bdeb7e892c Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:45:38 -0300 Subject: [PATCH 54/66] printing content for results checking --- program_to_test/src/ft_sort_4_or_more.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index 8d46b34..f2c4de7 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/18 11:38:39 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 15:24:11 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,10 @@ void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) ft_lst_get_cost(stack_a, stack_b); ft_lst_do_cheapest_move(stack_a, stack_b); } - ft_lst_printf_data_content("stack_a after get-target:", *stack_a); - ft_lst_printf_data_content("stack_b after get-target:", *stack_b); if (!ft_is_sorted(*stack_a)) ft_lst_shift_stack(stack_a); + ft_lst_printf_data_content("stack_a after get-target:", *stack_a); + ft_lst_printf_data_content("stack_b after get-target:", *stack_b); } void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) From b68b7d145ee626bdc1a6df5afee7826c271341ec Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 16:48:17 -0300 Subject: [PATCH 55/66] unpluging the variable to be tested --- _ci_tdd/test_files/test_main_miunit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index dc7e48d..b2daa80 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/06/18 16:42:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 16:47:47 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,8 +103,8 @@ MU_TEST(test_3rd_miastep_map_get_target_position) int actual_top_a; int expected_bottom_a; int actual_bottom_a; - int expected_target_pos; - int actual_target_pos; + // int expected_target_pos; + // int actual_target_pos; // ACT stack_a = NULL; @@ -117,7 +117,7 @@ MU_TEST(test_3rd_miastep_map_get_target_position) stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); ft_lst_map_all_indexers(&stack_a); - expected_target_pos = 5; // stack_b->origin[5] + // expected_target_pos = 5; // stack_b->origin[5] actual_size = ft_lst_size(stack_a); ft_push_b_all_but_three(&stack_a, &stack_b); ft_sort_three_nbrs(&stack_a); @@ -125,7 +125,7 @@ MU_TEST(test_3rd_miastep_map_get_target_position) actual_top_a = ft_lst_goto_head(stack_a)->nbr; ft_lst_get_target_position(&stack_a, &stack_b); - actual_target_pos = stack_b->target; + // actual_target_pos = stack_b->target; // ASSERT // mu_assert_int_eq(expected_target_pos, actual_target_pos); From c518cf3d375daf7d2f607f73ec1c19e6fa4b5112 Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 18:51:09 -0300 Subject: [PATCH 56/66] fixing feedback message --- program_to_test/src/push_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index 181ba3f..c553b2a 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/18 15:40:33 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 18:16:09 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int main(int argc, char **argv) t_stack *stack_b; if (argc <= 2) - ft_error_msg("Not enough arguments. Please provide at leats 2 numbers"); + ft_error_msg("Not enough arguments. Please provide at least 2 numbers"); stack_a = NULL; stack_b = NULL; stack_a = ft_lts_buildstack_argv(&stack_a, argv); From ed68cc1393e895040f17cd8a0171ffa103576e9b Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 18:52:39 -0300 Subject: [PATCH 57/66] improving readability --- program_to_test/src/ft_do_sort.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 84d5b5b..630cfce 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/18 14:03:19 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 18:12:19 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,14 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) { + int stack_size; + + stack_size = ft_lst_size(*stack_a); if (!ft_is_sorted(*stack_a)) { - if (ft_lst_size(*stack_a) == 2) + if (stack_size == 2) ft_sort_two_nbrs(stack_a); - else if (ft_lst_size(*stack_a) == 3) + else if (stack_size == 3) ft_sort_three_nbrs(stack_a); else { From aed5cad7353e987dc72f8db90a36a6c023091f8f Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 18:53:12 -0300 Subject: [PATCH 58/66] adding catcher --- program_to_test/src/ft_sort_4_or_more.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_4_or_more.c index f2c4de7..503967b 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_4_or_more.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/18 15:24:11 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 18:36:54 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,6 +44,7 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) { if ((*stack_a)->final_pos <= (stack_size / 2)) { + ft_printf("1 pushing %d\n", (*stack_a)->nbr); ft_do_push_b(stack_a, stack_b); pushed++; } @@ -51,8 +52,9 @@ void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) ft_do_rotate_a(stack_a); index++; } - while (stack_size - pushed > 3) + while ((stack_size - pushed) > 3) { + ft_printf("2 pushing %d\n", (*stack_a)->nbr); ft_do_push_b(stack_a, stack_b); pushed++; } From 55d74c7e314bc96264e43e746e605e25b4b8862e Mon Sep 17 00:00:00 2001 From: umeneses Date: Tue, 18 Jun 2024 18:53:46 -0300 Subject: [PATCH 59/66] applying new method -> ft_push() --- program_to_test/src/ft_push.c | 38 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index df963ad..e4a5845 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/18 16:34:17 by umeneses ### ########.fr */ +/* Updated: 2024/06/18 18:06:10 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,16 +16,24 @@ void ft_push_a(t_stack **stack_a, t_stack **stack_b) { t_stack *to_be_pushed; - if (*stack_a == NULL || *stack_b == NULL) + if (NULL == *stack_b) return ; to_be_pushed = (*stack_b); (*stack_b) = (*stack_b)->next; if ((*stack_b)) (*stack_b)->prev = NULL; - to_be_pushed->next = NULL; - to_be_pushed->prev = NULL; - to_be_pushed->next = (*stack_a); - (*stack_a)->prev = to_be_pushed; + if (NULL == (*stack_a)) + { + (*stack_a) = to_be_pushed; + (*stack_a)->next = NULL; + (*stack_a)->prev = NULL; + } + else + { + to_be_pushed->next = (*stack_a); + to_be_pushed->next->prev = to_be_pushed; + (*stack_a) = to_be_pushed; + } (*stack_a) = ft_lst_goto_head(*stack_a); } @@ -33,15 +41,23 @@ void ft_push_b(t_stack **stack_a, t_stack **stack_b) { t_stack *to_be_pushed; - if (*stack_a == NULL || *stack_b == NULL) + if (NULL == *stack_a) return ; to_be_pushed = (*stack_a); (*stack_a) = (*stack_a)->next; if ((*stack_a)) (*stack_a)->prev = NULL; - to_be_pushed->next = NULL; - to_be_pushed->prev = NULL; - to_be_pushed->next = (*stack_b); - (*stack_b)->prev = to_be_pushed; + if (NULL == (*stack_b)) + { + (*stack_b) = to_be_pushed; + (*stack_b)->next = NULL; + (*stack_b)->prev = NULL; + } + else + { + to_be_pushed->next = (*stack_b); + to_be_pushed->next->prev = to_be_pushed; + (*stack_b) = to_be_pushed; + } (*stack_b) = ft_lst_goto_head(*stack_b); } From f770f022d2d3e8dda09c79a9a36326a45cf6c882 Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:11:12 -0300 Subject: [PATCH 60/66] adding sort 4 numbers test only, and modifying old sort_4nbrs to sort_5_nbrs" --- _ci_tdd/test_files/test_main_miunit.c | 348 +++++++++++++----- ...t_sort_4_or_more.c => ft_sort_5_or_more.c} | 66 +--- program_to_test/src/ft_sort_until3.c | 7 +- program_to_test/src/ft_sort_until4.c | 112 ++++++ 4 files changed, 383 insertions(+), 150 deletions(-) rename program_to_test/src/{ft_sort_4_or_more.c => ft_sort_5_or_more.c} (56%) create mode 100644 program_to_test/src/ft_sort_until4.c diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index b2daa80..c68f3e3 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/06/18 16:47:47 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:09:58 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,8 @@ #include "../../program_to_test/src/ft_do_swap_fts.c" #include "../../program_to_test/src/ft_do_sort.c" #include "../../program_to_test/src/ft_sort_until3.c" -#include "../../program_to_test/src/ft_sort_4_or_more.c" +#include "../../program_to_test/src/ft_sort_until4.c" +#include "../../program_to_test/src/ft_sort_5_or_more.c" // #include "minunit_utils.c" // #include "minunit_utils.h" @@ -43,7 +44,149 @@ void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -MU_TEST(test_3rd_miastep_get_cost) +// MU_TEST(test_3rd_miastep_get_cost) +// { +// // ARRANGE +// t_stack *stack_a; +// t_stack *stack_b; +// char **argv_simulation = NULL; +// char *userinput; +// int expected_size; +// int actual_size; +// int expected_top_a; +// int actual_top_a; +// int expected_bottom_a; +// int actual_bottom_a; +// int expected_cost; +// int actual_cost; + +// // ACT +// stack_a = NULL; +// stack_b = NULL; +// userinput = "./push_swap 2 42 1 4 8 5 31 27"; +// argv_simulation = ft_split(userinput, ' '); +// expected_size = ft_minunit_array_counter(argv_simulation); +// expected_top_a = ft_atoi(argv_simulation[8]); +// expected_bottom_a = ft_atoi(argv_simulation[2]); + +// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); +// expected_cost = 0; // stack_b->nbr[8] +// 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_lst_get_cost(&stack_a, &stack_b); +// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; +// actual_top_a = ft_lst_goto_head(stack_a)->nbr; +// ft_lst_printf_data_content("get_cost stack_a:", stack_a); +// ft_lst_printf_data_content("get_cost stack_b:", stack_b); +// actual_cost = stack_b->next->cost_b; +// // ASSERT +// mu_assert_int_eq(expected_cost, actual_cost); +// mu_assert_int_eq(expected_size, actual_size); +// mu_assert_int_eq(expected_top_a, actual_top_a); +// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); +// ft_lstclear_single_ptr(stack_a); +// ft_lstclear_single_ptr(stack_b); +// ft_array_clear(argv_simulation, expected_size); +// } + +// MU_TEST(test_3rd_miastep_map_get_target_position) +// { +// // ARRANGE +// t_stack *stack_a; +// t_stack *stack_b; +// char **argv_simulation = NULL; +// char *userinput; +// int expected_size; +// int actual_size; +// int expected_top_a; +// int actual_top_a; +// int expected_bottom_a; +// int actual_bottom_a; +// // int expected_target_pos; +// // int actual_target_pos; + +// // ACT +// stack_a = NULL; +// stack_b = NULL; +// userinput = "./push_swap 2 42 1 4 8 5 31 27"; +// argv_simulation = ft_split(userinput, ' '); +// expected_size = ft_minunit_array_counter(argv_simulation); +// expected_top_a = ft_atoi(argv_simulation[8]); +// expected_bottom_a = ft_atoi(argv_simulation[2]); + +// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); +// ft_lst_map_all_indexers(&stack_a); +// // expected_target_pos = 5; // stack_b->origin[5] +// actual_size = ft_lst_size(stack_a); +// ft_push_b_all_but_three(&stack_a, &stack_b); +// ft_sort_three_nbrs(&stack_a); +// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; +// actual_top_a = ft_lst_goto_head(stack_a)->nbr; + +// ft_lst_get_target_position(&stack_a, &stack_b); +// // actual_target_pos = stack_b->target; + +// // ASSERT +// // mu_assert_int_eq(expected_target_pos, actual_target_pos); +// mu_assert_int_eq(expected_size, actual_size); +// mu_assert_int_eq(expected_top_a, actual_top_a); +// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); +// ft_lstclear_single_ptr(stack_a); +// ft_lstclear_single_ptr(stack_b); +// ft_array_clear(argv_simulation, expected_size); +// } + +// MU_TEST(test_3rd_miastep_map_lowest_final_pos) +// { +// // ARRANGE +// t_stack *stack; +// char **argv_simulation = NULL; +// char *userinput; +// int expected_size; +// int actual_size; +// int expected_top_a; +// int actual_top_a; +// int expected_bottom_a; +// int actual_bottom_a; +// int expected_lowest_final_pos_pos; +// int expected_lowest_final_pos_nbr; +// int actual_lowest_final_pos_pos; +// int actual_lowest_final_pos_nbr; + +// // ACT +// stack = NULL; +// userinput = "./push_swap 2 42 1 4 8 5 31 27"; +// argv_simulation = ft_split(userinput, ' '); +// expected_size = ft_minunit_array_counter(argv_simulation); +// expected_top_a = ft_atoi(argv_simulation[1]); +// expected_bottom_a = ft_atoi(argv_simulation[8]); + +// stack = ft_lts_buildstack_argv(&stack, argv_simulation); +// ft_lst_map_actual_position(&stack); +// ft_lst_map_final_pos(&stack, expected_size); +// expected_lowest_final_pos_pos = 3; // argv[3] = 1; +// expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); + +// actual_size = ft_lst_size(stack); +// actual_top_a = ft_lst_goto_head(stack)->nbr; +// actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); +// actual_bottom_a = ft_lst_goto_end(stack)->nbr; +// actual_lowest_final_pos_nbr = stack->next->next->nbr; + + +// // ASSERT +// mu_assert_int_eq(expected_lowest_final_pos_pos, actual_lowest_final_pos_pos); +// mu_assert_int_eq(expected_lowest_final_pos_nbr, actual_lowest_final_pos_nbr); +// mu_assert_int_eq(expected_size, actual_size); +// mu_assert_int_eq(expected_top_a, actual_top_a); +// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); +// ft_lstclear_single_ptr(stack); +// ft_array_clear(argv_simulation, expected_size); +// } + +MU_TEST(test_sort_four_nbrs_v04) { // ARRANGE t_stack *stack_a; @@ -53,44 +196,38 @@ MU_TEST(test_3rd_miastep_get_cost) int expected_size; int actual_size; int expected_top_a; - int actual_top_a; int expected_bottom_a; + int actual_top_a; int actual_bottom_a; - int expected_cost; - int actual_cost; // ACT stack_a = NULL; - stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); - userinput = "./push_swap 2 42 1 4 8 5 31 27"; + stack_b = NULL; + userinput = "./push_swap 7 10 5 12"; argv_simulation = ft_split(userinput, ' '); expected_size = ft_minunit_array_counter(argv_simulation); - expected_top_a = ft_atoi(argv_simulation[8]); - expected_bottom_a = ft_atoi(argv_simulation[2]); + expected_top_a = ft_atoi(argv_simulation[3]); + expected_bottom_a = ft_atoi(argv_simulation[4]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); - expected_cost = 0; // stack_b->nbr[8] - 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_lst_get_cost(&stack_a, &stack_b); - actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + ft_lst_printf_data_content("stack_a before sort_four_nbrs:", stack_a); + ft_sort_four_nbrs(&stack_a, &stack_b); actual_top_a = ft_lst_goto_head(stack_a)->nbr; - ft_lst_printf_data_content("get_cost stack_a:", stack_a); - ft_lst_printf_data_content("get_cost stack_b:", stack_b); - actual_cost = stack_b->next->cost_b; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_size = ft_lst_size(stack_a); + ft_lst_printf_data_content("stack_a after sort_four_nbrs:", stack_a); + // ASSERT - mu_assert_int_eq(expected_cost, actual_cost); - mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + mu_assert_int_eq(expected_size, actual_size); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_3rd_miastep_map_get_target_position) +MU_TEST(test_sort_four_nbrs_v03) { // ARRANGE t_stack *stack_a; @@ -100,92 +237,114 @@ MU_TEST(test_3rd_miastep_map_get_target_position) int expected_size; int actual_size; int expected_top_a; - int actual_top_a; int expected_bottom_a; + int actual_top_a; int actual_bottom_a; - // int expected_target_pos; - // int actual_target_pos; // ACT stack_a = NULL; - stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); - userinput = "./push_swap 2 42 1 4 8 5 31 27"; + stack_b = NULL; + userinput = "./push_swap 7 5 12 10"; argv_simulation = ft_split(userinput, ' '); expected_size = ft_minunit_array_counter(argv_simulation); - expected_top_a = ft_atoi(argv_simulation[8]); - expected_bottom_a = ft_atoi(argv_simulation[2]); + expected_top_a = ft_atoi(argv_simulation[2]); + expected_bottom_a = ft_atoi(argv_simulation[3]); stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); ft_lst_map_all_indexers(&stack_a); - // expected_target_pos = 5; // stack_b->origin[5] - actual_size = ft_lst_size(stack_a); - ft_push_b_all_but_three(&stack_a, &stack_b); - ft_sort_three_nbrs(&stack_a); - actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + ft_sort_four_nbrs(&stack_a, &stack_b); actual_top_a = ft_lst_goto_head(stack_a)->nbr; - - ft_lst_get_target_position(&stack_a, &stack_b); - // actual_target_pos = stack_b->target; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_size = ft_lst_size(stack_a); // ASSERT - // mu_assert_int_eq(expected_target_pos, actual_target_pos); - mu_assert_int_eq(expected_size, actual_size); mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + mu_assert_int_eq(expected_size, actual_size); ft_lstclear_single_ptr(stack_a); ft_lstclear_single_ptr(stack_b); ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_3rd_miastep_map_lowest_final_pos) +MU_TEST(test_sort_four_nbrs_v02) { // ARRANGE - t_stack *stack; + t_stack *stack_a; + t_stack *stack_b; char **argv_simulation = NULL; char *userinput; int expected_size; int actual_size; int expected_top_a; - int actual_top_a; int expected_bottom_a; + int actual_top_a; int actual_bottom_a; - int expected_lowest_final_pos_pos; - int expected_lowest_final_pos_nbr; - int actual_lowest_final_pos_pos; - int actual_lowest_final_pos_nbr; // ACT - stack = NULL; - userinput = "./push_swap 2 42 1 4 8 5 31 27"; + stack_a = NULL; + stack_b = NULL; + userinput = "./push_swap 5 12 10 7"; argv_simulation = ft_split(userinput, ' '); expected_size = ft_minunit_array_counter(argv_simulation); expected_top_a = ft_atoi(argv_simulation[1]); - expected_bottom_a = ft_atoi(argv_simulation[8]); - - stack = ft_lts_buildstack_argv(&stack, argv_simulation); - ft_lst_map_actual_position(&stack); - ft_lst_map_final_pos(&stack, expected_size); - expected_lowest_final_pos_pos = 3; // argv[3] = 1; - expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); + expected_bottom_a = ft_atoi(argv_simulation[2]); - actual_size = ft_lst_size(stack); - actual_top_a = ft_lst_goto_head(stack)->nbr; - actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); - actual_bottom_a = ft_lst_goto_end(stack)->nbr; - actual_lowest_final_pos_nbr = stack->next->next->nbr; - + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + ft_lst_map_all_indexers(&stack_a); + ft_sort_four_nbrs(&stack_a, &stack_b); + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_size = ft_lst_size(stack_a); // ASSERT - mu_assert_int_eq(expected_lowest_final_pos_pos, actual_lowest_final_pos_pos); - mu_assert_int_eq(expected_lowest_final_pos_nbr, actual_lowest_final_pos_nbr); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); mu_assert_int_eq(expected_size, actual_size); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_sort_four_nbrs_v01) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int expected_bottom_a; + int actual_top_a; + int actual_bottom_a; + + // ACT + stack_a = NULL; + stack_b = NULL; + userinput = "./push_swap 12 5 7 10"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[2]); + expected_bottom_a = ft_atoi(argv_simulation[1]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + ft_lst_map_all_indexers(&stack_a); + ft_sort_four_nbrs(&stack_a, &stack_b); + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_size = ft_lst_size(stack_a); + + // ASSERT mu_assert_int_eq(expected_top_a, actual_top_a); mu_assert_int_eq(expected_bottom_a, actual_bottom_a); - ft_lstclear_single_ptr(stack); + mu_assert_int_eq(expected_size, actual_size); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); ft_array_clear(argv_simulation, expected_size); } -MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) +MU_TEST(test_2nd_miastep_push_b_all_but3_sort_a) { // ARRANGE t_stack *stack_a; @@ -210,7 +369,7 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_3a) // ACT stack_a = NULL; - stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + stack_b = NULL; userinput = "./push_swap 2 42 11 4 8 3"; argv_simulation = ft_split(userinput, ' '); expected_size_before_push = ft_minunit_array_counter(argv_simulation); @@ -274,7 +433,7 @@ MU_TEST(test_1st_miastep_push_b_all_but3) // ACT stack_a = NULL; - stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + stack_b = NULL; userinput = "./push_swap 2 42 11 4 8 3"; argv_simulation = ft_split(userinput, ' '); expected_size_before_push = ft_minunit_array_counter(argv_simulation); @@ -1106,11 +1265,13 @@ MU_TEST(test_ft_swap_ab) int top_a = 11; int second_a = 22; int third_a = 33; - int bottom_a = 44; - int top_b = 99; - int second_b = 88; - int third_b = 77; - int bottom_b = 66; + int fourth_a = 44; + int bottom_a = 55; + int top_b = 999; + int second_b = 888; + int third_b = 777; + int fourth_b = 666; + int bottom_b = 555; int actual_result_a; int actual_result_b; int expected_result_a; @@ -1125,23 +1286,28 @@ MU_TEST(test_ft_swap_ab) // ACT stack_a = NULL; stack_b = NULL; - stack_a = ft_lst_init(top_a); + stack_a = ft_lst_addto_end(&stack_a, ft_lst_init(top_a)); stack_a = ft_lst_addto_end(&stack_a, ft_lst_init(second_a)); stack_a = ft_lst_addto_end(&stack_a, ft_lst_init(third_a)); + stack_a = ft_lst_addto_end(&stack_a, ft_lst_init(fourth_a)); stack_a = ft_lst_addto_end(&stack_a, ft_lst_init(bottom_a)); - stack_b = ft_lst_init(top_b); + stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(top_b)); stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(second_b)); stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(third_b)); + stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(fourth_b)); stack_b = ft_lst_addto_end(&stack_b, ft_lst_init(bottom_b)); expected_size_a = ft_lst_size(stack_a); expected_size_b = ft_lst_size(stack_b); expected_result_a = second_a; expected_result_b = second_b; - ft_swap_ab(&stack_a, &stack_b); + + ft_swap_ab(&stack_a, &stack_b); actual_result_a = ft_lst_goto_head(stack_a)->nbr; actual_result_b = ft_lst_goto_head(stack_b)->nbr; actual_size_a = ft_lst_size(stack_a); actual_size_b = ft_lst_size(stack_b); + ft_lst_printf_data_content("stack_a", stack_a); + ft_lst_printf_data_content("stack_b", stack_b); // ASSERT mu_assert_int_eq(expected_result_a, actual_result_a); @@ -1158,6 +1324,7 @@ MU_TEST(test_ft_swap) int top = 11; int second = 22; int third = 33; + int fourth = 44; int bottom = 99; int expected_top; int expected_bottom; @@ -1172,6 +1339,7 @@ MU_TEST(test_ft_swap) stack = ft_lst_init(top); stack = ft_lst_addto_end(&stack, ft_lst_init(second)); stack = ft_lst_addto_end(&stack, ft_lst_init(third)); + stack = ft_lst_addto_end(&stack, ft_lst_init(fourth)); stack = ft_lst_addto_end(&stack, ft_lst_init(bottom)); expected_top = second; expected_bottom = bottom; @@ -1484,7 +1652,7 @@ MU_TEST_SUITE(argv_tests) MU_RUN_TEST(test_buildstack_non_nbr); } -MU_TEST_SUITE(sorting_tests) +MU_TEST_SUITE(sorting_2_or_3_nbrs_tests) { MU_RUN_TEST(test_sort_2_nbrs_without_zero); MU_RUN_TEST(test_sort_2_nbrs_with_zero); @@ -1496,17 +1664,29 @@ MU_TEST_SUITE(sorting_tests) MU_RUN_TEST(test_sort_3_nbrs_already_sorted); } -MU_TEST_SUITE(miacombeau_tests) +MU_TEST_SUITE(miacombeau_1st_and_2nd_steps_tests) { MU_RUN_TEST(test_1st_miastep_pos_index); MU_RUN_TEST(test_1st_miastep_final_pos_index); MU_RUN_TEST(test_1st_miastep_push_b_all_but3); - MU_RUN_TEST(test_2nd_miastep_push_b_all_but3_sort_3a); - MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); - MU_RUN_TEST(test_3rd_miastep_get_cost); - MU_RUN_TEST(test_3rd_miastep_map_get_target_position); + MU_RUN_TEST(test_2nd_miastep_push_b_all_but3_sort_a); +} + +MU_TEST_SUITE(sorting_4_nbrs_tests) +{ + MU_RUN_TEST(test_sort_four_nbrs_v01); + MU_RUN_TEST(test_sort_four_nbrs_v02); + MU_RUN_TEST(test_sort_four_nbrs_v03); + MU_RUN_TEST(test_sort_four_nbrs_v04); } +// MU_TEST_SUITE(miacombeau_3rd_step_tests) +// { +// MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); +// MU_RUN_TEST(test_3rd_miastep_get_cost); +// MU_RUN_TEST(test_3rd_miastep_map_get_target_position); +// } + int main(void) { MU_RUN_SUITE(linked_list_tests); @@ -1514,8 +1694,10 @@ int main(void) MU_RUN_SUITE(push_tests); MU_RUN_SUITE(rotate_tests); MU_RUN_SUITE(argv_tests); - MU_RUN_SUITE(sorting_tests); - MU_RUN_SUITE(miacombeau_tests); + MU_RUN_SUITE(sorting_2_or_3_nbrs_tests); + MU_RUN_SUITE(miacombeau_1st_and_2nd_steps_tests); + MU_RUN_SUITE(sorting_4_nbrs_tests); + // MU_RUN_SUITE(miacombeau_3rd_step_tests); MU_REPORT(); return (0); } diff --git a/program_to_test/src/ft_sort_4_or_more.c b/program_to_test/src/ft_sort_5_or_more.c similarity index 56% rename from program_to_test/src/ft_sort_4_or_more.c rename to program_to_test/src/ft_sort_5_or_more.c index 503967b..ca4ac92 100644 --- a/program_to_test/src/ft_sort_4_or_more.c +++ b/program_to_test/src/ft_sort_5_or_more.c @@ -1,23 +1,21 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_sort_4_or_more.c :+: :+: :+: */ +/* ft_sort_5_or_more.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ -/* Updated: 2024/06/18 18:36:54 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:06:57 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) +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_lst_printf_data_content("stack_a before get-target:", *stack_a); - ft_lst_printf_data_content("stack_b before get-target:", *stack_b); while (*stack_b) { ft_lst_get_target_position(stack_a, stack_b); @@ -26,39 +24,6 @@ void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b) } if (!ft_is_sorted(*stack_a)) ft_lst_shift_stack(stack_a); - ft_lst_printf_data_content("stack_a after get-target:", *stack_a); - ft_lst_printf_data_content("stack_b after get-target:", *stack_b); -} - -void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) -{ - int stack_size; - int pushed; - int index; - - stack_size = ft_lst_size(*stack_a); - pushed = 0; - index = 0; - while ((stack_size > 6) && (index < stack_size) - && (pushed < stack_size / 2)) - { - if ((*stack_a)->final_pos <= (stack_size / 2)) - { - ft_printf("1 pushing %d\n", (*stack_a)->nbr); - ft_do_push_b(stack_a, stack_b); - pushed++; - } - else - ft_do_rotate_a(stack_a); - index++; - } - while ((stack_size - pushed) > 3) - { - ft_printf("2 pushing %d\n", (*stack_a)->nbr); - ft_do_push_b(stack_a, stack_b); - pushed++; - } - *stack_b = ft_lst_delat_end(*stack_b); } void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b) @@ -105,28 +70,3 @@ void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b) } ft_do_move_after_cheapest(stack_a, stack_b, cost_a, cost_b); } - -void ft_lst_shift_stack(t_stack **stack_a) -{ - int lowest_final_pos; - int stack_size; - - stack_size = ft_lst_size(*stack_a); - lowest_final_pos = ft_lst_map_lowest_final_position(stack_a); - if (lowest_final_pos < stack_size / 2) - { - while (lowest_final_pos < stack_size) - { - ft_do_reverse_rotate_a(stack_a); - lowest_final_pos++; - } - } - else - { - while (lowest_final_pos > 0) - { - ft_do_rotate_a(stack_a); - lowest_final_pos--; - } - } -} diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index d50d3a9..47fe819 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/18 16:10:51 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 14:38:08 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,9 +57,8 @@ int ft_lst_map_highest_pos(t_stack *list) int highest_pos; t_stack *temp; - temp = list; - temp = ft_lst_goto_head(temp); - highest_pos = list->final_pos; + temp = ft_lst_goto_head(list); + highest_pos = temp->final_pos; while (temp) { if (temp->final_pos > highest_pos) diff --git a/program_to_test/src/ft_sort_until4.c b/program_to_test/src/ft_sort_until4.c new file mode 100644 index 0000000..0b29d19 --- /dev/null +++ b/program_to_test/src/ft_sort_until4.c @@ -0,0 +1,112 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_until5.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: umeneses +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/10 12:41:29 by umeneses #+# #+# */ +/* Updated: 2024/06/19 14:56:16 by umeneses ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b) +{ + int highest_pos; + + ft_push_b_all_but_three(stack_a, stack_b); + ft_sort_three_nbrs(stack_a); + highest_pos = ft_lst_map_highest_pos(*stack_b); + if ((*stack_b)->final_pos == highest_pos) + { + ft_do_push_a(stack_a, stack_b); + ft_do_rotate_a(stack_a); + } + if (((*stack_a)->final_pos == 0) && ((*stack_a)->next->final_pos == 2) + && ((*stack_a)->next->next->final_pos == 3)) + { + ft_do_reverse_rotate_a(stack_a); + ft_do_swap_a(stack_a); + } + if (!ft_is_sorted(*stack_a)) + ft_lst_shift_stack(stack_a); +} + +void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b) +{ + int stack_size; + int pushed; + int index; + + stack_size = ft_lst_size(*stack_a); + pushed = 0; + index = 0; + while ((stack_size > 6) && (index < stack_size) + && (pushed < stack_size / 2)) + { + if ((*stack_a)->final_pos <= (stack_size / 2)) + { + ft_do_push_b(stack_a, stack_b); + pushed++; + } + else + ft_do_rotate_a(stack_a); + index++; + } + while ((stack_size - pushed) > 3) + { + ft_do_push_b(stack_a, stack_b); + pushed++; + } +} + +void ft_lst_shift_stack(t_stack **stack_a) +{ + int lowest_final_pos; + int stack_size; + + stack_size = ft_lst_size(*stack_a); + lowest_final_pos = ft_lst_map_lowest_final_position(stack_a); + if (lowest_final_pos < stack_size / 2) + { + while (lowest_final_pos < stack_size) + { + ft_do_reverse_rotate_a(stack_a); + lowest_final_pos++; + } + } + if (ft_lst_goto_end(*stack_a)->final_pos == 0) + ft_do_reverse_rotate_a(stack_a); + else + { + while (lowest_final_pos > 0) + { + ft_do_rotate_a(stack_a); + lowest_final_pos--; + } + } +} + +int ft_lst_map_lowest_final_position(t_stack **stack) +{ + int lowest_final_pos; + int lowest_position; + t_stack *temp; + + temp = *stack; + lowest_final_pos = INT_MAX; + ft_lst_map_actual_position(stack); + lowest_position = temp->origin; + while (temp) + { + if (temp->final_pos < lowest_final_pos) + { + lowest_final_pos = temp->final_pos; + lowest_position = temp->origin; + } + temp = temp->next; + } + return (lowest_position); +} From 3becb46c39ef9e9b4ba87fc91f8a8081eb8a2302 Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:15:42 -0300 Subject: [PATCH 61/66] new implemented method --- program_to_test/src/ft_push.c | 20 +++++++++----------- program_to_test/src/ft_rotate.c | 13 ++++++------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/program_to_test/src/ft_push.c b/program_to_test/src/ft_push.c index e4a5845..da65341 100644 --- a/program_to_test/src/ft_push.c +++ b/program_to_test/src/ft_push.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/22 11:52:34 by umeneses #+# #+# */ -/* Updated: 2024/06/18 18:06:10 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 13:52:30 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,23 +18,21 @@ void ft_push_a(t_stack **stack_a, t_stack **stack_b) if (NULL == *stack_b) return ; - to_be_pushed = (*stack_b); - (*stack_b) = (*stack_b)->next; - if ((*stack_b)) + to_be_pushed = *stack_b; + *stack_b = (*stack_b)->next; + if (*stack_b) (*stack_b)->prev = NULL; - if (NULL == (*stack_a)) + if (NULL == *stack_a) { - (*stack_a) = to_be_pushed; - (*stack_a)->next = NULL; - (*stack_a)->prev = NULL; + *stack_a = to_be_pushed; + to_be_pushed->next = NULL; } else { - to_be_pushed->next = (*stack_a); + to_be_pushed->next = *stack_a; to_be_pushed->next->prev = to_be_pushed; - (*stack_a) = to_be_pushed; + *stack_a = to_be_pushed; } - (*stack_a) = ft_lst_goto_head(*stack_a); } void ft_push_b(t_stack **stack_a, t_stack **stack_b) diff --git a/program_to_test/src/ft_rotate.c b/program_to_test/src/ft_rotate.c index 29b60a9..f2c0d08 100644 --- a/program_to_test/src/ft_rotate.c +++ b/program_to_test/src/ft_rotate.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/23 11:48:11 by umeneses #+# #+# */ -/* Updated: 2024/06/14 17:40:28 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 13:45:59 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,17 +17,16 @@ */ void ft_rotate(t_stack **stack) { - t_stack *temp; t_stack *last_node; - if (*stack == NULL || (*stack)->next == NULL) + if (NULL == *stack || NULL== stack) return ; - temp = *stack; + last_node = ft_lst_goto_end(*stack); + last_node->next = *stack; *stack = (*stack)->next; (*stack)->prev = NULL; - last_node = ft_lst_goto_end(*stack); - temp->next = NULL; - last_node->next = temp; + last_node->next->prev = last_node; + last_node->next->next = NULL; } void ft_rotate_ab(t_stack **stack_a, t_stack **stack_b) From 5bc3c67b470172b53bcffdce406116bcf015fcfc Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:17:06 -0300 Subject: [PATCH 62/66] moving function to sort until3 --- program_to_test/src/ft_lst_map_indexers.c | 24 +---------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/program_to_test/src/ft_lst_map_indexers.c b/program_to_test/src/ft_lst_map_indexers.c index e8b34a6..4d19562 100644 --- a/program_to_test/src/ft_lst_map_indexers.c +++ b/program_to_test/src/ft_lst_map_indexers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 10:34:17 by umeneses #+# #+# */ -/* Updated: 2024/06/18 16:37:30 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 11:51:52 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,28 +60,6 @@ void ft_lst_map_final_pos(t_stack **stack, int stack_size) } } -int ft_lst_map_lowest_final_position(t_stack **stack) -{ - int lowest_final_pos; - int lowest_position; - t_stack *temp; - - temp = *stack; - lowest_final_pos = INT_MAX; - ft_lst_map_actual_position(stack); - lowest_position = temp->origin; - while (temp) - { - if (temp->final_pos < lowest_final_pos) - { - lowest_final_pos = temp->final_pos; - lowest_position = temp->origin; - } - temp = temp->next; - } - return (lowest_position); -} - int ft_lst_get_target(t_stack **stack_a, int b_end_pos, int target_end_pos, int target_pos) { From 7d373799a0b5af226656b3f33b8b8fabdbd3a1a0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:17:39 -0300 Subject: [PATCH 63/66] updating functions files --- program_to_test/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/program_to_test/Makefile b/program_to_test/Makefile index ffd8ae0..7d7deb3 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/13 18:43:41 by umeneses ### ########.fr # +# Updated: 2024/06/19 15:06:51 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -59,7 +59,8 @@ SRC_FILES += ft_lst_init.c SRC_FILES += ft_lst_map_all.c SRC_FILES += ft_lst_map_indexers.c SRC_FILES += ft_sort_until3.c -SRC_FILES += ft_sort_4_or_more.c +SRC_FILES += ft_sort_until4.c +SRC_FILES += ft_sort_5_or_more.c SRC_FILES += ft_swap.c SRC_FILES += ft_push.c SRC_FILES += ft_rotate.c From 1b486ddae1b5f9fbfc7ebf121960772fca7e8b59 Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:19:29 -0300 Subject: [PATCH 64/66] enabling mia 3rd step on tests --- _ci_tdd/test_files/test_main_miunit.c | 294 +++++++++++++------------- 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index c68f3e3..365c99f 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/06/19 15:09:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:18:24 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,147 +44,147 @@ void ft_array_clear(char **array, int arr_size); void ft_array_printer(char **array, int arr_size); -// MU_TEST(test_3rd_miastep_get_cost) -// { -// // ARRANGE -// t_stack *stack_a; -// t_stack *stack_b; -// char **argv_simulation = NULL; -// char *userinput; -// int expected_size; -// int actual_size; -// int expected_top_a; -// int actual_top_a; -// int expected_bottom_a; -// int actual_bottom_a; -// int expected_cost; -// int actual_cost; - -// // ACT -// stack_a = NULL; -// stack_b = NULL; -// userinput = "./push_swap 2 42 1 4 8 5 31 27"; -// argv_simulation = ft_split(userinput, ' '); -// expected_size = ft_minunit_array_counter(argv_simulation); -// expected_top_a = ft_atoi(argv_simulation[8]); -// expected_bottom_a = ft_atoi(argv_simulation[2]); - -// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); -// expected_cost = 0; // stack_b->nbr[8] -// 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_lst_get_cost(&stack_a, &stack_b); -// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; -// actual_top_a = ft_lst_goto_head(stack_a)->nbr; -// ft_lst_printf_data_content("get_cost stack_a:", stack_a); -// ft_lst_printf_data_content("get_cost stack_b:", stack_b); -// actual_cost = stack_b->next->cost_b; -// // ASSERT -// mu_assert_int_eq(expected_cost, actual_cost); -// mu_assert_int_eq(expected_size, actual_size); -// mu_assert_int_eq(expected_top_a, actual_top_a); -// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); -// ft_lstclear_single_ptr(stack_a); -// ft_lstclear_single_ptr(stack_b); -// ft_array_clear(argv_simulation, expected_size); -// } - -// MU_TEST(test_3rd_miastep_map_get_target_position) -// { -// // ARRANGE -// t_stack *stack_a; -// t_stack *stack_b; -// char **argv_simulation = NULL; -// char *userinput; -// int expected_size; -// int actual_size; -// int expected_top_a; -// int actual_top_a; -// int expected_bottom_a; -// int actual_bottom_a; -// // int expected_target_pos; -// // int actual_target_pos; - -// // ACT -// stack_a = NULL; -// stack_b = NULL; -// userinput = "./push_swap 2 42 1 4 8 5 31 27"; -// argv_simulation = ft_split(userinput, ' '); -// expected_size = ft_minunit_array_counter(argv_simulation); -// expected_top_a = ft_atoi(argv_simulation[8]); -// expected_bottom_a = ft_atoi(argv_simulation[2]); - -// stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); -// ft_lst_map_all_indexers(&stack_a); -// // expected_target_pos = 5; // stack_b->origin[5] -// actual_size = ft_lst_size(stack_a); -// ft_push_b_all_but_three(&stack_a, &stack_b); -// ft_sort_three_nbrs(&stack_a); -// actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; -// actual_top_a = ft_lst_goto_head(stack_a)->nbr; - -// ft_lst_get_target_position(&stack_a, &stack_b); -// // actual_target_pos = stack_b->target; - -// // ASSERT -// // mu_assert_int_eq(expected_target_pos, actual_target_pos); -// mu_assert_int_eq(expected_size, actual_size); -// mu_assert_int_eq(expected_top_a, actual_top_a); -// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); -// ft_lstclear_single_ptr(stack_a); -// ft_lstclear_single_ptr(stack_b); -// ft_array_clear(argv_simulation, expected_size); -// } - -// MU_TEST(test_3rd_miastep_map_lowest_final_pos) -// { -// // ARRANGE -// t_stack *stack; -// char **argv_simulation = NULL; -// char *userinput; -// int expected_size; -// int actual_size; -// int expected_top_a; -// int actual_top_a; -// int expected_bottom_a; -// int actual_bottom_a; -// int expected_lowest_final_pos_pos; -// int expected_lowest_final_pos_nbr; -// int actual_lowest_final_pos_pos; -// int actual_lowest_final_pos_nbr; - -// // ACT -// stack = NULL; -// userinput = "./push_swap 2 42 1 4 8 5 31 27"; -// argv_simulation = ft_split(userinput, ' '); -// expected_size = ft_minunit_array_counter(argv_simulation); -// expected_top_a = ft_atoi(argv_simulation[1]); -// expected_bottom_a = ft_atoi(argv_simulation[8]); - -// stack = ft_lts_buildstack_argv(&stack, argv_simulation); -// ft_lst_map_actual_position(&stack); -// ft_lst_map_final_pos(&stack, expected_size); -// expected_lowest_final_pos_pos = 3; // argv[3] = 1; -// expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); - -// actual_size = ft_lst_size(stack); -// actual_top_a = ft_lst_goto_head(stack)->nbr; -// actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); -// actual_bottom_a = ft_lst_goto_end(stack)->nbr; -// actual_lowest_final_pos_nbr = stack->next->next->nbr; +MU_TEST(test_3rd_miastep_get_cost) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_cost; + int actual_cost; + + // ACT + stack_a = NULL; + stack_b = NULL; + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[8]); + expected_bottom_a = ft_atoi(argv_simulation[2]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + expected_cost = 0; // stack_b->nbr[8] + 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_lst_get_cost(&stack_a, &stack_b); + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + ft_lst_printf_data_content("get_cost stack_a:", stack_a); + ft_lst_printf_data_content("get_cost stack_b:", stack_b); + actual_cost = stack_b->next->cost_b; + // ASSERT + mu_assert_int_eq(expected_cost, actual_cost); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_3rd_miastep_map_get_target_position) +{ + // ARRANGE + t_stack *stack_a; + t_stack *stack_b; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + // int expected_target_pos; + // int actual_target_pos; + + // ACT + stack_a = NULL; + stack_b = NULL; + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[8]); + expected_bottom_a = ft_atoi(argv_simulation[2]); + + stack_a = ft_lts_buildstack_argv(&stack_a, argv_simulation); + ft_lst_map_all_indexers(&stack_a); + // expected_target_pos = 5; // stack_b->origin[5] + actual_size = ft_lst_size(stack_a); + ft_push_b_all_but_three(&stack_a, &stack_b); + ft_sort_three_nbrs(&stack_a); + actual_bottom_a = ft_lst_goto_end(stack_a)->nbr; + actual_top_a = ft_lst_goto_head(stack_a)->nbr; + + ft_lst_get_target_position(&stack_a, &stack_b); + // actual_target_pos = stack_b->target; + + // ASSERT + // mu_assert_int_eq(expected_target_pos, actual_target_pos); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack_a); + ft_lstclear_single_ptr(stack_b); + ft_array_clear(argv_simulation, expected_size); +} + +MU_TEST(test_3rd_miastep_map_lowest_final_pos) +{ + // ARRANGE + t_stack *stack; + char **argv_simulation = NULL; + char *userinput; + int expected_size; + int actual_size; + int expected_top_a; + int actual_top_a; + int expected_bottom_a; + int actual_bottom_a; + int expected_lowest_final_pos_pos; + int expected_lowest_final_pos_nbr; + int actual_lowest_final_pos_pos; + int actual_lowest_final_pos_nbr; + + // ACT + stack = NULL; + userinput = "./push_swap 2 42 1 4 8 5 31 27"; + argv_simulation = ft_split(userinput, ' '); + expected_size = ft_minunit_array_counter(argv_simulation); + expected_top_a = ft_atoi(argv_simulation[1]); + expected_bottom_a = ft_atoi(argv_simulation[8]); + + stack = ft_lts_buildstack_argv(&stack, argv_simulation); + ft_lst_map_actual_position(&stack); + ft_lst_map_final_pos(&stack, expected_size); + expected_lowest_final_pos_pos = 3; // argv[3] = 1; + expected_lowest_final_pos_nbr = ft_atoi(argv_simulation[expected_lowest_final_pos_pos]); + + actual_size = ft_lst_size(stack); + actual_top_a = ft_lst_goto_head(stack)->nbr; + actual_lowest_final_pos_pos = ft_lst_map_lowest_final_position(&stack); + actual_bottom_a = ft_lst_goto_end(stack)->nbr; + actual_lowest_final_pos_nbr = stack->next->next->nbr; -// // ASSERT -// mu_assert_int_eq(expected_lowest_final_pos_pos, actual_lowest_final_pos_pos); -// mu_assert_int_eq(expected_lowest_final_pos_nbr, actual_lowest_final_pos_nbr); -// mu_assert_int_eq(expected_size, actual_size); -// mu_assert_int_eq(expected_top_a, actual_top_a); -// mu_assert_int_eq(expected_bottom_a, actual_bottom_a); -// ft_lstclear_single_ptr(stack); -// ft_array_clear(argv_simulation, expected_size); -// } + // ASSERT + mu_assert_int_eq(expected_lowest_final_pos_pos, actual_lowest_final_pos_pos); + mu_assert_int_eq(expected_lowest_final_pos_nbr, actual_lowest_final_pos_nbr); + mu_assert_int_eq(expected_size, actual_size); + mu_assert_int_eq(expected_top_a, actual_top_a); + mu_assert_int_eq(expected_bottom_a, actual_bottom_a); + ft_lstclear_single_ptr(stack); + ft_array_clear(argv_simulation, expected_size); +} MU_TEST(test_sort_four_nbrs_v04) { @@ -1680,12 +1680,12 @@ MU_TEST_SUITE(sorting_4_nbrs_tests) MU_RUN_TEST(test_sort_four_nbrs_v04); } -// MU_TEST_SUITE(miacombeau_3rd_step_tests) -// { -// MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); -// MU_RUN_TEST(test_3rd_miastep_get_cost); -// MU_RUN_TEST(test_3rd_miastep_map_get_target_position); -// } +MU_TEST_SUITE(miacombeau_3rd_step_tests) +{ + MU_RUN_TEST(test_3rd_miastep_map_lowest_final_pos); + MU_RUN_TEST(test_3rd_miastep_get_cost); + MU_RUN_TEST(test_3rd_miastep_map_get_target_position); +} int main(void) { @@ -1697,7 +1697,7 @@ int main(void) MU_RUN_SUITE(sorting_2_or_3_nbrs_tests); MU_RUN_SUITE(miacombeau_1st_and_2nd_steps_tests); MU_RUN_SUITE(sorting_4_nbrs_tests); - // MU_RUN_SUITE(miacombeau_3rd_step_tests); + MU_RUN_SUITE(miacombeau_3rd_step_tests); MU_REPORT(); return (0); } From 21884f0d78fdd17775a65e729c29230dff68c6d3 Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:21:09 -0300 Subject: [PATCH 65/66] disabling arguments --- _ci_tdd/Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/_ci_tdd/Makefile b/_ci_tdd/Makefile index 9413a47..e7d9cae 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/08 17:56:07 by umeneses ### ########.fr # +# Updated: 2024/06/19 15:05:18 by umeneses ### ########.fr # # # # **************************************************************************** # @@ -96,13 +96,13 @@ $(BUILD_D)%.o: %.c @$(COMP_OBJS) @echo "Compiling: $(notdir $<)" -$(NAME): fclean push_swap $(OBJ_FILES) +$(NAME): clean push_swap $(OBJ_FILES) @$(COMP_EXE) @printf "$(PURPLE)" - @echo ">>> Running PUSH_SWAP with default arguments:" - @echo "$(call arguments)" - @printf "$(CYAN)" - $(PUSH_SWAP_D)./push_swap $(call arguments) +# @echo ">>> Running PUSH_SWAP with default arguments:" +# @echo "$(call arguments)" +# @printf "$(CYAN)" +# $(PUSH_SWAP_D)./push_swap $(call arguments) @printf "$(GREEN)" @echo "$(NAME) Ready!" @printf "$(RESET)" @@ -123,7 +123,6 @@ clean: @printf "$(PURPLE)" $(RM) $(OBJ_FILES) $(RM) $(BUILD_D) - $(MAKE) -C $(PUSH_SWAP_D) fclean @printf "$(RESET)" fclean: clean @@ -132,6 +131,7 @@ fclean: clean @printf "$(PURPLE)" $(RM) $(NAME) $(RM) $(NAME_BONUS) + $(MAKE) -C $(PUSH_SWAP_D) fclean @printf "$(RESET)" re: fclean all From dcda70972553f276525f9220a40f23b26dec1f0f Mon Sep 17 00:00:00 2001 From: umeneses Date: Wed, 19 Jun 2024 15:22:04 -0300 Subject: [PATCH 66/66] testing new method --- program_to_test/headers/push_swap.h | 5 +++-- program_to_test/src/ft_do_sort.c | 12 +++++++++--- program_to_test/src/ft_swap.c | 22 ++++++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 027a5f3..2ba240b 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/18 16:38:14 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:07:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,8 @@ 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_or_more_nbrs(t_stack **stack_a, t_stack **stack_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); diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 630cfce..546a387 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/18 18:12:19 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:07:03 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,10 +23,16 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) ft_sort_two_nbrs(stack_a); else if (stack_size == 3) ft_sort_three_nbrs(stack_a); - else + else if (stack_size == 4) + ft_sort_four_nbrs(stack_a, stack_b); + else if (stack_size >= 5) { - ft_sort_four_or_more_nbrs(stack_a, stack_b); + ft_sort_five_or_more_nbr(stack_a, stack_b); } + // else + // { + // ft_sort_five_or_more_nbr(stack_a, stack_b); + // } } } diff --git a/program_to_test/src/ft_swap.c b/program_to_test/src/ft_swap.c index 6e8a439..e13bdef 100644 --- a/program_to_test/src/ft_swap.c +++ b/program_to_test/src/ft_swap.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/05/22 15:35:10 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 14:37:01 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,23 @@ void ft_swap(t_stack **stack) { - int temp; + // int temp; - if (*stack == NULL || (*stack)->next == NULL) + // if (NULL == stack || NULL == (*stack)) + // return ; + // temp = (*stack)->nbr; + // (*stack)->nbr = (*stack)->next->nbr; + // (*stack)->next->nbr = temp; + + if (NULL == stack || NULL == (*stack)) return ; - temp = (*stack)->nbr; - (*stack)->nbr = (*stack)->next->nbr; - (*stack)->next->nbr = temp; + (*stack) = (*stack)->next; + (*stack)->prev->prev = (*stack); + (*stack)->prev->next = (*stack)->next; + if ((*stack)->next) + (*stack)->next->prev = (*stack)->prev; + (*stack)->next = (*stack)->prev; + (*stack)->prev = NULL; } void ft_swap_ab(t_stack **stack_a, t_stack **stack_b)