diff options
Diffstat (limited to 'test.sh')
| -rwxr-xr-x | test.sh | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -54,7 +54,44 @@ assert_error() { assert "$1" "Error" } -if [ "$1" = "--error" ]; then +if [ "$1" = "--bench" ] +then + [ "$#" -ne 3 ] && echo 'Usage: ./test.sh --bench num_bench stack_len' && exit 1 + total=0 + num_bench="$2" + stack_len="$3" + for i in $(seq "$num_bench") + do + instruction_count="$(seq "$stack_len" | shuf | xargs ./push_swap | wc -l)" + total=$((total + instruction_count)) + printf "%4d: %7d, current average: %7d\n" "$i" "$instruction_count" $((total / i)) + done + printf "Final Total: %7d\n" "$total" + printf "Final Average: %7d\n" $((total / num_bench)) + exit 0 +fi + +if [ "$1" = "--perm" ] +then + [ -z "$2" ] && echo 'Usage: ./test.sh --perm stack_len' && exit 1 + stack_len="$2" + python <<EOF | +from itertools import permutations +print('\n'.join([' '.join(map(str, p)) for p in permutations(range(1, $stack_len + 1))])) +EOF + while read -r perm + do + + instructions=$(./push_swap $perm) + instruction_count="$(echo "$instructions" | wc -w)" + check=$(printf "%s\n" "$instructions" | ./checker $perm) + printf "%s: %3d, check: %s, instructions: %s\n" "$perm" "$instruction_count" "$check" "$(echo $instructions)" + done + exit 0 +fi + +if [ "$1" = "--error" ] +then printf "No arguments:\n" if [ -z "$(./checker)" ] then @@ -139,6 +176,8 @@ else end="$3" fi +[ -f result.log ] && rm result.log + for i in $(seq 1 "$test_nb") do arg="$(seq "$start" "$end" | shuf | xargs)" |
