Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying 3rd mia step #7

Merged
merged 16 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 51 additions & 108 deletions _ci_tdd/test_files/test_main_miunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */
/* Updated: 2024/06/14 17:17:51 by umeneses ### ########.fr */
/* Updated: 2024/06/18 16:47:47 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -125,15 +77,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 pos[%d] target [%d] has cost = %d\n", temp->nbr, temp->pos, 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);
Expand All @@ -145,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;
Expand All @@ -158,8 +103,8 @@ MU_TEST(test_3rd_miastep_map_get_target)
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;
Expand All @@ -171,27 +116,19 @@ 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;
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;
}

// actual_target_pos = stack_b->target;

// 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);
Expand All @@ -200,7 +137,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;
Expand All @@ -212,10 +149,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;
Expand All @@ -226,21 +163,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]);
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_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_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);
Expand Down Expand Up @@ -281,13 +218,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_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_three_nbrs(&stack_a);

Expand Down Expand Up @@ -345,13 +282,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_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]);
Expand All @@ -375,7 +312,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;
Expand All @@ -387,8 +324,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;
Expand All @@ -397,25 +334,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);
ft_lst_map_actual_position(&stack);
ft_lst_map_final_pos(&stack, expected_size);

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;

while (stack->pos <= 2)
while (stack->origin <= 2)
{
stack = stack->next;
if (stack->pos == 2)
actual_highest_weight = stack->weight;
if (stack->origin == 2)
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);
Expand Down Expand Up @@ -448,14 +385,14 @@ 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_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;
Expand Down Expand Up @@ -489,6 +426,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;
Expand Down Expand Up @@ -523,6 +461,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;
Expand Down Expand Up @@ -557,6 +496,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;
Expand Down Expand Up @@ -591,6 +531,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;
Expand Down Expand Up @@ -625,10 +566,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);
Expand Down Expand Up @@ -659,6 +602,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;
Expand Down Expand Up @@ -1555,13 +1499,12 @@ 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);
MU_RUN_TEST(test_3rd_miastep_map_get_target_position);
}

int main(void)
Expand Down
Loading