#! /bin/tcsh -f
#
# Run the test plan defined in ./plan.{html,pdf}, q.v.
#
# See the version of run.csh in ../../1/testing for further explanatory 
# commentary about CSC 357 testing scripts.
#
# NOTE: Some of the test cases may take a while to run.  Given the normal
# behavior of a test run script, you will not see any output progress while the
# script is running, if everything runs correctly.  If you would like to see
# output as each case runs, edit the script in ./diff-case.csh where it says
# "Uncomment the next line to see intermediate progress".
#

#
# Set path to timelimit function (thanks, Phil).
#
alias timelimit ~gfisher/classes/357/bin/timelimit

#
# Set var so that files from /usr are referenced as local copies.
#
set usr_copy = ~gfisher/usr

#
# Check that there is an inputs directory and expected outputs-directory.
#
if ((! -e inputs) || (! -d inputs)) then
    echo "There is no inputs directory."
    exit
endif

if ((! -e expected-output) || (! -d expected-output)) then
    echo "There is no expected-output directory."
    exit
endif


#
# Check that there is an executable ./nwc.
#
if ((! -e ./nwc) || (! -x ./nwc)) then
    echo "There is no executable ./nwc program."
    exit
endif


#
# Make the output and diffs directories if necessary, and clear them both out.
#
if (! -e output) mkdir output
if (! -e diffs) mkdir diffs
if (`ls output` != "") rm -rf output/*
if (`ls diffs` != "") rm -rf diffs/*


#
# Set the timelimit value.
#
set limit = 15


#
# Zero out the scores file.
#
echo 0 > score


#
# Run the cases.
#
set c = 1

#
# Case 1.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc nonexistent >& output/$c\:no-file.errout
./diff-case.csh 1 $c\:no-file.errout 2 $*
@ c = $c + 1


#
# Case 2.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc -n xxx >& output/$c\:usage.errout
./diff-case.csh 2 $c\:usage.errout 2 $*
@ c = $c + 1


#
# Case 3.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/empty > output/$c\:empty.out
./diff-case.csh 3 $c\:empty.out 2 $*
@ c = $c + 1


#
# Case 4.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds > output/$c\:10-wds.out
./diff-case.csh 4 $c\:10-wds.out 10 $*
@ c = $c + 1


#
# Case 5.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds-rpts > output/$c\:10-wds-rpts.out
./diff-case.csh 5 $c\:10-wds-rpts.out 10 $*
@ c = $c + 1


#
# Case 6.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds-cases > output/$c\:10-wds-cases.out
./diff-case.csh 6 $c\:10-wds-cases.out 5 $*
@ c = $c + 1


#
# Case 7.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc < inputs/empty > output/$c\:empty-stdin.out
./diff-case.csh 7 $c\:empty-stdin.out 2 $*
@ c = $c + 1


#
# Case 8.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc <inputs/10-wds > output/$c\:10-wds-stdin.out
./diff-case.csh 8 $c\:10-wds-stdin.out 2 $*
@ c = $c + 1


#
# Case 9.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds-cases inputs/10-other-wds > output/$c\:10-of-20-wds.out
./diff-case.csh 9 $c\:10-of-20-wds.out 10 $*
@ c = $c + 1


#
# Case 10.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds-cases inputs/10-other-wds inputs/more-wds > output/$c\:3-in-files.out
./diff-case.csh 10 $c\:3-in-files.out  5 $*
@ c = $c + 1


#
# Case 11.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/10-wds-cases nonexistent inputs/10-other-wds inputs/more-wds >& output/$c\:3-in-files.errout
./diff-case.csh 11 $c\:3-in-files.errout 2 $*
@ c = $c + 1


#
# Case 12.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc -n 20 inputs/10-wds-cases inputs/10-other-wds inputs/more-wds > output/$c\:20-wds.out
./diff-case.csh 12 $c\:20-wds.out 6 $*
@ c = $c + 1


#
# Case 13.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc -n 50 inputs/10-wds-cases inputs/10-other-wds inputs/more-wds > output/$c\:33-wds.out
./diff-case.csh 13 $c\:33-wds.out 6 $*
@ c = $c + 1


#
# Case 14.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/many-1-wd  > output/$c\:many-1-wd.out
./diff-case.csh 14 $c\:many-1-wd.out 5 $*
@ c = $c + 1


#
# Case 15.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/many-wds > output/$c\:many-wds.out
./diff-case.csh 15 $c\:many-wds.out 5 $*
@ c = $c + 1


#
# Case 16.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/1-long-wd > output/$c\:1-long-wd.out
./diff-case.csh 16 $c\:1-long-wd.out 5 $*
@ c = $c + 1


#
# Case 17.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc inputs/man-tcsh > output/$c\:man-tcsh.out
./diff-case.csh 17 $c\:man-tcsh.out 3 $*
@ c = $c + 1


#
# Case 18.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc -n 20 inputs/man-tcsh > output/$c\:20-wds-man-tcsh.out
./diff-case.csh 18 $c\:20-wds-man-tcsh.out  2 $*
@ c = $c + 1


#
# Case 19.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc $usr_copy/dict/words > output/$c\:usr-dict-words.out
./diff-case.csh 19 $c\:usr-dict-words.out 4 $*
@ c = $c + 1


#
# Case 20.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc $usr_copy/dict/words $usr_copy/dict/words $usr_copy/dict/words > output/$c\:usr-dict-words-3.out
./diff-case.csh 20 $c\:usr-dict-words-3.out 3 $*
@ c = $c + 1


#
# Case 21.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc $usr_copy/man/man1/* > output/$c\:usr-man-man1.out
./diff-case.csh 21 $c\:usr-man-man1.out 3 $*
@ c = $c + 1


#
# Case 22.
#
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc $usr_copy/dict/words $usr_copy/man/man1/* > output/$c\:both-dict-man.out
./diff-case.csh 22 $c\:both-dict-man.out 3 $*
@ c = $c + 1


#
# Case 23.
#
@ limit = $limit * 2
if ($1 == "-v") echo Case $c
timelimit $limit ./nwc $usr_copy/dict/words $usr_copy/man/man*/* > output/$c\:all-man.out
./diff-case.csh 23 $c\:all-man.out 3 $*
@ c = $c + 1


#
# Print score.
#
echo ""
echo "Score: " `cat score`/100
echo ""


#  LocalWords:  pdf csh endif nwc diffs mkdir xxx wds rpts wd tcsh html
#  LocalWords:  timelimit gfisher
