P1Test.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #! /bin/bash
  2. # ecs60 Program 1
  3. # This script compares the example output with the output from your program.
  4. # It does not grade your programs.
  5. echo "Running your programs (sortedverification.sh, consistentresultverification.sh, timealgorithms.sh) on examples.."
  6. echo "Building test environment.."
  7. chmod u+x *.sh
  8. rm -rf testerDirectory
  9. mkdir -p testerDirectory
  10. mkdir -p testerDirectory/diff
  11. cd testerDirectory
  12. cp /home/rsgysel/public/60-Program1-Examples/* . &> /dev/null
  13. echo "..."
  14. cp ../* . &> /dev/null
  15. echo "...."
  16. numExamples=100
  17. totalTestsPassed=0
  18. # Sorted Verification
  19. testsPassed=0
  20. program=SortedVerification
  21. echo "Checking sortedverification.sh.."
  22. echo ${program} > Results.txt
  23. for i in {1..100}; do
  24. testFile=Example${i}
  25. ./sortedverification.sh ${testFile}.json > ${testFile}-${program}Submission.json
  26. diff -w ${testFile}-${program}Submission.json ${testFile}-${program}Solution.json > ./diff/${testFile}-${program}Diff.txt
  27. diffFile=./diff/${testFile}-${program}Diff.txt
  28. if [ ! -s $diffFile ]; then
  29. echo ${testFile}.json: Pass >> Results.txt
  30. testsPassed=$((testsPassed+1))
  31. else
  32. echo ${testFile}.json: Fail. See $diffFile >> Results.txt
  33. fi
  34. done
  35. echo ./sortedverification.sh ${testsPassed} tests passed of $numExamples total tests
  36. echo
  37. echo >> Results.txt
  38. totalTestsPassed=$(($totalTestsPassed + $testsPassed))
  39. # Consistent Result Verificaiton
  40. testsPassed=0;
  41. program=ConsistentResultVerification
  42. echo "Checking ./consistentresultverification.sh.."
  43. echo ${program} >> Results.txt
  44. for i in {1..99}; do
  45. testFile1=Example${i}
  46. j=$((i+1))
  47. testFile2=Example${j}
  48. testFile=${testFile1}-${testFile2}
  49. ./consistentresultverification.sh ${testFile1}.json ${testFile2}.json > ${testFile}-${program}Submission.json
  50. diff -w ${testFile}-${program}Submission.json ${testFile}-${program}Solution.json > ./diff/${testFile}-${program}Diff.txt
  51. diffFile=./diff/${testFile}-${program}Diff.txt
  52. if [ ! -s $diffFile ]; then
  53. echo ${testFile1}.json ${testFile2}.json: Pass >> Results.txt
  54. testsPassed=$((testsPassed+1))
  55. else
  56. echo ${testFile1}.json ${testFile2}.json: Fail. See $diffFile >> Results.txt
  57. fi
  58. done
  59. echo ./consistentresultverification.sh ${testsPassed} tests passed of 99 total tests
  60. echo
  61. echo >> Results.txt
  62. totalTestsPassed=$(($totalTestsPassed + $testsPassed))
  63. # Time Algorithms
  64. testsPassed=0;
  65. program=TimedAlgorithms
  66. echo "Checking ./timealgorithms.sh.. (Timing columns are ignored during comparison and are 0's in the Solution files, your time values should not be 0)"
  67. echo ${program} >> Results.txt
  68. for i in {1..100}; do
  69. testFile=Example${i}
  70. ./timealgorithms.sh ${testFile}.json > ${testFile}-${program}Submission.csv
  71. # cut timing fields
  72. cut --complement -f 2,5,8 -d, ${testFile}-${program}Submission.csv > temp.csv
  73. mv temp.csv ${testFile}-${program}Submission.csv
  74. cut --complement -f 2,5,8 -d, ${testFile}-${program}Solution.csv > temp.csv
  75. mv temp.csv ${testFile}-${program}Solution.csv
  76. #head -n1 ${testFile}-${program}Submission.csv > temp.csv
  77. # pipe into wc so only #lines printed
  78. #k=$(cat ${testFile}-${program}Submission.csv | wc -l)
  79. #k=$((k-1))
  80. #tail -n$k ${testFile}-${program}Submission.csv | cut --complement -f 2,5,8 -d, >> temp.csv
  81. #mv temp.csv ${testFile}-${program}Submission.csv
  82. #head -n1 ${testFile}-${program}Solution.csv > temp.csv
  83. #k=$(cat ${testFile}-${program}Solution.csv | wc -l)
  84. #k=$((k-1))
  85. #tail -n$k ${testFile}-${program}Solution.csv | cut --complement -f 2,5,8 -d, >> temp.csv
  86. #mv temp.csv ${testFile}-${program}Solution.csv
  87. #diff -w ${testFile}-${program}Submission.csv ${testFile}-${program}Solution.csv > ./diff/${testFile}-${program}Diff.txt
  88. diffFile=./diff/${testFile}-${program}Diff.txt
  89. if [ ! -s $diffFile ]; then
  90. echo ${testFile}.json: Pass >> Results.txt
  91. testsPassed=$((testsPassed+1))
  92. else
  93. echo ${testFile}.json: Fail. See $diffFile >> Results.txt
  94. fi
  95. done
  96. echo ./timealgorithms.sh ${testsPassed} tests passed of $numExamples total tests
  97. echo
  98. totalTestsPassed=$(($totalTestsPassed + $testsPassed))
  99. # Cleanup
  100. cp Results.txt ../
  101. cp -r diff ../
  102. cd ..
  103. rm -rf testerDirectory
  104. echo "Testing finished, you passed $totalTestsPassed out of $((3*$numExamples)) total tests. See Results.txt for details. Be sure to include your compile.sh in your submission, which was not tested by this script."