Skip to content

Commit

Permalink
Merge pull request #11 from biralavor/10-bugfixargv-validation-range
Browse files Browse the repository at this point in the history
10 bugfixargv validation range
  • Loading branch information
biralavor authored Jun 27, 2024
2 parents ef984a8 + f1f24a2 commit 588f9a8
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 104 deletions.
4 changes: 2 additions & 2 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/06/20 12:50:07 by umeneses ### ########.fr #
# Updated: 2024/06/27 17:02:35 by umeneses ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -75,7 +75,7 @@ COMP_EXE = $(CC) $(LDFLAGS) $(OBJ_FILES) $(LDLIBS) -o $(NAME)
# **************************************************************************** #

define arguments
42 1 10 21 11 77 666
42 -2 10 -10 11 77 666 -2147483648 2147483647
endef

define bonus
Expand Down
105 changes: 99 additions & 6 deletions _ci_tdd/test_files/test_main_miunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 19:06:12 by umeneses #+# #+# */
/* Updated: 2024/06/26 14:06:06 by umeneses ### ########.fr */
/* Updated: 2024/06/27 17:01:14 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"
Expand All @@ -36,7 +37,7 @@
// #include "minunit_utils.h"

// TODO:
// make test for a list with 5 or more numbers
// make test for a list with 8 or more numbers
// make test for negative numbers
// make test for double or more signs (-- +++)

Expand Down Expand Up @@ -961,6 +962,94 @@ MU_TEST(test_buildstack_argv)
ft_array_clear(argv_simulation, expected_size);
}

MU_TEST(test_argv_inside_range_intmin_intmax_outside_int_min)
{
// ARRANGE
char **argv_simulation = NULL;
char *userinput;
int expected_size;
int expected;
int result;

// ACT
userinput = "./push_swap 1 4 3 2 -2147483649 12 9";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
expected = false;

result = ft_argv_inside_range_intmin_intmax(argv_simulation);

// ASSERT
mu_assert_int_eq(expected, result);
ft_array_clear(argv_simulation, expected_size);
}

MU_TEST(test_argv_inside_range_intmin_intmax_inside_int_min)
{
// ARRANGE
char **argv_simulation = NULL;
char *userinput;
int expected_size;
int expected;
int result;

// ACT
userinput = "./push_swap 1 4 3 2 -2147483648 12 9";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
expected = true;

result = ft_argv_inside_range_intmin_intmax(argv_simulation);

// ASSERT
mu_assert_int_eq(expected, result);
ft_array_clear(argv_simulation, expected_size);
}

MU_TEST(test_argv_inside_range_intmin_intmax_outside_int_max)
{
// ARRANGE
char **argv_simulation = NULL;
char *userinput;
int expected_size;
int expected;
int result;

// ACT
userinput = "./push_swap 1 4 3 2 2147483649 12 9";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
expected = false;

result = ft_argv_inside_range_intmin_intmax(argv_simulation);

// ASSERT
mu_assert_int_eq(expected, result);
ft_array_clear(argv_simulation, expected_size);
}

MU_TEST(test_argv_inside_range_intmin_intmax_inside_int_max)
{
// ARRANGE
char **argv_simulation = NULL;
char *userinput;
int expected_size;
int expected;
int result;

// ACT
userinput = "./push_swap 1 4 3 2 2147483647 12 9";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
expected = true;

result = ft_argv_inside_range_intmin_intmax(argv_simulation);

// ASSERT
mu_assert_int_eq(expected, result);
ft_array_clear(argv_simulation, expected_size);
}

MU_TEST(test_argv_is_duplicated_true)
{
// ARRANGE
Expand All @@ -974,8 +1063,8 @@ MU_TEST(test_argv_is_duplicated_true)
userinput = "./push_swap 1 2 3 4 5 6 7 8 2 9";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
actual_result = ft_argv_is_duplicated(argv_simulation);
expected_result = true;
actual_result = ft_argv_is_not_duplicated(argv_simulation);
expected_result = false;

// ASSERT
mu_assert_int_eq(expected_result, actual_result);
Expand All @@ -995,8 +1084,8 @@ MU_TEST(test_argv_is_duplicated_false)
userinput = "./push_swap 1 2 3 4 5 6 7 8";
argv_simulation = ft_split(userinput, ' ');
expected_size = ft_minunit_array_counter(argv_simulation);
actual_result = ft_argv_is_duplicated(argv_simulation);
expected_result = false;
actual_result = ft_argv_is_not_duplicated(argv_simulation);
expected_result = true;

// ASSERT
mu_assert_int_eq(expected_result, actual_result);
Expand Down Expand Up @@ -1697,6 +1786,10 @@ MU_TEST_SUITE(argv_tests)
MU_RUN_TEST(test_argv_size);
MU_RUN_TEST(test_argv_is_duplicated_false);
MU_RUN_TEST(test_argv_is_duplicated_true);
MU_RUN_TEST(test_argv_inside_range_intmin_intmax_inside_int_min);
MU_RUN_TEST(test_argv_inside_range_intmin_intmax_outside_int_min);
MU_RUN_TEST(test_argv_inside_range_intmin_intmax_inside_int_max);
MU_RUN_TEST(test_argv_inside_range_intmin_intmax_outside_int_max);
MU_RUN_TEST(test_buildstack_argv);
MU_RUN_TEST(test_buildstack_non_nbr);
}
Expand Down
3 changes: 2 additions & 1 deletion program_to_test/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/09 17:59:28 by umeneses #+# #+# #
# Updated: 2024/06/26 12:23:15 by umeneses ### ########.fr #
# Updated: 2024/06/26 15:35:39 by umeneses ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -45,6 +45,7 @@ LIBS = $(LIBFT)
NAME = push_swap

SRC_FILES = push_main.c
SRC_FILES += ft_argv_utils.c
SRC_FILES += ft_argv_validation.c
SRC_FILES += ft_do_sort.c
SRC_FILES += ft_do_push_fts.c
Expand Down
135 changes: 69 additions & 66 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/06/26 12:21:53 by umeneses ### ########.fr */
/* Updated: 2024/06/27 14:17:14 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -29,83 +29,86 @@ typedef struct s_stack
struct s_stack *next;
} t_stack;

t_stack *ft_lst_init(int value);
t_stack *ft_lst_goto_end(t_stack *stack);
t_stack *ft_lst_goto_head(t_stack *stack);
t_stack *ft_lst_goto_before_end(t_stack *stack);
t_stack *ft_lst_addto_end(t_stack **stack, t_stack *new);
t_stack *ft_lst_addto_begin(t_stack **stack, t_stack *new);
t_stack *ft_lst_delat_begin(t_stack *stack);
t_stack *ft_lst_delat_end(t_stack *stack);
void ft_lstclear_double_ptr(t_stack **stack);
void ft_lstclear_single_ptr(t_stack *stack);
void ft_lst_printf_data_content(char *msg, t_stack *stack);
t_stack *ft_lts_buildstack_argv(t_stack **stack, char **argv);
bool ft_is_sign(int c);
bool ft_is_space(int c);
bool ft_argv_is_duplicated(char **argv);
int ft_argv_size(char **argv);
bool ft_argv_validation(char **argv);
t_stack *ft_lst_init(int value);
t_stack *ft_lst_goto_end(t_stack *stack);
t_stack *ft_lst_goto_head(t_stack *stack);
t_stack *ft_lst_goto_before_end(t_stack *stack);
t_stack *ft_lst_addto_end(t_stack **stack, t_stack *new);
t_stack *ft_lst_addto_begin(t_stack **stack, t_stack *new);
t_stack *ft_lst_delat_begin(t_stack *stack);
t_stack *ft_lst_delat_end(t_stack *stack);
void ft_lstclear_double_ptr(t_stack **stack);
void ft_lstclear_single_ptr(t_stack *stack);
void ft_lst_printf_data_content(char *msg, t_stack *stack);
t_stack *ft_lts_buildstack_argv(t_stack **stack, char **argv);
bool ft_is_sign(int c);
bool ft_is_space(int c);
bool ft_argv_is_not_duplicated(char **argv);
int ft_argv_size(char **argv);
bool ft_argv_signs_and_nbrs(char **argv);
long int ft_atoi_long_int(const char *str);
bool ft_argv_inside_range_intmin_intmax(char **argv);
bool ft_argv_validation(char **argv);
/* new functions for push_swap to be added in LIBFT */

int ft_lst_size(t_stack *stack);
void ft_swap(t_stack **stack);
void ft_swap_ab(t_stack **stack_a, t_stack **stack_b);
void ft_push_a(t_stack **stack_a, t_stack **stack_b);
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_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
int ft_lst_size(t_stack *stack);
void ft_swap(t_stack **stack);
void ft_swap_ab(t_stack **stack_a, t_stack **stack_b);
void ft_push_a(t_stack **stack_a, t_stack **stack_b);
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_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
/* basic push_swap functions */

bool ft_is_sorted(t_stack *stack);
bool ft_is_sorted(t_stack *stack);
/* sorting validation functions */

int ft_lst_map_highest_pos(t_stack *list);
void ft_do_sort(t_stack **stack_a, t_stack **stack_b);
t_stack *ft_sort_two_nbrs(t_stack **stack);
t_stack *ft_sort_three_nbrs(t_stack **stack);
int ft_lst_map_highest_pos(t_stack *list);
void ft_do_sort(t_stack **stack_a, t_stack **stack_b);
t_stack *ft_sort_two_nbrs(t_stack **stack);
t_stack *ft_sort_three_nbrs(t_stack **stack);
/* sorting functions if list has until 3 numbers */

void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b);
void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b);
void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b);
int ft_lst_get_target(t_stack **stack_a, int b_end_pos,
int target_end_pos, int target_pos);
void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b);
void ft_lst_map_all_indexers(t_stack **stack);
void ft_lst_map_actual_position(t_stack **stack);
void ft_lst_map_final_pos(t_stack **stack, int stack_size);
int ft_lst_map_lowest_final_position(t_stack **stack);
void ft_lst_shift_stack(t_stack **stack_a);
void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b);
int abs_nbr(int nbr);
void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b);
void ft_do_move_after_cheapest(t_stack **stack_a, t_stack **stack_b,
int cost_a, int cost_b);
void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b);
void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b);
void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b);
int ft_lst_get_target(t_stack **stack_a, int b_end_pos,
int target_end_pos, int target_pos);
void ft_lst_get_target_position(t_stack **stack_a, t_stack **stack_b);
void ft_lst_map_all_indexers(t_stack **stack);
void ft_lst_map_actual_position(t_stack **stack);
void ft_lst_map_final_pos(t_stack **stack, int stack_size);
int ft_lst_map_lowest_final_position(t_stack **stack);
void ft_lst_shift_stack(t_stack **stack_a);
void ft_lst_get_cost(t_stack **stack_a, t_stack **stack_b);
int abs_nbr(int nbr);
void ft_lst_do_cheapest_move(t_stack **stack_a, t_stack **stack_b);
void ft_do_move_after_cheapest(t_stack **stack_a, t_stack **stack_b,
int cost_a, int cost_b);
/* sorting functions if list has 4 or more numbers */

void ft_rev_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b,
int *cost_a, int *cost_b);
void ft_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b,
int *cost_a, int *cost_b);
void ft_rotate_a_with_cost(t_stack **stack_a, int *cost_a);
void ft_rotate_b_with_cost(t_stack **stack_b, int *cost_b);
void ft_rev_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b,
int *cost_a, int *cost_b);
void ft_rotate_ab_with_cost(t_stack **stack_a, t_stack **stack_b,
int *cost_a, int *cost_b);
void ft_rotate_a_with_cost(t_stack **stack_a, int *cost_a);
void ft_rotate_b_with_cost(t_stack **stack_b, int *cost_b);
/* sorting functions take takes the cheapest cost and do the move */

void ft_do_swap_a(t_stack **stack);
void ft_do_swap_b(t_stack **stack);
void ft_do_swap_ab(t_stack **stack_a, t_stack **stack_b);
void ft_do_push_a(t_stack **stack_a, t_stack **stack_b);
void ft_do_push_b(t_stack **stack_a, t_stack **stack_b);
void ft_push(t_stack **source, t_stack **destiny);
void ft_do_rotate_a(t_stack **stack);
void ft_do_rotate_b(t_stack **stack);
void ft_do_rotate_ab(t_stack **stack_a, t_stack **stack_b);
void ft_do_reverse_rotate_a(t_stack **stack);
void ft_do_reverse_rotate_b(t_stack **stack);
void ft_do_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
void ft_do_swap_a(t_stack **stack);
void ft_do_swap_b(t_stack **stack);
void ft_do_swap_ab(t_stack **stack_a, t_stack **stack_b);
void ft_do_push_a(t_stack **stack_a, t_stack **stack_b);
void ft_do_push_b(t_stack **stack_a, t_stack **stack_b);
void ft_push(t_stack **source, t_stack **destiny);
void ft_do_rotate_a(t_stack **stack);
void ft_do_rotate_b(t_stack **stack);
void ft_do_rotate_ab(t_stack **stack_a, t_stack **stack_b);
void ft_do_reverse_rotate_a(t_stack **stack);
void ft_do_reverse_rotate_b(t_stack **stack);
void ft_do_reverse_rotate_ab(t_stack **stack_a, t_stack **stack_b);
/* functions that call sorting and print the action on STDOUT */

#endif
Loading

0 comments on commit 588f9a8

Please sign in to comment.