P2Test.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /bin/bash
  2. # ecs60 Program 2
  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 (buildheap.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 ../* . &> /dev/null
  13. rm *.json -f
  14. echo "..."
  15. cp ~rsgysel/60-Program2-Examples/* . &> /dev/null
  16. echo "...."
  17. numExamples=100
  18. totalTestsPassed=0
  19. # buildheap
  20. testsPassed=0;
  21. numExamples=0
  22. program=buildheap
  23. echo "Checking ./buildheap.sh"
  24. echo ${program} > Results.txt
  25. for file in *.json; do
  26. numExamples=$((numExamples + 1))
  27. testFile=$(basename ${file} .json)
  28. ./buildheap.sh ${testFile}.json > ${testFile}studentheapoutput.json
  29. if [ -s ${testFile}studentheapoutput.json ]; then
  30. diff -w ${testFile}studentheapoutput.json ${testFile}.buildheapoutput > ./diff/${testFile}Diff.txt
  31. diffFile=./diff/${testFile}Diff.txt
  32. if [ ! -s $diffFile ]; then
  33. if [ -f $diffFile ]; then
  34. echo ${testFile}studentheapoutput.json: Pass >> Results.txt
  35. testsPassed=$((testsPassed+1))
  36. else
  37. echo $diffFile not found!
  38. fi
  39. else
  40. echo ${testFile}studentheapoutput.json: Fail. See $diffFile >> Results.txt
  41. fi
  42. else
  43. echo ${testFile}.json: Fail, no output from your program >> Results.txt
  44. fi
  45. done
  46. echo ./buildheap.sh ${testsPassed} tests passed of ${numExamples} total tests
  47. echo
  48. echo >> Results.txt
  49. totalTestsPassed=$(($totalTestsPassed + $testsPassed))
  50. # Cleanup
  51. echo Cleaning up...
  52. cp Results.txt ../
  53. cp -r diff ../
  54. cd ..
  55. rm -rf testerDirectory
  56. echo "Testing finished, you passed $totalTestsPassed out of $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."