Skip to content

Instantly share code, notes, and snippets.

@jb55
Last active December 19, 2017 20:54
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 jb55/8db763fdae9e24c9d6c769c12f2c698b to your computer and use it in GitHub Desktop.
Save jb55/8db763fdae9e24c9d6c769c12f2c698b to your computer and use it in GitHub Desktop.
Simple functional testing with bash
1..4
ok 1 - scalar division
ok 2 - scalar multiplication
not ok 3 - multiply 1 BTC to the smallest unit
#
# got '0 msat', expected '1 msat'
#
ok 4 - lots of msats
#!/usr/bin/env bash
n=1
c=$(wc -l < tests.csv)
fail=0
printf "1..%d\n" "$c"
while IFS=, read -r description args input expected
do
output=$(../bcalc $args <<<"$input")
if [ "$description" == "" ] || [ "$output" != "$expected" ]; then
printf "not ok %d - %s\n" "$n" "$description"
printf "#\n# got '%s', expected '%s'\n#\n" "$output" "$expected"
fail=1
else
printf "ok %d - %s\n" "$n" "$description"
fi
n=$((n + 1))
done < tests.csv
exit $fail
scalar division --btc -p 1 BTC / 10 0.1 BTC
scalar multiplication --btc 10 * 1 BTC 10
multiply 1 BTC to the smallest unit -pm 1 BTC * 0.00000000001 1 msat
lots of msats -B 1 msat * 100000000000 1
@jb55
Copy link
Author

jb55 commented Dec 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment