PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

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