diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-09-10 19:37:16 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-09-10 19:37:16 +0200 |
| commit | 48fc8d0ffa3bfb766d28bce858eccb68fb0fdec5 (patch) | |
| tree | f20299615e35f5b8c0c40eadf5f04c4945d0e5ed /test.sh | |
| parent | 7a6533373ab9b0dd075f995c98dcf332a7876fac (diff) | |
| download | push_swap-48fc8d0ffa3bfb766d28bce858eccb68fb0fdec5.tar.gz push_swap-48fc8d0ffa3bfb766d28bce858eccb68fb0fdec5.tar.bz2 push_swap-48fc8d0ffa3bfb766d28bce858eccb68fb0fdec5.zip | |
Added check for already sorted stack, Added special cases for length 3 stacks, Added test.sh benchmark and testing all permutations
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)" |
