Skip to content

Commit

Permalink
spliting tester into many files
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed Jul 5, 2024
1 parent 435d2a7 commit 55437ee
Show file tree
Hide file tree
Showing 10 changed files with 2,692 additions and 2,657 deletions.
5 changes: 2 additions & 3 deletions _ci_tdd/Makefile
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/10 10:09:44 by umeneses #+# #+# #
# Updated: 2024/07/04 15:53:05 by umeneses ### ########.fr #
# Updated: 2024/07/05 12:27:10 by umeneses ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -42,8 +42,7 @@ LIBS = $(LIBFT_D)libft.a $(PUSH_SWAP_D)

NAME = push_swap.tests

SRC_FILES = test_main_miunit.c
#SRC_FILES += minunit_utils.c
SRC_FILES = pushswap_main_tester.c

SRC_FILES_ALL = $(addprefix $(TEST_D), $(SRC_FILES))

Expand Down
66 changes: 66 additions & 0 deletions _ci_tdd/test_files/pushswap_main_tester.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pushswap_main_tester.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */
/* Updated: 2024/07/05 12:49:15 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

#include "minunit.h"
#include "push_swap.h"

#include "../../program_to_test/src/ft_argv_utils.c"
#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"
#include "../../program_to_test/src/ft_lst_addto.c"
#include "../../program_to_test/src/ft_lst_deletes.c"
#include "../../program_to_test/src/ft_lst_clear.c"
#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_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_do_sort.c"
#include "../../program_to_test/src/ft_do_move_with_cost.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_4_utils.c"

#include "test_minunit_utils.c"
#include "test01_list_init.c"
#include "test02_do_moves.c"
#include "test03_argv.c"
#include "test04_miasteps.c"
#include "test05_neg_non_zero_nbs.c"

int main(void)
{
MU_RUN_SUITE(linked_list_tests);

MU_RUN_SUITE(swap_tests);
MU_RUN_SUITE(push_tests);
MU_RUN_SUITE(rotate_tests);

MU_RUN_SUITE(argv_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_RUN_SUITE(negative_numbers_test);
MU_RUN_SUITE(non_numbers_test);
MU_RUN_SUITE(zero_tests);
MU_RUN_SUITE(three_neg_nbrs_tests);
MU_REPORT();
return (0);
}
282 changes: 282 additions & 0 deletions _ci_tdd/test_files/test01_list_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */
/* Updated: 2024/07/05 12:48:56 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

#include "minunit.h"
#include "push_swap.h"


MU_TEST(test_lst_delat_end)
{
// ARRANGE
int top = 11;
int second = 22;
int third = 33;
int bottom = 44;
int expected_top;
int expected_bottom;
int expected_size;
int actual_top;
int actual_bottom;
int actual_size;
t_stack *stack;

// ACT
stack = NULL;
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(bottom));
stack = ft_lst_goto_head(stack);
expected_size = ft_lst_size(stack) - 1;
expected_top = top;
expected_bottom = third;
stack = ft_lst_delat_end(stack);
actual_bottom = ft_lst_goto_end(stack)->nbr;
actual_top = ft_lst_goto_head(stack)->nbr;
actual_size = ft_lst_size(stack);

// ASSERT
mu_assert_int_eq(expected_size, actual_size);
mu_assert_int_eq(expected_top, actual_top);
mu_assert_int_eq(expected_bottom, actual_bottom);
ft_lstclear_single_ptr(stack);
}

MU_TEST(test_lst_delat_begin)
{
// ARRANGE
int top = 11;
int second = 22;
int third = 33;
int bottom = 44;
int expected_top;
int expected_bottom;
int expected_size;
int actual_top;
int actual_bottom;
int actual_size;
t_stack *stack;

// ACT
stack = NULL;
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(bottom));
stack = ft_lst_goto_head(stack);
expected_size = ft_lst_size(stack) - 1;
expected_top = second;
expected_bottom = bottom;
stack = ft_lst_delat_begin(stack);
actual_bottom = ft_lst_goto_end(stack)->nbr;
actual_top = ft_lst_goto_head(stack)->nbr;
actual_size = ft_lst_size(stack);

// ASSERT
mu_assert_int_eq(expected_size, actual_size);
mu_assert_int_eq(expected_top, actual_top);
mu_assert_int_eq(expected_bottom, actual_bottom);
ft_lstclear_single_ptr(stack);
}

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 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;
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(bottom));
expected_top = top;
expected_before_end = third;
expected_bottom = bottom;
expected_size = 4;
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);
actual_before_end = ft_lst_goto_before_end(stack)->nbr;
while (stack->next != NULL)
{
stack = stack->next;
}
actual_top_again = ft_lst_goto_head(stack)->nbr;
actual_ptr = ft_lst_goto_head(stack);

// ASSERT
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);
mu_assert_int_eq(expected_bottom, actual_bottom);
mu_assert_int_eq(expected_size, actual_size);
ft_lstclear_single_ptr(stack);
}

MU_TEST(test_lst_addto_end)
{
// ARRANGE
int top = 11;
int second = 22;
int third = 33;
int bottom = 44;
int expected_top;
int expected_bottom;
int actual_top;
int actual_bottom;
int expected_size;
int actual_size;
t_stack *stack;

// ACT
stack = NULL;
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(bottom));
expected_top = top;
expected_bottom = bottom;
while (stack && stack->prev)
stack = stack->prev;
actual_top = stack->nbr;
while (stack && stack->next)
stack = stack->next;
actual_bottom = stack->nbr;
while (stack && stack->prev)
stack = stack->prev;
actual_size = ft_lst_size(stack);
expected_size = 4;

// ASSERT
mu_assert_int_eq(expected_top, actual_top);
mu_assert_int_eq(expected_bottom, actual_bottom);
mu_assert_int_eq(expected_size, actual_size);
ft_lstclear_single_ptr(stack);
}

MU_TEST(test_lst_addto_begin)
{
// ARRANGE
int top = 11;
int second = 22;
int third = 33;
int bottom = 44;
int expected_top;
int expected_bottom;
int expected_size;
int actual_top;
int actual_bottom;
int actual_size;
t_stack *stack;

// ACT
stack = NULL;
stack = ft_lst_init(top);
stack = ft_lst_addto_begin(&stack, ft_lst_init(second));
stack = ft_lst_addto_begin(&stack, ft_lst_init(third));
stack = ft_lst_addto_begin(&stack, ft_lst_init(bottom));
expected_top = bottom;
expected_bottom = top;
while (stack && stack->prev)
stack = stack->prev;
actual_top = stack->nbr;
while (stack && stack->next)
stack = stack->next;
actual_bottom = stack->nbr;
while (stack && stack->prev)
stack = stack->prev;
actual_size = ft_lst_size(stack);
expected_size = 4;

// ASSERT
mu_assert_int_eq(expected_top, actual_top);
mu_assert_int_eq(expected_bottom, actual_bottom);
mu_assert_int_eq(expected_size, actual_size);
ft_lstclear_single_ptr(stack);
}

MU_TEST(test_lstsize_int_expec_3)
{
// ARRANGE
int top = 11;
int second = 22;
int bottom = 33;
int expected_size;
int actual_size;
t_stack *stack;

// ACT
stack = NULL;
stack = ft_lst_init(top);
stack = ft_lst_addto_end(&stack, ft_lst_init(second));
stack = ft_lst_addto_end(&stack, ft_lst_init(bottom));
actual_size = ft_lst_size(stack);
expected_size = 3;

// ASSERT
mu_assert_int_eq(expected_size, actual_size);
ft_lstclear_single_ptr(stack);
}

MU_TEST(test_lst_init_nbr)
{
// ARRANGE
int top = 11;
int expected_result;
int expected_size;
int actual_result;
int actual_size;
t_stack *stack;

// ACT
stack = ft_lst_init(top);
actual_result = stack->nbr;
expected_result = top;
actual_size = ft_lst_size(stack);
if ((stack->next == NULL) && (stack->prev == NULL))
expected_size = 1;

// ASSERT
mu_assert_int_eq(expected_result, actual_result);
mu_assert_int_eq(expected_size, actual_size);
ft_lstclear_single_ptr(stack);
}

MU_TEST_SUITE(linked_list_tests)
{
MU_RUN_TEST(test_lst_init_nbr);
MU_RUN_TEST(test_lstsize_int_expec_3);
MU_RUN_TEST(test_lst_addto_begin);
MU_RUN_TEST(test_lst_addto_end);
MU_RUN_TEST(test_lst_gotoend_head_and_beforeend);
MU_RUN_TEST(test_lst_delat_begin);
MU_RUN_TEST(test_lst_delat_end);
}
Loading

0 comments on commit 55437ee

Please sign in to comment.