From 48fc8d0ffa3bfb766d28bce858eccb68fb0fdec5 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 10 Sep 2021 19:37:16 +0200 Subject: Added check for already sorted stack, Added special cases for length 3 stacks, Added test.sh benchmark and testing all permutations --- test.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'test.sh') diff --git a/test.sh b/test.sh index 2f39818..d27aebc 100755 --- a/test.sh +++ b/test.sh @@ -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 <