Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #50 #52

Merged
merged 1 commit into from
May 3, 2023
Merged

Fix #50 #52

merged 1 commit into from
May 3, 2023

Conversation

younesaassila
Copy link
Contributor

Fixes #50 by properly calculating the additional indent level:

The previous code assumed a paren depth of 1 meant 2 tabs. This is incorrect and the code made a few exceptions for control statements and return statements to correct for this behavior. Of course, this couldn't catch all possible code where this adjustment was needed.

The new code assumes a paren depth of 1 means 1 tab. Tab count starts increasing once the paren depth is at least 2. (Had to check norminette's code to find this behavior, it wasn't fun)


Also fixed a test case that was based on the previous (incorrect) behavior (and it indeed made the norminette complain)


Finally, made a line of the code clearer and removed an unused comment at the top of the test file.

@cacharle cacharle requested a review from keyhr May 2, 2023 16:53
@keyhr
Copy link
Collaborator

keyhr commented May 2, 2023

Is Norminette rules changed after I quit 42? or did I just missed the test case?
Anyway, the code seems good.

@younesaassila
Copy link
Contributor Author

I don't believe the rules changed recently. The bug was just well hidden thanks to the discount system for if, while, etc.

@younesaassila
Copy link
Contributor Author

younesaassila commented May 2, 2023

@cacharle You should reopen #51 (marked as duplicate of #50) because they are not relating to the same issue. #51 seems to be a conflict with clang-format where clang-format breaks the alignment of a correctly aligned file and c_formatter_42 fails to fix it after. I can reproduce the bug (both old and new versions) with this file of mine (for function are_rotations_same_direction):

See: #53

Code
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   push_swap.h                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: yaassila <[email protected]>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2023/02/01 13:00:00 by yaassila          #+#    #+#             */
/*   Updated: 2023/02/14 18:00:00 by yaassila         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef PUSH_SWAP_H
# define PUSH_SWAP_H

# include "libft.h"
# include <limits.h>

// --- Types ---

typedef struct s_node
{
	int				data;
	struct s_node	*prev;
	struct s_node	*next;
}					t_node;

typedef struct s_stack
{
	t_node			*top;
	t_node			*bottom;
	size_t			size;
}					t_stack;

typedef struct s_find_result
{
	t_node			*node;
	size_t			index;
}					t_find_result;

typedef struct s_cost
{
	size_t			stack_a_index;
	size_t			stack_b_index;
	int				cost;
}					t_cost;

// --- Prototypes ---

int					parse_args(int argc, char const *argv[], t_stack *stack);

t_node				*node_new(int data);

t_stack				*stack_new(void);
void				stack_free(t_stack *stack);
void				stack_print(t_stack *stack);

t_find_result		stack_find(t_stack *stack, int data);
t_find_result		stack_find_min(t_stack *stack);
t_find_result		stack_find_max(t_stack *stack);

t_node				*stack_pop_top(t_stack *stack);
t_node				*stack_pop_bottom(t_stack *stack);

void				stack_push_top(t_stack *stack, t_node *node);
void				stack_push_bottom(t_stack *stack, t_node *node);

void				sa(t_stack *stack_a);
void				sb(t_stack *stack_b);
void				ss(t_stack *stack_a, t_stack *stack_b);

void				pa(t_stack *stack_a, t_stack *stack_b);
void				pb(t_stack *stack_a, t_stack *stack_b);

void				ra(t_stack *stack_a);
void				rb(t_stack *stack_b);
void				rr(t_stack *stack_a, t_stack *stack_b);

void				rra(t_stack *stack_a);
void				rrb(t_stack *stack_b);
void				rrr(t_stack *stack_a, t_stack *stack_b);

size_t				get_rotate_count(t_stack *stack, size_t index);
t_bool				are_rotations_same_direction(t_stack *stack_a,
						t_stack *stack_b, size_t index_a, size_t index_b);
t_bool				are_rotations_normal(t_stack *stack_a, t_stack *stack_b,
						size_t index_a, size_t index_b);

void				rotate_stack_to_index(t_stack *stack, size_t index,
						void (*r)(t_stack *), void (*rr)(t_stack *));
void				rotate_stacks_to_indices(t_stack *stack_a, t_stack *stack_b,
						size_t index_a, size_t index_b);

t_bool				is_stack_sorted_ascending(t_stack *stack);

void				sort(t_stack *stack_a, t_stack *stack_b);
void				three_sort(t_stack *stack_a);
void				insertion_sort(t_stack *stack_a, t_stack *stack_b);
void				min_cost_sort(t_stack *stack_a, t_stack *stack_b,
						size_t insertion_sort_threshold);

#endif

@cacharle cacharle merged commit c336f8a into dawnbeen:master May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TOO_MANY_TAB
3 participants