Skip to content

Instantly share code, notes, and snippets.

@algmyr
Created October 23, 2018 21:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save algmyr/e1db4d2299bb228b33248f01f3c37d0d to your computer and use it in GitHub Desktop.
Save algmyr/e1db4d2299bb228b33248f01f3c37d0d to your computer and use it in GitHub Desktop.
Simple hackable test script
#!/bin/bash
mode="$1"
if [[ "$mode" == "perf" ]]; then
cmd="$2"
i=0
while true
do
echo "Test $((i+=1))"
python gen.py > gendata
time $cmd < gendata > /dev/null
echo "------------"
echo
done
elif [[ "$mode" == "stress" ]]; then
if [[ -z "$3" ]]; then
cmpcmd="diff -Z"
cmd="$2"
else
cmpcmd="$2"
cmd="$3"
fi
i=0
while (( $? == 0 ))
do
echo "Test $((i+=1))"
python gen.py > gendata
$cmpcmd <(python brute.py < gendata) <($cmd < gendata)
done
elif [[ "$mode" == "generate" ]]; then
n="$2"
if [[ "$n" == "" ]]; then n=10; fi
rm -rf tests
mkdir -p tests
for i in $(seq $n); do
infile=$(printf "tests/%03d.in" $i)
echo "Generate $infile"
python gen.py > $infile
done
elif [[ "$mode" == "answer" ]]; then
for infile in tests/*.in; do
echo "Generate answer for $infile"
base=${infile%.in}
ansfile=$base.ans
python brute.py < $infile > $ansfile
done
elif [[ "$mode" == "test" ]]; then
cmd="$2"
for infile in tests/*.in; do
base=${infile%.in}
ansfile=$base.ans
outfile=$base.out
echo "Test $infile"
diff -Z <($cmd < $infile) $ansfile
done
else
echo "Valid modes are: perf, stress, generate, answer, test"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment