From e967d5dadc4a5f1d113b20cfb4fe8cfd89de9cf0 Mon Sep 17 00:00:00 2001 From: Bruce Adams Date: Tue, 24 Sep 2013 20:49:38 -0400 Subject: [PATCH] Add tests for the Python programs Adjust 06-the-one/tf-06.py to avoid adding an extra blank line at the end, so it will pass the tests. --- 06-the-one/tf-06.py | 2 +- test/pride-and-prejudice.txt | 25 +++++++++++++++++++++++++ test/test.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/pride-and-prejudice.txt create mode 100755 test/test.sh diff --git a/06-the-one/tf-06.py b/06-the-one/tf-06.py index 579f7f5..c114141 100644 --- a/06-the-one/tf-06.py +++ b/06-the-one/tf-06.py @@ -12,7 +12,7 @@ class TFTheOne: return TFTheOne(result) def printm(monad): - print monad._value + print monad._value, # # The functions diff --git a/test/pride-and-prejudice.txt b/test/pride-and-prejudice.txt new file mode 100644 index 0000000..3453ed3 --- /dev/null +++ b/test/pride-and-prejudice.txt @@ -0,0 +1,25 @@ +mr - 786 +elizabeth - 635 +very - 488 +darcy - 418 +such - 395 +mrs - 343 +much - 329 +more - 327 +bennet - 323 +bingley - 306 +jane - 295 +miss - 283 +one - 275 +know - 239 +before - 229 +herself - 227 +though - 226 +well - 224 +never - 220 +sister - 218 +soon - 216 +think - 211 +now - 209 +time - 203 +good - 201 diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..318b648 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +function msg() { + echo $(date +%T) "$@" +} + +failures=0 +total=0 +mydir=$(cd $(dirname $0); pwd) +files=$(echo *.txt) +for dir in ../[0-9][0-9]-* ; do + cd $dir + for file in $files ; do + exe=$(echo tf-[0-9][0-9].py) + msg testing $(basename $dir)/$exe with $file + python $exe ../$file | diff -b - $mydir/$file + result=$? + total=$((total+1)) + if [ $result -ne 0 ]; then + failures=$(($failures+1)) + msg FAILED! + else + msg passed. + fi + done + cd $mydir +done + +msg $(date +%T) Ran $total tests with $failures failures. +if [ $failures -ne 0 ]; then + msg FAILED! + exit $failures +fi +msg PASSED