Skip to content

Commit

Permalink
adding new function - ft_swap_ab
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed May 20, 2024
1 parent 90f4e63 commit 02a8e31
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
48 changes: 46 additions & 2 deletions _ci_tdd/test_files/test_main_miunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,57 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "minunit.h"
#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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions program_to_test/src/push_functions.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/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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 02a8e31

Please sign in to comment.