PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/code/Text-NSP-1.09/Testing/leftFisher/error-handling.sh

https://github.com/wwwjscom/Segments-Tester
Shell | 214 lines | 117 code | 54 blank | 43 comment | 15 complexity | f04841ca0b69a3986810259a181b7e32 MD5 | raw file
  1. #!/bin/csh -f
  2. # shell program to test leftFisher.pm's responses to various erroneous
  3. # conditions. note of course that leftFisher never halts on errors/warnings
  4. # but sets error codes that statistic.pl can request later on.
  5. # -------------------------------------------------------------------
  6. # Subtest 1: what happens when ngram > 2 is provided to leftFisher
  7. echo "Subtest 1"
  8. echo ""
  9. # input file
  10. set TESTFILE = "test-1.sub-1.cnt"
  11. # check if this file exists. if not, quit!
  12. if (!(-e $TESTFILE)) then
  13. echo "File $TESTFILE does not exist... aborting"
  14. exit
  15. endif
  16. # test-1.sub-1.cnt has trigrams in it. so leftFisher.pm should complain
  17. # during the initialization step, since leftFisher is for bigrams only!
  18. # required output file
  19. set TARGETFILE = "test-1.sub-1.reqd"
  20. if (!(-e $TARGETFILE)) then
  21. echo "File $TARGETFILE does not exist... aborting"
  22. exit
  23. endif
  24. # now the test!
  25. echo "Test: statistic.pl --ngram 3 leftFisher test-1.out $TESTFILE"
  26. statistic.pl --ngram 3 leftFisher test-1.out $TESTFILE >& error.out
  27. # compare the error output with the required output
  28. diff error.out $TARGETFILE > difference
  29. if (-z difference) then
  30. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  31. else
  32. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  33. cat difference
  34. endif
  35. echo ""
  36. /bin/rm -f difference
  37. /bin/rm -f error.out
  38. /bin/rm -f test-1.out
  39. # -------------------------------------------------------------------
  40. # Subtest 2: what happens when all three frequency values are not
  41. # available to leftFisher
  42. echo "Subtest 2"
  43. echo ""
  44. # input file
  45. set TESTFILE = "test-1.sub-2.cnt"
  46. # check if this file exists. if not, quit!
  47. if (!(-e $TESTFILE)) then
  48. echo "File $TESTFILE does not exist... aborting"
  49. exit
  50. endif
  51. # freq combo file describing above input file's frequency values
  52. set FREQCOMBFILE = "test-1.sub-2.freq_combo.txt"
  53. # check if this file exists. if not, quit!
  54. if (!(-e $FREQCOMBFILE)) then
  55. echo "File $FREQCOMBFILE does not exist... aborting"
  56. exit
  57. endif
  58. # test-1.sub-2.cnt has bigrams in it, but only 2 of the three required frequency values.
  59. # required output file
  60. set TARGETFILE = "test-1.sub-2.reqd"
  61. if (!(-e $TARGETFILE)) then
  62. echo "File $TARGETFILE does not exist... aborting"
  63. exit
  64. endif
  65. # now the test!
  66. echo "Test: statistic.pl --set_freq_combo $FREQCOMBFILE leftFisher test-1.out $TESTFILE"
  67. statistic.pl --set_freq_combo $FREQCOMBFILE leftFisher test-1.out $TESTFILE >& error.out
  68. # compare the error output with the required output
  69. diff error.out $TARGETFILE > difference
  70. if (-z difference) then
  71. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  72. else
  73. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  74. cat difference
  75. endif
  76. echo ""
  77. /bin/rm -f difference
  78. /bin/rm -f error.out
  79. /bin/rm -f test-1.out
  80. # -------------------------------------------------------------------
  81. # Subtest 3: what happens when the totalBigrams is less equal to 0
  82. echo "Subtest 3"
  83. echo ""
  84. # input file
  85. set TESTFILE = "test-1.sub-3.cnt"
  86. # check if this file exists. if not, quit!
  87. if (!(-e $TESTFILE)) then
  88. echo "File $TESTFILE does not exist... aborting"
  89. exit
  90. endif
  91. # test-1.sub-3.cnt has totalBigrams = -17 in it.
  92. # required output file
  93. set TARGETFILE = "test-1.sub-3.reqd"
  94. if (!(-e $TARGETFILE)) then
  95. echo "File $TARGETFILE does not exist... aborting"
  96. exit
  97. endif
  98. # now the test!
  99. echo "Test: statistic.pl leftFisher test-1.out $TESTFILE"
  100. statistic.pl leftFisher test-1.out $TESTFILE >& error.out
  101. # compare the error output with the required output
  102. diff error.out $TARGETFILE > difference
  103. if (-z difference) then
  104. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  105. else
  106. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  107. cat difference
  108. endif
  109. echo ""
  110. /bin/rm -f difference
  111. /bin/rm -f error.out
  112. /bin/rm -f test-1.out
  113. # -------------------------------------------------------------------
  114. # Subtest 4: what happens when the frequency values are "wrong"
  115. echo "Subtest 4"
  116. echo ""
  117. # input file
  118. set TESTFILE = "test-1.sub-4.cnt"
  119. # check if this file exists. if not, quit!
  120. if (!(-e $TESTFILE)) then
  121. echo "File $TESTFILE does not exist... aborting"
  122. exit
  123. endif
  124. # test-1.sub-4.cnt has only one bigram that has "correct"
  125. # values. every other is wrong!
  126. # required output file
  127. set TARGETFILE = "test-1.sub-4.reqd"
  128. if (!(-e $TARGETFILE)) then
  129. echo "File $TARGETFILE does not exist... aborting"
  130. exit
  131. endif
  132. # required error output file
  133. set TARGETERRORFILE = "test-1.sub-4.error.reqd"
  134. if (!(-e $TARGETERRORFILE)) then
  135. echo "File $TARGETERRORFILE does not exist... aborting"
  136. exit
  137. endif
  138. # now the test!
  139. echo "Test: statistic.pl leftFisher test-1.out $TESTFILE"
  140. statistic.pl leftFisher test-1.out $TESTFILE >& error.out
  141. # compare the error output with the required output
  142. diff error.out $TARGETERRORFILE > difference
  143. if (-z difference) then
  144. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETERRORFILE)"
  145. else
  146. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETERRORFILE :"
  147. cat difference
  148. endif
  149. # compare the actual output with the required output
  150. diff test-1.out $TARGETFILE > difference
  151. if (-z difference) then
  152. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  153. else
  154. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  155. cat difference
  156. endif
  157. echo ""
  158. /bin/rm -f difference
  159. /bin/rm -f error.out
  160. /bin/rm -f test-1.out