cw3_marking/cw3_test.sh
changeset 978 8778d23fef92
equal deleted inserted replaced
977:1e6eca42d90b 978:8778d23fef92
       
     1 #!/bin/zsh
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo -e "" > $out
       
    10 
       
    11 echo `date` | tee -a $out
       
    12 echo "" >> $out
       
    13 echo "Below is the feedback and provisional marks for your CW 3 submission." >> $out
       
    14 echo "Please note all marks are provisional until ratified by the" >> $out
       
    15 echo "assessment board -- this is not an official results transcript." >> $out
       
    16 echo "" >> $out
       
    17 
       
    18 echo "The feedback for your submission for cw03.sc" >> $out
       
    19 echo "" >> $out
       
    20 
       
    21 # marks for CW 3
       
    22 marks=$(( 0.0 ))
       
    23 
       
    24 # compilation tests
       
    25 
       
    26 function scala_compile {
       
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" amm -s "$1" 2> c$out 1> c$out)
       
    28 }
       
    29 
       
    30 # functional tests
       
    31 
       
    32 function scala_assert {
       
    33   rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 2> /dev/null ;    
       
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out)
       
    35 }
       
    36 
       
    37 function scala_fail {
       
    38   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out)
       
    39 }
       
    40 
       
    41 
       
    42 
       
    43 ### compilation test
       
    44 
       
    45 echo -e "0) cw03.sc compiles?\n" | tee -a $out
       
    46 
       
    47 if (scala_compile "c.sc")
       
    48 then
       
    49     echo -e "    --> yes cw03.sc compiles\n" | tee -a $out
       
    50     tsts=$(( 0 ))
       
    51 else
       
    52     echo -e "    --> AMM DID NOT compile cw03.sc\n" | tee -a $out
       
    53     cat c$out | tee -a $out
       
    54     echo -e "\n\n" >> $out
       
    55     tsts=$(( 1 ))
       
    56 fi
       
    57 
       
    58 ### parsing test
       
    59 echo >> $out
       
    60 #echo -e "\n\n\n" >> $out
       
    61 
       
    62 if [ $tsts -eq 0 ]
       
    63 then
       
    64   echo -e "1) Parsing test with example files (does it raise an exception):\n" | tee -a $out
       
    65   cat cw03.sc c3_add.sc > cw033_add.sc  
       
    66   if (scala_assert "c3.sc")
       
    67   then
       
    68       echo -e "   --> success (+ 6.0 Marks)\n" | tee -a $out
       
    69       marks=$(( marks + 6.0 ))
       
    70   else
       
    71       echo -e "   --> FAILED\n" | tee -a $out
       
    72       #cat $out | tee -a $out
       
    73   fi
       
    74 fi
       
    75 
       
    76 ### eval test
       
    77 echo >> $out
       
    78 #echo -e "\n\n\n" >> $out
       
    79 
       
    80 if [ $tsts -eq 0 ]
       
    81 then
       
    82   echo -e "2) Evaluation of primes.while:\n" | tee -a $out
       
    83   cat c4_pre.sc cw03.sc c4_add.sc > cw034_add.sc  
       
    84   if (scala_assert "c4.sc")
       
    85   then
       
    86       echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
       
    87       marks=$(( marks + 2.0 ))
       
    88   else
       
    89       echo -e "   --> FAILED\n" | tee -a $out
       
    90       #cat $out | tee -a $out
       
    91   fi
       
    92 fi
       
    93 
       
    94 ### print test
       
    95 echo >> $out
       
    96 #echo -e "\n\n\n" >> $out
       
    97 
       
    98 if [ $tsts -eq 0 ]
       
    99 then
       
   100     echo -e "3) Testing of what is printed with the program:\n" | tee -a $out
       
   101     echo -e "\"\"\"" >> $out
       
   102     cat "test.while" >> $out
       
   103     echo -e "\"\"\"\n" >> $out
       
   104     if (scala_assert "c5.sc")
       
   105     then
       
   106 	echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
       
   107 	marks=$(( marks + 2.0 ))
       
   108     else
       
   109 	echo -e "   --> FAILED\n" | tee -a $out
       
   110 	tail -25 $out | pr -to10
       
   111     fi
       
   112 fi
       
   113 
       
   114 
       
   115 ## final marks
       
   116 echo >> $out
       
   117 echo "Overall mark for CW 3" | tee -a $out
       
   118 printf " %0.2f\n" $marks | tee -a $out
       
   119 
       
   120 
       
   121