diff --git a/_ci_tdd/test_files/test_main_miunit.c b/_ci_tdd/test_files/test_main_miunit.c index 9dd4159..3f8e17d 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/05/20 12:53:01 by umeneses ### ########.fr */ +/* Updated: 2024/05/20 13:10:16 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,49 @@ #include "push_swap.h" #include "../../program_to_test/src/push_functions.c" +MU_TEST(test_ft_swap_ab) +{ + // ARRNAGE + int top_a = 5; + int middle_a = 21; + int bottom_a = 11; + int top_b = 99; + int middle_b = 88; + int bottom_b = 77; + int actual_result_a; + int actual_result_b; + int expected_result_a; + int expected_result_b; + t_stack *stack_a; + t_stack *stack_b; + + stack_a = (t_stack *)ft_calloc(1, sizeof(t_stack)); + stack_b = (t_stack *)ft_calloc(1, sizeof(t_stack)); + stack_a->next = NULL; + stack_b->next = NULL; + stack_a->prev = NULL; + stack_b->prev = NULL; + // stack_a->nbr = top_a; + // stack_b->nbr = top_b; + expected_result_a = bottom_a; + expected_result_b = bottom_b; + + // ACT + stack_a = ft_lstend_int(stack_a, top_a); + stack_a = ft_lstend_int(stack_a, middle_a); + stack_a = ft_lstend_int(stack_a, bottom_a); + stack_b = ft_lstend_int(stack_b, top_b); + stack_b = ft_lstend_int(stack_b, middle_b); + stack_b = ft_lstend_int(stack_b, bottom_b); + ft_swap_ab(&stack_a, &stack_b); + actual_result_a = stack_a->nbr; + actual_result_b = stack_b->nbr; + + // ASSERT + mu_assert_int_eq(expected_result_a, actual_result_a); + mu_assert_int_eq(expected_result_b, actual_result_b); +} + MU_TEST(test_ft_swap) { // ARRANGE @@ -27,7 +70,7 @@ MU_TEST(test_ft_swap) stack = (t_stack *)ft_calloc(1, sizeof(t_stack)); stack->next = NULL; stack->prev = NULL; - stack->nbr = top; + // stack->nbr = top; expected_result = bottom; // ACT @@ -72,6 +115,7 @@ MU_TEST_SUITE(first_tests) MU_RUN_TEST(test_pushadd_5plus4); MU_RUN_TEST(test_pushsubtract_5minus3); MU_RUN_TEST(test_ft_swap); + MU_RUN_TEST(test_ft_swap_ab); } int main(void) diff --git a/program_to_test/src/push_functions.c b/program_to_test/src/push_functions.c index 2c2d2d8..06f862d 100644 --- a/program_to_test/src/push_functions.c +++ b/program_to_test/src/push_functions.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/05/20 12:53:18 by umeneses ### ########.fr */ +/* Updated: 2024/05/20 13:13:47 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,17 +45,28 @@ void ft_swap(t_stack **stack) return ; first = *stack; last = *stack; - temp = 0; + temp = first->nbr; while (last->next != NULL) { last->prev = last; last = last->next; } - temp = first->nbr; first->nbr = last->nbr; last->nbr = temp; } +void ft_swap_ab(t_stack **stack_a, t_stack **stack_b) +{ + ft_swap(stack_a); + ft_swap(stack_b); +} + + + + + + + int push_add(int a, int b) { return (a + b);