Skip to content

Instantly share code, notes, and snippets.

@halivert
Created April 10, 2021 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halivert/f88485d4916deb4d5fc7948bfdc3edb8 to your computer and use it in GitHub Desktop.
Save halivert/f88485d4916deb4d5fc7948bfdc3edb8 to your computer and use it in GitHub Desktop.
Mini test framework (Tests programs with single input (stdin) and single output (stdout))
EXEC="./$1"
function test() {
if [ "$1" $2 "$3" ]; then
echo -e "\e[32mPASS\e[0m"
else
echo -e "\e[31mNOT PASS - $1 $4 $3 \e[0m"
fi
}
function assertEquals() {
test $(echo $1 | $EXEC) = $2 "should be"
}
function assertDifferent() {
test $(echo $1 | $EXEC) != $2 "should not be"
}
# e.g.
# EXEC=fibonacci
# assertEquals 3 2
# assertEquals 6 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment