Created
May 10, 2013 01:57
-
-
Save dmoney/5551923 to your computer and use it in GitHub Desktop.
Script for verifying the output of a FizzBuzz program. $ ./fizzbuzz.sh | ./fizzcheck.sh
$ ./fizzcheck.sh ./fizzbuzz.sh`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# fizzbuzz.sh - A reference FizzBuzz program for testing fizzcheck.sh | |
# Author: Dustin King (cathodion@gmail.com) | |
limit=20 | |
i=1 | |
while expr $i '<=' $limit >/dev/null; do | |
out= | |
if expr $i % 3 = 0 >/dev/null; then out=Fizz; fi | |
if expr $i % 5 = 0 >/dev/null; then out="$out"Buzz; fi | |
if expr X$out = X'' >/dev/null; then out=$i; fi | |
echo $out | |
i=`expr $i + 1` | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# fizzcheck.sh - A script for verifying the output of FizzBuzz | |
# Author: Dustin King (cathodion@gmail.com) | |
# Original idea from https://twitter.com/qntm/status/329560932269301760 | |
CMD=${1-'cat -'} | |
i=1 | |
$CMD | while read actual; do | |
expect= | |
if expr $i % 3 = 0 >/dev/null; then expect=Fizz; fi | |
if expr $i % 5 = 0 >/dev/null; then expect="$expect"Buzz; fi | |
if expr X$expect = X'' >/dev/null; then expect=$i; fi | |
if expr "X$actual" '!=' "X$expect" >/dev/null; then | |
echo $i: Expected: \"$expect\", got \"$actual\"; | |
exit 1 | |
fi | |
i=`expr $i + 1` | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment