/code/Text-NSP-1.09/Testing/ll3/error-handling.sh
Shell | 209 lines | 117 code | 53 blank | 39 comment | 15 complexity | 9b6881b13548fd795e4a012d22ab6fd1 MD5 | raw file
- #!/bin/csh -f
- # shell program to test ll3.pm's responses to various erroneous
- # conditions. note of course that ll3 never halts on errors/warnings
- # but sets error codes that statistic.pl can request later on.
- # Subtest 1: what happens when ngram != 3 is provided to ll3
- echo "Subtest 1"
- echo ""
- # input file
- set TESTFILE = "test-1.sub-1.cnt"
- # check if this file exists. if not, quit!
- if (!(-e $TESTFILE)) then
- echo "File $TESTFILE does not exist... aborting"
- exit
- endif
- # test-1.sub-1.cnt has trigrams in it. so ll3.pm should complain
- # during the initialization step, since ll3 is for trigrams only!
- # required output file
- set TARGETFILE = "test-1.sub-1.reqd"
- if (!(-e $TARGETFILE)) then
- echo "File $TARGETFILE does not exist... aborting"
- exit
- endif
- # now the test!
- echo "Test: statistic.pl ll3 test-1.out $TESTFILE"
- statistic.pl ll3 test-1.out $TESTFILE >& error.out
- # compare the error output with the required output
- diff error.out $TARGETFILE > difference
- if (-z difference) then
- echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
- else
- echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
- cat difference
- endif
- echo ""
- /bin/rm -f difference
- /bin/rm -f error.out
- /bin/rm -f test-1.out
- # Subtest 2: what happens when all 7 frequency values are not
- # available to ll3
- echo "Subtest 2"
- echo ""
- # input file
- set TESTFILE = "test-1.sub-2.cnt"
- # check if this file exists. if not, quit!
- if (!(-e $TESTFILE)) then
- echo "File $TESTFILE does not exist... aborting"
- exit
- endif
- # freq combo file describing above input file's frequency values
- set FREQCOMBFILE = "test-1.sub-2.freq_combo.txt"
- # check if this file exists. if not, quit!
- if (!(-e $FREQCOMBFILE)) then
- echo "File $FREQCOMBFILE does not exist... aborting"
- exit
- endif
- # test-1.sub-2.cnt has trigrams in it, but only 6 of the 7 required frequency values.
- # required output file
- set TARGETFILE = "test-1.sub-2.reqd"
- if (!(-e $TARGETFILE)) then
- echo "File $TARGETFILE does not exist... aborting"
- exit
- endif
- # now the test!
- echo "Test: statistic.pl --set_freq_combo $FREQCOMBFILE ll3 test-1.out $TESTFILE"
- statistic.pl --ngram 3 --set_freq_combo $FREQCOMBFILE ll3 test-1.out $TESTFILE >& error.out
- # compare the error output with the required output
- diff error.out $TARGETFILE > difference
- if (-z difference) then
- echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
- else
- echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
- cat difference
- endif
- echo ""
- /bin/rm -f difference
- /bin/rm -f error.out
- /bin/rm -f test-1.out
- # Subtest 3: what happens when the totalBigrams is less equal to 0
- echo "Subtest 3"
- echo ""
- # input file
- set TESTFILE = "test-1.sub-3.cnt"
- # check if this file exists. if not, quit!
- if (!(-e $TESTFILE)) then
- echo "File $TESTFILE does not exist... aborting"
- exit
- endif
- # test-1.sub-3.cnt has totalBigrams = -17 in it.
- # required output file
- set TARGETFILE = "test-1.sub-3.reqd"
- if (!(-e $TARGETFILE)) then
- echo "File $TARGETFILE does not exist... aborting"
- exit
- endif
- # now the test!
- echo "Test: statistic.pl ll3 test-1.out $TESTFILE"
- statistic.pl --ngram 3 ll3 test-1.out $TESTFILE >& error.out
- # compare the error output with the required output
- diff error.out $TARGETFILE > difference
- if (-z difference) then
- echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
- else
- echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
- cat difference
- endif
- echo ""
- /bin/rm -f difference
- /bin/rm -f error.out
- /bin/rm -f test-1.out
- # Subtest 4: what happens when the frequency values are "wrong"
- echo "Subtest 4"
- echo ""
- # input file
- set TESTFILE = "test-1.sub-4.cnt"
- # check if this file exists. if not, quit!
- if (!(-e $TESTFILE)) then
- echo "File $TESTFILE does not exist... aborting"
- exit
- endif
- # test-1.sub-4.cnt has only one trigram that has "correct"
- # values. every other is wrong!
- # required output file
- set TARGETFILE = "test-1.sub-4.reqd"
- if (!(-e $TARGETFILE)) then
- echo "File $TARGETFILE does not exist... aborting"
- exit
- endif
- # required error output file
- set TARGETERRORFILE = "test-1.sub-4.error.reqd"
- if (!(-e $TARGETERRORFILE)) then
- echo "File $TARGETERRORFILE does not exist... aborting"
- exit
- endif
- # now the test!
- echo "Test: statistic.pl ll3 test-1.out $TESTFILE"
- statistic.pl --ngram 3 ll3 test-1.out $TESTFILE >& error.out
- # compare the error output with the required output
- diff error.out $TARGETERRORFILE > difference
- if (-z difference) then
- echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETERRORFILE)"
- else
- echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETERRORFILE :"
- cat difference
- endif
- # compare the actual output with the required output
- diff test-1.out $TARGETFILE > difference
- if (-z difference) then
- echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
- else
- echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
- cat difference
- endif
- echo ""
- /bin/rm -f difference
- /bin/rm -f error.out
- /bin/rm -f test-1.out