diff -r 2bc526c28a3f -r f60e0908f80b marking1/collatz_test.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking1/collatz_test.sh Mon Nov 27 01:15:36 2017 +0000 @@ -0,0 +1,121 @@ +#!/bin/bash + +# to make the script fail safely +set -euo pipefail + + +out=${1:-output} + +echo "" > $out + +echo "Below is the feedback and provisional marks for your submission" >> $out +echo "for assignment 6 Part 1 + 2. Please note all marks are provisional until" >> $out +echo "ratified by the assessment board -- this is not an official" >> $out +echo "results transcript." >> $out +echo "" >> $out + +echo "Below is the feedback for your submission for collatz.scala" >> $out +echo "" >> $out + +# marks for CW6 parts 1 + 2 +marks=$(( 0 )) + +# compilation tests + +function scala_compile { + (ulimit -t 30 -m 1024000 ; scala "$1" 2> /dev/null 1> /dev/null) +} + +# functional tests + +function scala_assert { + (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) +} + +# purity test + +function scala_vars { + (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) +} + + +# var, .par return, ListBuffer test +# +echo "collatz.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out + +if (scala_vars collatz.scala) +then + echo " --> fail" | tee -a $out + tsts0=$(( 1 )) +else + echo " --> success" | tee -a $out + tsts0=$(( 0 )) +fi + +### compilation test + + +if [ $tsts0 -eq 0 ] +then + echo "collatz.scala runs?" | tee -a $out + + if (scala_compile collatz.scala) + then + echo " --> success" | tee -a $out + tsts=$(( 0 )) + else + echo " --> scala did not run collatz.scala" | tee -a $out + tsts=$(( 1 )) + fi +else + tsts=$(( 1 )) +fi + +### collatz tests + +if [ $tsts -eq 0 ] +then + echo "collatz.scala tests:" | tee -a $out + echo " collatz(1) == 0,1 or 4" | tee -a $out + echo " collatz(6) == 9" | tee -a $out + echo " collatz(9) == 20" | tee -a $out + echo " collatz(9000) == 48" | tee -a $out + + if (scala_assert "collatz.scala" "collatz_test1.scala") + then + echo " --> success" | tee -a $out + marks=$(( marks + 2 )) + else + echo " --> one of the tests failed" | tee -a $out + fi +fi + +### collatz-max tests + +if [ $tsts -eq 0 ] +then + echo " collatz_max(10) == (20, 9)" | tee -a $out + echo " collatz_max(100) == (119, 97)" | tee -a $out + echo " collatz_max(1000) == (179, 871)" | tee -a $out + echo " collatz_max(10000) == (262, 6171)" | tee -a $out + echo " collatz_max(100000) == (351, 77031)" | tee -a $out + echo " collatz_max(1000000) == (525, 837799)" | tee -a $out + echo " collatz_max(2) == (2, 2)" | tee -a $out + echo " collatz_max(77000) == (340, 52527)" | tee -a $out + + if (scala_assert "collatz.scala" "collatz_test2.scala") + then + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) + else + echo " --> one of the tests failed" | tee -a $out + fi +fi + + + +## final marks +echo "Overall mark for Part 1" | tee -a $out +echo " $marks" | tee -a $out + +