PageRenderTime 23ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/wwwjscom/Segments-Tester
Shell | 586 lines | 325 code | 151 blank | 110 comment | 39 complexity | f4bd4668d92b00e6cd53e1dd9be7846b MD5 | raw file
  1. #!/bin/csh -f
  2. # shell program to test statistic.pl's responses to various erroneous
  3. # conditions
  4. # Subtest 1: what happens when the ngram in the input file does not
  5. # have the expected number of tokens
  6. echo "Subtest 1"
  7. echo ""
  8. # input file
  9. set TESTFILE = "test-1.sub-1.cnt"
  10. set PERL5LIB = pwd
  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. # library file
  17. set LIB = "test_1_sub_3_d.pm"
  18. if (!(-e $LIB)) then
  19. echo "File $LIB does not exist... aborting"
  20. exit
  21. endif
  22. # subtest 1 a
  23. # test-1.sub-1.cnt has trigrams in it. so statistic.pl should be run with
  24. # --ngram 3. if no --ngram provided, then bigram is assumed and there
  25. # should be an error as defined in test-1.sub-1-a.reqd.
  26. # required output file
  27. set TARGETFILE = "test-1.sub-1-a.reqd"
  28. if (!(-e $TARGETFILE)) then
  29. echo "File $TARGETFILE does not exist... aborting"
  30. exit
  31. endif
  32. # now the test!
  33. echo "Test: statistic.pl $LIB test-1.out $TESTFILE"
  34. statistic.pl $LIB test-1.out $TESTFILE >& error.out
  35. # compare the error output with the required output
  36. diff error.out $TARGETFILE > difference
  37. if (-z difference) then
  38. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  39. else
  40. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  41. cat difference
  42. endif
  43. echo ""
  44. /bin/rm -f difference
  45. /bin/rm -f error.out
  46. /bin/rm -f test-1.out
  47. # subtest 1 b
  48. # similarly, there should an error when --ngram 4 is used, as defined
  49. # in test-1.sub-1-b.reqd.
  50. # required output file
  51. set TARGETFILE = "test-1.sub-1-b.reqd"
  52. if (!(-e $TARGETFILE)) then
  53. echo "File $TARGETFILE does not exist... aborting"
  54. exit
  55. endif
  56. # now the test!
  57. echo "Test: statistic.pl --ngram 4 $LIB test-1.out $TESTFILE"
  58. statistic.pl --ngram 4 $LIB test-1.out $TESTFILE >& error.out
  59. # compare the error output with the required output
  60. diff error.out $TARGETFILE > difference
  61. if (-z difference) then
  62. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  63. else
  64. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  65. cat difference
  66. endif
  67. echo ""
  68. /bin/rm -f difference
  69. /bin/rm -f error.out
  70. /bin/rm -f test-1.out
  71. # subtest 1 c
  72. # finally, there should be no complaint when using --ngram 3
  73. # required output file
  74. set TARGETFILE = "test-1.sub-1-c.reqd"
  75. if (!(-e $TARGETFILE)) then
  76. echo "File $TARGETFILE does not exist... aborting"
  77. exit
  78. endif
  79. # now the test!
  80. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  81. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  82. # compare the error output with the required output
  83. diff error.out $TARGETFILE > difference
  84. if (-z difference) then
  85. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  86. else
  87. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  88. cat difference
  89. endif
  90. echo ""
  91. /bin/rm -f difference
  92. /bin/rm -f error.out
  93. /bin/rm -f test-1.out
  94. # Subtest 2: what happens when the number of frequency values in the
  95. # input file does not match with expected value (expected by default
  96. # from the --ngram setting or from the --set_freq_combo setting.
  97. echo "Subtest 2"
  98. echo ""
  99. # input file
  100. set TESTFILE = "test-1.sub-2.cnt"
  101. # check if this file exists. if not, quit!
  102. if (!(-e $TESTFILE)) then
  103. echo "File $TESTFILE does not exist... aborting"
  104. exit
  105. endif
  106. # library file
  107. set LIB = "test_1_sub_3_d.pm"
  108. if (!(-e $LIB)) then
  109. echo "File $LIB does not exist... aborting"
  110. exit
  111. endif
  112. # subtest 2 a
  113. # test-1.sub-2.cnt has trigrams in it, but with only 4 frequency
  114. # values as opposed to the possible 7. this file was created using
  115. # test-1.sub-2.freq_combo.txt file with the --set_freq_combo
  116. # switch. so statistic.pl should also be run with --set_freq_combo
  117. # test-1.sub-2.freq_combo.txt. Check what happens if we dont provide
  118. # this file!
  119. # required output file
  120. set TARGETFILE = "test-1.sub-2-a.reqd"
  121. if (!(-e $TARGETFILE)) then
  122. echo "File $TARGETFILE does not exist... aborting"
  123. exit
  124. endif
  125. # now the test!
  126. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  127. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  128. # compare the error output with the required output
  129. diff error.out $TARGETFILE > difference
  130. if (-z difference) then
  131. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  132. else
  133. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  134. cat difference
  135. endif
  136. echo ""
  137. /bin/rm -f difference
  138. /bin/rm -f error.out
  139. /bin/rm -f test-1.out
  140. # subtest 2 b
  141. # there shouldnt be any problems if we use --set_freq_combo test-1.sub-2.freq_combo.txt
  142. # required output file
  143. set TARGETFILE = "test-1.sub-2-b.reqd"
  144. set FREQCOMBFILE = "test-1.sub-2.freq_combo.txt"
  145. # first check if these files exist. if any one does not, quit
  146. if (!(-e $TARGETFILE)) then
  147. echo "File $TARGETFILE does not exist... aborting"
  148. exit
  149. endif
  150. if (!(-e $FREQCOMBFILE)) then
  151. echo "File $FREQCOMBFILE does not exist... aborting"
  152. exit
  153. endif
  154. # now the test!
  155. echo "Test: statistic.pl --ngram 3 --set_freq_comb $FREQCOMBFILE $LIB test-1.out $TESTFILE"
  156. statistic.pl --ngram 3 --set_freq_comb $FREQCOMBFILE $LIB test-1.out $TESTFILE >& error.out
  157. # compare the error output with the required output
  158. diff error.out $TARGETFILE > difference
  159. if (-z difference) then
  160. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  161. else
  162. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  163. cat difference
  164. endif
  165. echo ""
  166. /bin/rm -f difference
  167. /bin/rm -f error.out
  168. /bin/rm -f test-1.out
  169. # Subtest 3: what happens when the mandatory functions
  170. # initializeStatistic() and calculateStatistic() are not defined in
  171. # the statistic library file.
  172. echo "Subtest 3"
  173. echo ""
  174. # input file
  175. set TESTFILE = "test-1.sub-1.cnt"
  176. # check if this file exists. if not, quit!
  177. if (!(-e $TESTFILE)) then
  178. echo "File $TESTFILE does not exist... aborting"
  179. exit
  180. endif
  181. # subtest 3 a
  182. # statistical library file test_1_sub_3_a.pm neither defines nor
  183. # exports the symbols &calculateStatistic and &initializeStatistic
  184. # statistic.pl should give an error! note that since our testfile
  185. # test-1.sub-1.cnt has trigrams, we shall run statistic.pl with
  186. # --ngram 3
  187. # library file
  188. set LIB = "test_1_sub_3_a.pm"
  189. if (!(-e $LIB)) then
  190. echo "File $LIB does not exist... aborting"
  191. exit
  192. endif
  193. # required output file
  194. set TARGETFILE = "test-1.sub-3-a.reqd"
  195. if (!(-e $TARGETFILE)) then
  196. echo "File $TARGETFILE does not exist... aborting"
  197. exit
  198. endif
  199. # now the test!
  200. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  201. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  202. # compare the error output with the required output
  203. diff error.out $TARGETFILE > difference
  204. if (-z difference) then
  205. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  206. else
  207. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  208. cat difference
  209. endif
  210. echo ""
  211. /bin/rm -f difference
  212. /bin/rm -f error.out
  213. /bin/rm -f test-1.out
  214. # subtest 3 b
  215. # statistical library file test_1_sub_3_b.pm defines
  216. # initializeStatistic but not calculateStatistic.
  217. # library file
  218. set LIB = "test_1_sub_3_b.pm"
  219. if (!(-e $LIB)) then
  220. echo "File $LIB does not exist... aborting"
  221. exit
  222. endif
  223. # required output file
  224. set TARGETFILE = "test-1.sub-3-b.reqd"
  225. if (!(-e $TARGETFILE)) then
  226. echo "File $TARGETFILE does not exist... aborting"
  227. exit
  228. endif
  229. # now the test!
  230. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  231. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  232. # compare the error output with the required output
  233. diff error.out $TARGETFILE > difference
  234. if (-z difference) then
  235. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  236. else
  237. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  238. cat difference
  239. endif
  240. echo ""
  241. /bin/rm -f difference
  242. /bin/rm -f error.out
  243. /bin/rm -f test-1.out
  244. # subtest 3 c
  245. # statistical library file test_1_sub_3_c.pm defines
  246. # calculateStatistic but not initializeStatistic.
  247. # library file
  248. set LIB = "test_1_sub_3_c.pm"
  249. if (!(-e $LIB)) then
  250. echo "File $LIB does not exist... aborting"
  251. exit
  252. endif
  253. # required output file
  254. set TARGETFILE = "test-1.sub-3-c.reqd"
  255. if (!(-e $TARGETFILE)) then
  256. echo "File $TARGETFILE does not exist... aborting"
  257. exit
  258. endif
  259. # now the test!
  260. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  261. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  262. # compare the error output with the required output
  263. diff error.out $TARGETFILE > difference
  264. if (-z difference) then
  265. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  266. else
  267. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  268. cat difference
  269. endif
  270. echo ""
  271. /bin/rm -f difference
  272. /bin/rm -f error.out
  273. /bin/rm -f test-1.out
  274. # subtest 3 d
  275. # statistical library file test_1_sub_3_d.pm defines both
  276. # calculateStatistic and initializeStatistic, so should not get any
  277. # errors on this one!
  278. # library file
  279. set LIB = "test_1_sub_3_d.pm"
  280. if (!(-e $LIB)) then
  281. echo "File $LIB does not exist... aborting"
  282. exit
  283. endif
  284. # required output file
  285. set TARGETFILE = "test-1.sub-3-d.reqd"
  286. if (!(-e $TARGETFILE)) then
  287. echo "File $TARGETFILE does not exist... aborting"
  288. exit
  289. endif
  290. # now the test!
  291. echo "Test: statistic.pl --ngram 3 $LIB test-1.out $TESTFILE"
  292. statistic.pl --ngram 3 $LIB test-1.out $TESTFILE >& error.out
  293. # compare the error output with the required output
  294. diff error.out $TARGETFILE > difference
  295. if (-z difference) then
  296. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  297. else
  298. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  299. cat difference
  300. endif
  301. echo ""
  302. /bin/rm -f difference
  303. /bin/rm -f error.out
  304. /bin/rm -f test-1.out
  305. # Subtest 4: what happens when the commandline is short on files?!
  306. echo "Subtest 4"
  307. echo ""
  308. # library file for all of subtest 4
  309. set LIB = "test_1_sub_3_d.pm"
  310. if (!(-e $LIB)) then
  311. echo "File $LIB does not exist... aborting"
  312. exit
  313. endif
  314. # subtest 4 a
  315. # run statistic.pl with only a library
  316. # required output file
  317. set TARGETFILE = "test-1.sub-4-a.reqd"
  318. if (!(-e $TARGETFILE)) then
  319. echo "File $TARGETFILE does not exist... aborting"
  320. exit
  321. endif
  322. # now the test!
  323. echo "Test: statistic.pl $LIB"
  324. statistic.pl $LIB >& error.out
  325. # compare the error output with the required output
  326. diff error.out $TARGETFILE > difference
  327. if (-z difference) then
  328. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  329. else
  330. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  331. cat difference
  332. endif
  333. echo ""
  334. /bin/rm -f difference
  335. /bin/rm -f error.out
  336. # subtest 4 b
  337. # run statistic.pl with only a library and an output file
  338. # required output file
  339. set TARGETFILE = "test-1.sub-4-b.reqd"
  340. if (!(-e $TARGETFILE)) then
  341. echo "File $TARGETFILE does not exist... aborting"
  342. exit
  343. endif
  344. # now the test!
  345. echo "Test: statistic.pl $LIB test-1.out"
  346. statistic.pl $LIB test-1.out >& error.out
  347. # compare the error output with the required output
  348. diff error.out $TARGETFILE > difference
  349. if (-z difference) then
  350. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  351. else
  352. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  353. cat difference
  354. endif
  355. echo ""
  356. /bin/rm -f difference
  357. /bin/rm -f error.out
  358. /bin/rm -f test-1.out
  359. # Subtest 5: what happens when the input frequency combinations dont
  360. # have the ngram frequency and a frequency cut off is requested?!
  361. echo "Subtest 5"
  362. echo ""
  363. # test file
  364. set TESTFILE = "test-1.sub-5.cnt"
  365. if (!(-e $TESTFILE)) then
  366. echo "File $TESTFILE does not exist... aborting"
  367. exit
  368. endif
  369. # freq combo file
  370. set FREQCOMBFILE = "test-1.sub-5.freq_comb.txt"
  371. if (!(-e $FREQCOMBFILE)) then
  372. echo "File $FREQCOMBFILE does not exist... aborting"
  373. exit
  374. endif
  375. # library file
  376. set LIB = "test_1_sub_3_d.pm"
  377. if (!(-e $LIB)) then
  378. echo "File $LIB does not exist... aborting"
  379. exit
  380. endif
  381. # file test-1.sub-5.cnt does not have the main ngram frequency and has
  382. # only the two marginal totals. a frequency cut off is meaningless
  383. # here, and should be warned off and ignored.
  384. # required output file
  385. set TARGETFILE = "test-1.sub-5.reqd"
  386. if (!(-e $TARGETFILE)) then
  387. echo "File $TARGETFILE does not exist... aborting"
  388. exit
  389. endif
  390. # now the test!
  391. echo "Test: statistic.pl --frequency 2 --set_freq_combo $FREQCOMBFILE $LIB test-1.out $TESTFILE"
  392. statistic.pl --frequency 2 --set_freq_combo $FREQCOMBFILE $LIB test-1.out $TESTFILE >& error.out
  393. # compare the error output with the required output
  394. diff error.out $TARGETFILE > difference
  395. if (-z difference) then
  396. echo "Status: OK\!\! Output error message matches target error message (as provided in $TARGETFILE)"
  397. else
  398. echo "Status: ERROR\!\! Following differences exist between error.out and $TARGETFILE :"
  399. cat difference
  400. endif
  401. echo ""
  402. /bin/rm -f difference
  403. /bin/rm -f error.out
  404. /bin/rm -f test-1.out
  405. # Subtest 6: what happens when the tokens include internal marker <||>
  406. # Test added by Amruta during version 0.71
  407. echo "Subtest 6"
  408. echo ""
  409. echo "Test: statistic.pl ll test-1.out test-1.sub-6.cnt"
  410. statistic.pl ll test-1.out test-1.sub-6.cnt >& error.out
  411. diff error.out test-1.sub-6.reqd > difference
  412. if(-z difference) then
  413. echo "Status: OK\!\! Output error message matches target error message (as provided in test-1.sub-6.reqd)"
  414. else
  415. echo "Status: ERROR\!\! Following differences exist between error.out and test-1.sub-6.reqd :"
  416. cat difference
  417. endif
  418. echo ""
  419. /bin/rm -f difference error.out test-1.out
  420. /bin/mv -f test_1_sub_3_a.pm test_1_sub_3_a.pm_test
  421. /bin/mv -f test_1_sub_3_b.pm test_1_sub_3_b.pm_test
  422. /bin/mv -f test_1_sub_3_c.pm test_1_sub_3_c.pm_test
  423. /bin/mv -f test_1_sub_3_d.pm test_1_sub_3_d.pm_test
  424. /bin/mv -f test_2.pm test_2.pm_test
  425. /bin/mv -f Text/NSP/Measures/2D/test_1_sub_3_a.pm Text/NSP/Measures/2D/test_1_sub_3_a.pm_test
  426. /bin/mv -f Text/NSP/Measures/2D/test_1_sub_3_b.pm Text/NSP/Measures/2D/test_1_sub_3_b.pm_test
  427. /bin/mv -f Text/NSP/Measures/2D/test_1_sub_3_c.pm Text/NSP/Measures/2D/test_1_sub_3_c.pm_test
  428. /bin/mv -f Text/NSP/Measures/2D/test_1_sub_3_d.pm Text/NSP/Measures/2D/test_1_sub_3_d.pm_test
  429. /bin/mv -f Text/NSP/Measures/2D/test_2.pm Text/NSP/Measures/2D/test_2.pm_test
  430. /bin/mv -f Text/NSP/Measures/2D/test-1.pm Text/NSP/Measures/2D/test-1.pm_test
  431. /bin/mv -f Text/NSP/Measures/3D/test_1_sub_3_a.pm Text/NSP/Measures/3D/test_1_sub_3_a.pm_test
  432. /bin/mv -f Text/NSP/Measures/3D/test_1_sub_3_b.pm Text/NSP/Measures/3D/test_1_sub_3_b.pm_test
  433. /bin/mv -f Text/NSP/Measures/3D/test_1_sub_3_c.pm Text/NSP/Measures/3D/test_1_sub_3_c.pm_test
  434. /bin/mv -f Text/NSP/Measures/3D/test_1_sub_3_d.pm Text/NSP/Measures/3D/test_1_sub_3_d.pm_test
  435. /bin/mv -f Text/NSP/Measures/3D/test_2.pm Text/NSP/Measures/3D/test_2.pm_test