Skip to content

Commit

Permalink
Merge pull request #22 from biralavor/21-bugfix-if-is-sign-only
Browse files Browse the repository at this point in the history
21 bugfix if is sign only
  • Loading branch information
biralavor authored Jul 1, 2024
2 parents e96ace4 + 0bc5cda commit 6e45bd9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
20 changes: 10 additions & 10 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/07/01 11:14:31 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:47:24 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -459,7 +459,7 @@ MU_TEST(test_3rd_miastep_get_cost)
actual_size = ft_lst_size(stack_a);
ft_lst_map_all_indexers(&stack_a);
ft_push_b_all_but_three(&stack_a, &stack_b);
ft_sort_three_nbrs(&stack_a);
ft_sort_a_with_three_nbrs(&stack_a);
ft_lst_get_cost(&stack_a, &stack_b);
actual_top_a = ft_lst_goto_head(stack_a)->nbr;
actual_bottom_a = ft_lst_goto_end(stack_a)->nbr;
Expand Down Expand Up @@ -505,7 +505,7 @@ MU_TEST(test_3rd_miastep_map_get_target_position)
expected_target_pos = 2; // should be stack_b->target
actual_size = ft_lst_size(stack_a);
ft_push_b_all_but_three(&stack_a, &stack_b);
ft_sort_three_nbrs(&stack_a);
ft_sort_a_with_three_nbrs(&stack_a);
ft_lst_get_target_position(&stack_a, &stack_b);

actual_bottom_a = ft_lst_goto_end(stack_a)->nbr;
Expand Down Expand Up @@ -815,7 +815,7 @@ MU_TEST(test_2nd_miastep_push_b_all_but3_sort_a)
actual_bottom_a_before_push = ft_lst_goto_end(stack_a)->nbr;

ft_push_b_all_but_three(&stack_a, &stack_b);
ft_sort_three_nbrs(&stack_a);
ft_sort_a_with_three_nbrs(&stack_a);

expected_top_a_after_push = ft_atoi(argv_simulation[6]);
expected_bottom_a_after_push = ft_atoi(argv_simulation[5]);
Expand Down Expand Up @@ -1021,7 +1021,7 @@ MU_TEST(test_sort_3_nbrs_already_sorted)
expected_sorted_bottom = ft_atoi(argv_simulation[3]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_top = ft_lst_goto_head(stack)->nbr;
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ MU_TEST(test_sort_3_nbrs_highest_last)
expected_sorted_bottom = ft_atoi(argv_simulation[3]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_top = ft_lst_goto_head(stack)->nbr;
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
Expand Down Expand Up @@ -1091,7 +1091,7 @@ MU_TEST(test_sort_3_nbrs_highest_first_v2)
expected_sorted_bottom = ft_atoi(argv_simulation[1]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_top = ft_lst_goto_head(stack)->nbr;
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
Expand Down Expand Up @@ -1126,7 +1126,7 @@ MU_TEST(test_sort_3_nbrs_highest_first)
expected_sorted_bottom = ft_atoi(argv_simulation[1]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_top = ft_lst_goto_head(stack)->nbr;
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle_v2)
expected_sorted_bottom = ft_atoi(argv_simulation[2]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
stack = ft_lst_goto_head(stack);
Expand Down Expand Up @@ -1197,7 +1197,7 @@ MU_TEST(test_sort_3_nbrs_highest_at_middle)
expected_sorted_bottom = ft_atoi(argv_simulation[2]);
stack = ft_lts_buildstack_argv(&stack, argv_simulation);
ft_lst_map_all_indexers(&stack);
stack = ft_sort_three_nbrs(&stack);
stack = ft_sort_a_with_three_nbrs(&stack);
actual_size = ft_lst_size(stack);
actual_sorted_top = ft_lst_goto_head(stack)->nbr;
actual_sorted_bottom = ft_lst_goto_end(stack)->nbr;
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/06/28 17:20:40 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:46:32 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -69,7 +69,7 @@ bool ft_is_sorted(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);
t_stack *ft_sort_a_with_three_nbrs(t_stack **stack_a);
/* sorting functions if list has until 3 numbers */

void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b);
Expand Down
7 changes: 5 additions & 2 deletions program_to_test/src/ft_argv_validation.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/06/03 11:43:20 by umeneses #+# #+# */
/* Updated: 2024/07/01 11:11:25 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:36:11 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -26,8 +26,11 @@ bool ft_argv_valid_sign_and_not_alpha(char **argv)
if (ft_isalpha(*(argv[index] + c_counter)))
return (false);
if (ft_is_sign(*(argv[index] + c_counter)))
if (ft_is_sign(*(argv[index] + c_counter + 1)))
{
if (ft_is_sign(*(argv[index] + c_counter + 1))
|| (*(argv[index] + c_counter + 1) == '\0'))
return (false);
}
c_counter++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions program_to_test/src/ft_do_sort.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/06/06 18:46:55 by umeneses #+# #+# */
/* Updated: 2024/06/26 14:01:57 by umeneses ### ########.fr */
/* Updated: 2024/07/01 11:58:52 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,7 +22,7 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b)
if (stack_size == 2)
ft_sort_two_nbrs(stack_a);
else if (stack_size == 3)
ft_sort_three_nbrs(stack_a);
ft_sort_a_with_three_nbrs(stack_a);
else
{
ft_sort_five_or_more_nbr(stack_a, stack_b);
Expand Down
4 changes: 2 additions & 2 deletions program_to_test/src/ft_sort_5_or_more.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/06/10 12:41:29 by umeneses #+# #+# */
/* Updated: 2024/06/26 14:01:00 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:46:58 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,7 +15,7 @@
void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b)
{
ft_push_b_all_but_three(stack_a, stack_b);
ft_sort_three_nbrs(stack_a);
ft_sort_a_with_three_nbrs(stack_a);
while (*stack_b)
{
ft_lst_get_target_position(stack_a, stack_b);
Expand Down
26 changes: 13 additions & 13 deletions program_to_test/src/ft_sort_until3.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/06/04 12:19:14 by umeneses #+# #+# */
/* Updated: 2024/06/26 14:02:16 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:46:17 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,21 +33,21 @@ t_stack *ft_sort_two_nbrs(t_stack **list)
return (*list);
}

t_stack *ft_sort_three_nbrs(t_stack **list)
t_stack *ft_sort_a_with_three_nbrs(t_stack **stack_a)
{
int highest_pos;

*list = ft_lst_goto_head(*list);
if (ft_is_sorted(*list))
return (*list);
highest_pos = ft_lst_map_highest_pos(*list);
if ((*list)->final_pos == highest_pos)
ft_do_rotate_a(list);
else if ((*list)->next->final_pos == highest_pos)
ft_do_reverse_rotate_a(list);
if ((*list)->final_pos > (*list)->next->final_pos)
ft_do_swap_a(list);
return (*list);
*stack_a = ft_lst_goto_head(*stack_a);
if (ft_is_sorted(*stack_a))
return (*stack_a);
highest_pos = ft_lst_map_highest_pos(*stack_a);
if ((*stack_a)->final_pos == highest_pos)
ft_do_rotate_a(stack_a);
else if ((*stack_a)->next->final_pos == highest_pos)
ft_do_reverse_rotate_a(stack_a);
if ((*stack_a)->final_pos > (*stack_a)->next->final_pos)
ft_do_swap_a(stack_a);
return (*stack_a);
}

int ft_lst_map_highest_pos(t_stack *list)
Expand Down
4 changes: 2 additions & 2 deletions program_to_test/src/ft_sort_until4.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/06/10 12:41:29 by umeneses #+# #+# */
/* Updated: 2024/06/26 13:47:22 by umeneses ### ########.fr */
/* Updated: 2024/07/01 12:46:21 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,7 @@ void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b)
int highest_pos_b;

ft_push_b_all_but_three(stack_a, stack_b);
ft_sort_three_nbrs(stack_a);
ft_sort_a_with_three_nbrs(stack_a);
highest_pos_b = ft_lst_map_highest_pos(*stack_b);
if ((*stack_b)->final_pos == highest_pos_b)
{
Expand Down

0 comments on commit 6e45bd9

Please sign in to comment.