From 896a8afd5e94bb8925c4d975a971db0d140a7191 Mon Sep 17 00:00:00 2001 From: Willem Haffmans Date: Sun, 1 Dec 2024 13:51:47 +0000 Subject: [PATCH] small error in rr and fix tester.sh --- src/moves/reverse_rotate.c | 2 + tester.sh | 100 ++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/src/moves/reverse_rotate.c b/src/moves/reverse_rotate.c index 88069b0..373c37f 100644 --- a/src/moves/reverse_rotate.c +++ b/src/moves/reverse_rotate.c @@ -45,6 +45,8 @@ void reverse_rotate(t_list **stack) return ; temp = *stack; last = ft_lstlast(*stack); + if (ft_lstsize(*stack) <= 1) + return ; while (temp->next->next) temp = temp->next; temp->next = NULL; diff --git a/tester.sh b/tester.sh index 4d3bb60..f8b9309 100755 --- a/tester.sh +++ b/tester.sh @@ -77,7 +77,7 @@ run_test_case() { AVG=$((AVG / ITER)) VARIANCE=$((SUM_SQUARES / ITER - AVG * AVG)) STDDEV=$(echo "sqrt($VARIANCE)" | bc -l) - echo -e "Testing\t $BOLD$N \telements $ITER times:$NC \t\tmax:$GREEN $MAX$NC\t\tmin:$RED $MIN$NC\t\tavg: $AVG\t\tstddev: $(printf "%.2f" $STDDEV)" + echo -e "Testing\t $BOLD$N \telements $ITER times:$NC \t\tmax:$GREEN $MAX$NC\t\tmin:$RED $MIN$NC\t\tavg: $AVG\t\tstddev: $(printf "%.2f" $STDDEV)\n" >> results.txt # echo "Iterations: $ITER" # echo "Max: $MAX" # echo "Min: $MIN" @@ -98,183 +98,171 @@ run_test_case() { check_output() { local output=$1 local expected=$2 - local message=$3 + local message=$4 + local n=$3 if [ "$output" == "$expected" ]; then - echo -e "${message}: ${GREEN}OK${NC}" + echo -e "${n}.\t${GREEN}OK${NC}:\t${message}" else - echo -e "${message}: ${RED}KO${NC}" + echo -e "${n}.\t${RED}KO${NC}:\t${message}: " fi } # Test push_swap with non-numeric arguments ARGS="a b c" OUTPUT=$(./push_swap $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "1. Test push_swap with non-numeric arguments" +check_output "$OUTPUT" "Error" "1" "Test push_swap with non-numeric arguments" # Test push_swap with duplicate arguments ARGS="1 1 2 3" OUTPUT=$(./push_swap $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "2. Test push_swap with duplicate arguments" +check_output "$OUTPUT" "Error" "2" "Test push_swap with duplicate arguments" # Test push_swap with empty arguments OUTPUT=$(./push_swap 2>&1 >/dev/null) -check_output "$OUTPUT" "" "3. Test push_swap with empty arguments" +check_output "$OUTPUT" "" "3" "Test push_swap with empty arguments" # Test push_swap with invalid arguments ARGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 a" OUTPUT=$(./push_swap $ARGS 2>&1) -check_output "$OUTPUT" "Error" "4. Test push_swap with invalid arguments" +check_output "$OUTPUT" "Error" "4" "Test push_swap with invalid arguments" # Test push_swap with valid arguments ARGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" OUTPUT=$(./push_swap $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "" "5. Test push_swap with valid arguments" +check_output "$OUTPUT" "" "5" "Test push_swap with valid arguments" # Run push_swap with only numeric parameters including one greater than MAXINT. The program must display "Error". OUTPUT=$(./push_swap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 999999999999999 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "6. Test push_swap with only numeric parameters including one greater than MAXINT" +check_output "$OUTPUT" "Error" "6" "Test push_swap with only numeric parameters including one greater than MAXINT" # Run the following command "$>./push_swap 42". The program should display nothing (0 instruction). OUTPUT=$(./push_swap 42 2>&1 >/dev/null) -check_output "$OUTPUT" "" "7. Test push_swap with a single argument" +check_output "$OUTPUT" "" "7" "Test push_swap with a single argument" # Run the following command "$>./push_swap 2 3". The program should display nothing (0 instruction). OUTPUT=$(./push_swap 2 3 2>&1 >/dev/null) -check_output "$OUTPUT" "" "8. Test push_swap with two ordered arguments" +check_output "$OUTPUT" "" "8" "Test push_swap with two ordered arguments" # Run the following command "$>./push_swap 0 1 2 3". The program should display nothing (0 instruction). OUTPUT=$(./push_swap 0 1 2 3 2>&1 >/dev/null) -check_output "$OUTPUT" "" "9. Test push_swap with four ordered arguments" +check_output "$OUTPUT" "" "9" "Test push_swap with four ordered arguments" # Run the following command "$>./push_swap 'Between 0 and 9 randomly sorted values chosen>'. The program should display nothing (0 instruction). OUTPUT=$(./push_swap 11 22 33 44 55 66 77 88 99 2>&1 >/dev/null) -check_output "$OUTPUT" "" "10. Test push_swap with nine ordered arguments" +check_output "$OUTPUT" "" "10" "Test push_swap with nine ordered arguments" # Run the following command "$>./push_swap 0 1 2 3 4 5 6 7 8 9". The program should display nothing (0 instruction). OUTPUT=$(./push_swap 0 1 2 3 4 5 6 7 8 9 2>&1 >/dev/null) -check_output "$OUTPUT" "" "11. Test push_swap with ten ordered arguments" +check_output "$OUTPUT" "" "11" "Test push_swap with ten ordered arguments" # Test checker with non-numeric arguments ARGS="a b c" OUTPUT=$(./checker $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "12. Test checker with non-numeric arguments" +check_output "$OUTPUT" "Error" "12" "Test checker with non-numeric arguments" # Test checker with duplicate arguments ARGS="1 1 2 3" OUTPUT=$(./checker $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "13. Test checker with duplicate arguments" +check_output "$OUTPUT" "Error" "13" "Test checker with duplicate arguments" # Test checker with empty arguments OUTPUT=$(./checker 2>&1 >/dev/null) -check_output "$OUTPUT" "" "14. Test checker with empty arguments" +check_output "$OUTPUT" "" "14" "Test checker with empty arguments" # Test checker with invalid arguments ARGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 a" OUTPUT=$(./checker $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "15. Test checker with invalid arguments" +check_output "$OUTPUT" "Error" "15" "Test checker with invalid arguments" # Test checker with valid arguments ARGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" OUTPUT=$(./push_swap $ARGS | ./checker $ARGS) -check_output "$OUTPUT" "OK" "16. Test push_swap and checker with ordered list" +check_output "$OUTPUT" "OK" "16" "Test push_swap and checker with ordered list" # Run "$>ARG="2 1 0"; ./push_swap $ARG | ./checker_OS $ARG". Check that the checker program displays "OK" and that the size of the list of instructions from push_swap is 2 OR 3. Otherwise the test fails. OUTPUT=$(ARG="2 1 0"; ./push_swap $ARG | ./checker $ARG) -check_output "$OUTPUT" "OK" "17. Run \"$>ARG=\"2 1 0\"; ./push_swap \$ARG | ./checker_OS \$ARG\". Check that the checker program displays \"OK\"" +check_output "$OUTPUT" "OK" "17" "Run \"$>ARG=\"2 1 0\"; ./push_swap \$ARG | ./checker_OS \$ARG\". Check that the checker program displays \"OK\"" OUTPUT=$(ARG="2 1 0"; ./push_swap $ARG | wc -l) if [ "$OUTPUT" -lt 3 ]; then - echo -e "18. The size of the list of instructions from push_swap is less than 3: ${GREEN}OK${NC}" + echo -e "18.\t${GREEN}OK${NC}:\tThe size of the list of instructions from push_swap is less than 3" else - echo -e "18. The size of the list of instructions from push_swap is less than 3: ${RED}KO${NC}" + echo -e "18\t${RED}KO${NC}:\tThe size of the list of instructions from push_swap is less than 3" fi # Run "$>ARG="1 5 2 4 3"; ./push_swap $ARG | ./checker_OS $ARG". Check that the checker program displays "OK" and that the size of the list of instructions from push_swap is 12. Otherwise the test fails. OUTPUT=$(ARG="1 5 2 4 3"; ./push_swap $ARG | ./checker $ARG) -check_output "$OUTPUT" "OK" "19. Run \"$>ARG=\"1 5 2 4 3\"; ./push_swap \$ARG | ./checker_OS \$ARG\". Check that the checker program displays \"OK\"" +check_output "$OUTPUT" "OK" "19" "Run \"$>ARG=\"1 5 2 4 3\"; ./push_swap \$ARG | ./checker_OS \$ARG\". Check that the checker program displays \"OK\"" OUTPUT=$(ARG="1 5 2 4 3"; ./push_swap $ARG | wc -l) if [ "$OUTPUT" -lt 12 ]; then - echo -e "20. The size of the list of instructions from push_swap is less than 12: ${GREEN}OK${NC}" + echo -e "20.\t${GREEN}OK${NC}:\tThe size of the list of instructions from push_swap is less than 12" else - echo -e "20. The size of the list of instructions from push_swap is less than 12: ${RED}KO${NC}" + echo -e "20.\t${RED}KO${NC}:\tThe size of the list of instructions from push_swap is less than 12" fi # Run checker with valid parameters and an invalid action ARGS="1 2 3" ACTIONS="invalid_action" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "21. Run checker with valid parameters and an invalid action" +check_output "$OUTPUT" "Error" "21" "Run checker with valid parameters and an invalid action" # Run checker with valid parameters and an action with spaces ARGS="1 2 3" ACTIONS=" sa \npb\nrrr " OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS 2>&1 >/dev/null) -check_output "$OUTPUT" "Error" "22. Run checker with valid parameters and an action with spaces" +check_output "$OUTPUT" "Error" "22" "Run checker with valid parameters and an action with spaces" # Run checker with a specific command and action list ARGS="0 9 1 8 2 7 3 6 4 5" -ACTIONS="sa\npb\nrrr\n" +ACTIONS="sa\npb\nrrr" +# echo -e "$ACTIONS" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "KO" "23. Run checker with specific command and action list" +check_output "$OUTPUT" "KO" "23" "Run checker with specific command and action list" # Run checker with a valid list and a valid instruction list that doesn't order the integers ARGS="4 3 2 1" ACTIONS="sa\npb\nra\nrra\npa" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "KO" "24. Run checker with valid list and invalid instruction list" +check_output "$OUTPUT" "KO" "24" "Run checker with valid list and invalid instruction list" ARGS="5 1 3 2 4" ACTIONS="pb\npb\nsa\npa\npa" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "KO" "25. Run checker with valid list and invalid instruction list" +check_output "$OUTPUT" "KO" "25" "Run checker with valid list and invalid instruction list" ARGS="6 5 4 3 2 1" ACTIONS="pb\npb\npb\nsa\npa\npa\npa" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "KO" "26. Run checker with valid list and invalid instruction list" +check_output "$OUTPUT" "KO" "26" "Run checker with valid list and invalid instruction list" # Run checker with no instructions ARGS="0 1 2" -OUTPUT=$(echo -e "" | ./checker $ARGS) -check_output "$OUTPUT" "OK" "27. Run checker with no instructions" +OUTPUT=$(printf "" | ./checker $ARGS) +check_output "$OUTPUT" "OK" "27" "Run checker with no instructions" # Run checker with a specific command and valid action list ARGS="0 9 1 8 2" ACTIONS="pb\nra\npb\nra\nsa\nra\npa\npa" OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "OK" "28. Run checker with specific command and valid action list" - -# Run checker with a valid list and a valid instruction list that orders the integers -ARGS="3 2 1" -ACTIONS="sa\nra\nsa\nrra" -OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "OK" "29. Run checker with valid list and valid instruction list" - -ARGS="4 1 3 2" -ACTIONS="pb\npb\nsa\npa\npa" -OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "OK" "30. Run checker with valid list and valid instruction list" - -ARGS="5 4 3 2 1" -ACTIONS="pb\npb\npb\nsa\npa\npa\npa" -OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) -check_output "$OUTPUT" "OK" "31. Run checker with valid list and valid instruction list" +check_output "$OUTPUT" "OK" "28" "Run checker with specific command and valid action list" # Repeat the test with several permutations for i in {1..5}; do ARGS=$(seq 1 5 | shuf | tr '\n' ' ') ACTIONS=$(./push_swap $ARGS) OUTPUT=$(echo -e "$ACTIONS" | ./checker $ARGS) - check_output "$OUTPUT" "OK" "32. Run checker with random permutation $i" + check_output "$OUTPUT" "OK" $((29 + i)) "Run checker with random permutation $i" done run_test_case 3 100 run_test_case 5 100 run_test_case 7 100 run_test_case 10 100 -run_test_case 50 1 -run_test_case 100 1 -run_test_case 500 1 +run_test_case 50 100 +run_test_case 100 100 +run_test_case 500 100 + cat results.txt | column -t + rm results.txt \ No newline at end of file