ajout du script de comparaison

This commit is contained in:
hugogogo
2021-06-29 20:25:12 +02:00
parent d69bb36234
commit f081f15f58
15 changed files with 102 additions and 33 deletions

View File

@@ -75,5 +75,13 @@ leaks: clean $(NAME)
valgrind: clean $(NAME)
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) -p 4 67 9 76 98 7 1
testp : clean $(NAME)
./$(NAME) -p 76 81 10 11 12 15 14 27 34 28 17 18 19 20 36 21 23 37 22 24 25 26 29 30 31 72 33 53 46 32 35 91 38 39 40 45 78 41 57 71 54 43 42 44 66 50 47 48 49 79 51 56 93 65 64 63 67 90 58 59 60 62 61 87 68 74 82 85 86 77 75 70 73 89 69 83 84 92 88 95 94 96 99 97 98 100 1 2 3 4 5 6 7 8 9 52 16 55 80 13
test : clean $(NAME)
./$(NAME) 76 81 10 11 12 15 14 27 34 28 17 18 19 20 36 21 23 37 22 24 25 26 29 30 31 72 33 53 46 32 35 91 38 39 40 45 78 41 57 71 54 43 42 44 66 50 47 48 49 79 51 56 93 65 64 63 67 90 58 59 60 62 61 87 68 74 82 85 86 77 75 70 73 89 69 83 84 92 88 95 94 96 99 97 98 100 1 2 3 4 5 6 7 8 9 52 16 55 80 13
# 83 94 28 17 18 36 20 33 39 53 23 37 22 24 45 25 29 78 26 30 31 72 46 32 35 70 38 93 50 91 40 5 41 57 71 66 92 54 67 75 65 42 43 44 74 79 47 48 49 88 51 63 7 68 87 61 82 4 90 58 59 62 60 1 85 89 96 98 100 84 69 77 73 3 86 99 97 6 2 9 8 52 80 16 55 13 76 81 10 11 12 15 14 27 34 56 21 64 95 19
.PHONY: all clean fclean re gcc

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

52
compare_pushswap.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
# usage of arguments
if [ $# -eq 3 ]
then # names = path to programs
NAME1=$1
NAME2=$2
PRGRM1=$1 # path to programs
PRGRM2=$2
SIZE=$3 # size of the list
elif [ $# -eq 5 ]
then # names given in arguments
NAME1=$1
NAME2=$3
PRGRM1=$2 # path to programs
PRGRM2=$4
SIZE=$5 # size of the list
else
echo "usage : ./compare_pushswap file1 file2 nb"
echo "or : ./compare_pushswap name1 file1 name2 file2 nb"
exit 0
fi
# range of random numbers
RANGE=100
if [ $SIZE -gt 99 ]; then RANGE=1000; fi
if [ $SIZE -gt 999 ]; then echo "size too big"; exit 0; fi
# generate the list of randoms differents numbers
LIST=($(shuf -i 0-$RANGE -n $SIZE))
echo -e "${LIST[@]}"
# player equal number of line of programm output
PLAYER1=$(./$PRGRM1 ${LIST[@]} | wc -l)
PLAYER2=$(./$PRGRM2 ${LIST[@]} | wc -l)
# colors variables
RED='\033[1;31m'
GREEN='\033[1;32m'
NC='\033[0m'
if [ $PLAYER1 -lt $PLAYER2 ]
then
COLOR1=$GREEN
COLOR2=$RED
else
COLOR1=$RED
COLOR2=$GREEN
fi
echo -e "${COLOR1}$NAME1 : $PLAYER1${NC}"
echo -e "${COLOR2}$NAME2 : $PLAYER2${NC}"

BIN
push_swap

Binary file not shown.

View File

@@ -39,11 +39,14 @@ void fill_solution(t_list *solution, char *sp)
void print_result(t_list *result, int flag)
{
int i;
char **part;
i = -1;
result = result->next->next;
while (result)
{
i++;
part = ft_split(result->content, '!');
ft_printf("%s\n", part[0]);
if (flag)
@@ -57,4 +60,6 @@ void print_result(t_list *result, int flag)
free(part[2]);
free(part);
}
if (flag)
ft_putnbrendl(i);
}

View File

@@ -5,13 +5,14 @@ void push(t_stack **dst, t_stack **src)
t_stack *tmp1;
t_stack *tmp2;
if (!((*src)->next))
return ;
tmp1 = *src;
tmp2 = *dst;
*src = (*src)->next;
tmp1->next = tmp2;
*dst = tmp1;
if (*src)
{
tmp1 = *src;
tmp2 = *dst;
*src = (*src)->next;
tmp1->next = tmp2;
*dst = tmp1;
}
}
t_list *pa(t_stack **a, t_stack **b, t_list **solution)

View File

@@ -47,10 +47,10 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag)
ft_lstadd_back(&solution, ft_lstnew(b));
if (flag)
fill_solution(solution, "start");
hugo_sort(a, b, solution);
// hugo_sort(a, b, solution);
bubble_sort(a, b, solution);
return (solution);
}
// bubble_sort(&a, &b, solution);
int main(int ac, char **av)
{

View File

@@ -5,17 +5,18 @@ void reverse_rotate(t_stack **stack)
t_stack *tmp;
t_stack *before;
tmp = *stack;
if (!tmp || !(tmp->next))
return ;
while (tmp->next)
if (*stack && (*stack)->next)
{
before = tmp;
tmp = tmp->next;
tmp = *stack;
while (tmp->next)
{
before = tmp;
tmp = tmp->next;
}
tmp->next = *stack;
*stack = tmp;
before->next = NULL;
}
tmp->next = *stack;
*stack = tmp;
before->next = NULL;
}
t_list *rra(t_stack **a, t_list **lst)

View File

@@ -5,15 +5,16 @@ void rotate(t_stack **stack)
t_stack *tmp;
t_stack *first;
first = *stack;
tmp = *stack;
if (!tmp || !(tmp->next))
return ;
*stack = (*stack)->next;
while (tmp->next)
tmp = tmp->next;
tmp->next = first;
first->next = NULL;
if (*stack && (*stack)->next)
{
first = *stack;
tmp = *stack;
*stack = (*stack)->next;
while (tmp->next)
tmp = tmp->next;
tmp->next = first;
first->next = NULL;
}
}
t_list *ra(t_stack **a, t_list **lst)

View File

@@ -4,12 +4,13 @@ void swap(t_stack **stack)
{
t_stack *tmp;
tmp = *stack;
if (!(tmp->next))
return ;
*stack = (*stack)->next;
tmp->next = (*stack)->next;
(*stack)->next = tmp;
if (*stack && (*stack)->next)
{
tmp = *stack;
*stack = (*stack)->next;
tmp->next = (*stack)->next;
(*stack)->next = tmp;
}
}
t_list *sa(t_stack **a, t_list **solution)