tester and cas if n==2

This commit is contained in:
whaffman 2024-11-19 17:34:34 +01:00
parent e99b6f1ad4
commit 33ac159055
2 changed files with 54 additions and 25 deletions

View File

@ -92,7 +92,8 @@ void common_rotations(int *shortest_a, int *shortest_b, t_state *state)
void sortmore(t_state *state) void sortmore(t_state *state)
{ {
push_all_but_3_b(state); push_all_but_3_b(state);
sort3(state); if (ft_lstsize(state->a) == 3)
sort3(state);
while (state->b) while (state->b)
b_merge_a(best_merge_a(state), state); b_merge_a(best_merge_a(state), state);
rotate_a_to_top(state); rotate_a_to_top(state);

View File

@ -1,30 +1,58 @@
#!/bin/bash #!/bin/bash
# This script is used to test the program # This script is used to test the program
# test case 1
echo "Test case 1" run_test_case() {
MAX=0 echo "Test case $1"
MIN=10000 MAX=0
for i in {1..100} MIN=10000000
do AVG=0
ARG=$(shuf -i 0-1000 -n 500) ITER=$2
N=$(./push_swap $ARG | wc -l) N=$1
if [ $N -gt $MAX ] MAX_ARGS=""
then for i in $(seq 1 $ITER)
if [ $N -gt 5500 ]; then do
echo "Max: $N | $(echo $ARG | tr -d '\n')" ARG=$(seq -1000 1000 | shuf -n $N)
OPS=$(./push_swap $ARG | wc -l)
OK=$(./push_swap $ARG | ./checker_linux $ARG)
if [ $OPS -gt $MAX ]
then
MAX_ARGS="Max: $OPS | $(echo $ARG | tr -d '\n')"
MAX=$OPS
fi fi
MAX=$N if [ $OPS -lt $MIN ]
fi then
if [ $N -lt $MIN ] MIN=$OPS
then fi
MIN=$N AVG=$((AVG + OPS))
fi if [ $OK != "OK" ]
AVG=$((AVG + N)) then
done echo "================================"
AVG=$((AVG / 100)) echo "Error"
echo "Max: $MAX" echo "Args: $ARG"
echo "Min: $MIN" echo "Ops: $OPS"
echo "Average: $AVG" echo "Checker: $OK"
echo "================================"
return
fi
done
AVG=$((AVG / ITER))
echo "Iterations: $ITER"
echo "Max: $MAX"
echo "Min: $MIN"
echo "Average: $AVG"
echo "--------------------------------"
echo "Max Args: $MAX_ARGS"
echo "--------------------------------"
echo ""
}
run_test_case 1 10
run_test_case 2 10
run_test_case 3 200
run_test_case 5 200
run_test_case 50 100
run_test_case 100 100
run_test_case 500 50