Skip to content

Commit

Permalink
implementing resverse_rotate_ab function
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed May 23, 2024
1 parent 27e1297 commit 3fa9e09
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 24 deletions.
90 changes: 69 additions & 21 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/05/23 18:56:21 by umeneses ### ########.fr */
/* Updated: 2024/05/23 19:10:51 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -21,36 +21,95 @@
#include "../../program_to_test/src/ft_push.c"
#include "../../program_to_test/src/ft_rotate.c"

MU_TEST(test_ft_reverse_rotate)
MU_TEST(test_ft_reverse_rotate_ab)
{
// ARRANGE
int top_a = 11;
int second_a = 22;
int third_a = 33;
int bottom_a = 44;
int top_b = 999;
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_size_a;
int expected_size_a;
int actual_size_b;
int expected_size_b;
t_stack *stack_a;
t_stack *stack_b;

expected_result_a = bottom_a;
expected_result_b = bottom_b;

// ACT
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(bottom_a));
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(bottom_b));
expected_size_a = ft_lstsize_int((t_list *)stack_a);
ft_reverse_rotate(&stack_a);
expected_size_b = ft_lstsize_int((t_list *)stack_b);
ft_reverse_rotate_ab(&stack_a, &stack_b);
actual_size_a = ft_lstsize_int((t_list *)stack_a);
actual_size_b = ft_lstsize_int((t_list *)stack_b);
actual_result_a = stack_a->nbr;
ft_printf("reverse rotate stack_A nbr: %d\n", stack_a->nbr);
actual_result_b = stack_b->nbr;
ft_printf("rotate stack_A nbr: %d\n", stack_a->nbr);
while (stack_a->next != NULL)
{
stack_a = stack_a->next;
ft_printf("reverse rotate stack_A nbr: %d\n", stack_a->nbr);
ft_printf("rotate stack_A nbr: %d\n", stack_a->nbr);
}
ft_printf("rotate stack_B nbr: %d\n", stack_b->nbr);
while (stack_b->next != NULL)
{
stack_b = stack_b->next;
ft_printf("rotate stack_B nbr: %d\n", 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_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);
ft_lstclear_single_ptr(stack_b);
}

MU_TEST(test_ft_reverse_rotate)
{
// ARRANGE
int top_a = 11;
int second_a = 22;
int third_a = 33;
int bottom_a = 44;
int actual_result_a;
int expected_result_a;
int actual_size_a;
int expected_size_a;
t_stack *stack_a;

expected_result_a = bottom_a;

// ACT
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(bottom_a));
expected_size_a = ft_lstsize_int((t_list *)stack_a);
ft_reverse_rotate(&stack_a);
actual_size_a = ft_lstsize_int((t_list *)stack_a);
actual_result_a = stack_a->nbr;
while (stack_a->next != NULL)
stack_a = stack_a->next;

// ASSERT
mu_assert_int_eq(expected_result_a, actual_result_a);
Expand All @@ -68,7 +127,7 @@ MU_TEST(test_ft_rotate_ab)
int top_b = 999;
int second_b = 888;
int third_b = 777;
int bottom_b = 555;
int bottom_b = 666;
int actual_result_a;
int actual_result_b;
int expected_result_a;
Expand All @@ -91,18 +150,6 @@ MU_TEST(test_ft_rotate_ab)
ft_rotate_ab(&stack_a, &stack_b);
actual_result_a = stack_a->nbr;
actual_result_b = stack_b->nbr;
// ft_printf("rotate stack_A nbr: %d\n", stack_a->nbr);
// while (stack_a->next != NULL)
// {
// stack_a = stack_a->next;
// ft_printf("rotate stack_A nbr: %d\n", stack_a->nbr);
// }
// ft_printf("rotate stack_B nbr: %d\n", stack_b->nbr);
// while (stack_b->next != NULL)
// {
// stack_b = stack_b->next;
// ft_printf("rotate stack_B nbr: %d\n", stack_b->nbr);
// }

// ASSERT
mu_assert_int_eq(expected_result_a, actual_result_a);
Expand Down Expand Up @@ -147,7 +194,7 @@ MU_TEST(test_ft_push_b)
int top_b = 999;
int second_b = 888;
int third_b = 777;
int bottom_b = 555;
int bottom_b = 666;
int actual_result_a;
int actual_result_b;
int expected_result_a;
Expand Down Expand Up @@ -188,7 +235,7 @@ MU_TEST(test_ft_push_a)
int top_b = 999;
int second_b = 888;
int third_b = 777;
int bottom_b = 555;
int bottom_b = 666;
int actual_result_a;
int actual_result_b;
int expected_result_a;
Expand Down Expand Up @@ -229,7 +276,7 @@ MU_TEST(test_ft_swap_ab)
int top_b = 99;
int second_b = 88;
int third_b = 77;
int bottom_b = 55;
int bottom_b = 66;
int actual_result_a;
int actual_result_b;
int expected_result_a;
Expand Down Expand Up @@ -479,6 +526,7 @@ MU_TEST_SUITE(rotate_tests)
MU_RUN_TEST(test_ft_rotate);
MU_RUN_TEST(test_ft_rotate_ab);
MU_RUN_TEST(test_ft_reverse_rotate);
MU_RUN_TEST(test_ft_reverse_rotate_ab);
}

int main(void)
Expand Down
4 changes: 2 additions & 2 deletions program_to_test/headers/push_swap.h
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/08 15:23:33 by umeneses #+# #+# */
/* Updated: 2024/05/23 17:21:41 by umeneses ### ########.fr */
/* Updated: 2024/05/23 19:03:10 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -41,7 +41,7 @@ void ft_push_b(t_stack **stack_a, t_stack **stack_b);
void ft_rotate(t_stack **stack);
void ft_rotate_ab(t_stack **stack_a, t_stack **stack_b);
void ft_reverse_rotate(t_stack **stack);
void ft_double_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
/* initial push_swap functions */

bool is_sorted(t_stack *stack);
Expand Down
11 changes: 10 additions & 1 deletion program_to_test/src/ft_rotate.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/23 11:48:11 by umeneses #+# #+# */
/* Updated: 2024/05/23 17:09:36 by umeneses ### ########.fr */
/* Updated: 2024/05/23 19:04:08 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,3 +44,12 @@ void ft_reverse_rotate(t_stack **stack)
*stack = ft_lst_addto_begin(*stack, ft_lst_init(temp));
*stack = ft_lst_delat_end(*stack);
}

void ft_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b)
{
if (*stack_a == NULL || (*stack_b == NULL)
|| ((*stack_a)->next == NULL || (*stack_b)->next == NULL))
return ;
ft_reverse_rotate(stack_a);
ft_reverse_rotate(stack_b);
}

0 comments on commit 3fa9e09

Please sign in to comment.