cw2_marking/cw2_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 2 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 cw02.sc" >> $out
       
    19 echo "" >> $out
       
    20 
       
    21 # marks for CW 2
       
    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   #rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 2> /dev/null ;  
       
    39   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1") # 1>> $out 2>> $out)
       
    40 }
       
    41 
       
    42 
       
    43 
       
    44 ### compilation test
       
    45 
       
    46 echo -e "0) cw02.sc compiles?\n" | tee -a $out
       
    47 
       
    48 if (scala_compile "c.sc")
       
    49 then
       
    50     echo -e "   --> yes cw02.sc compiles\n" | tee -a $out
       
    51     tsts=$(( 0 ))
       
    52 else
       
    53     echo -e "   --> AMM DID NOT compile cw02.sc\n" | tee -a $out
       
    54     cat c$out | tee -a $out
       
    55     echo -e "\n\n" >> $out
       
    56     tsts=$(( 1 ))
       
    57 fi
       
    58 
       
    59 echo >> $out
       
    60 
       
    61 ### "read n;" test
       
    62 echo >> $out
       
    63 #echo -e "\n\n\n" >> $out
       
    64 
       
    65 if [ $tsts -eq 0 ]
       
    66 then
       
    67     echo -e "1) Tokenise string from Question 2:\n" | tee -a $out
       
    68     echo -e "   tokenise(\"read n;\") == List(T_KEYWORD(read), T_ID(n), T_SEMI) ?\n" | tee -a $out
       
    69     if (scala_assert "c1.sc")
       
    70     then
       
    71 	echo -e "   --> success (+ 3.0 Marks)\n" | tee -a $out
       
    72 	marks=$(( marks + 3.0 ))
       
    73     else
       
    74 	echo -e "   --> FAILED\n" | tee -a $out
       
    75 	echo -e "       instead it generates:\n" | tee -a $out
       
    76 	(scala_fail "c1a.sc" || true) | tee -a $out
       
    77 	echo -e "\n\n" >> $out
       
    78     fi
       
    79 fi
       
    80 
       
    81 ### tokenise test
       
    82 echo >> $out
       
    83 #echo -e "\n\n\n" >> $out
       
    84 
       
    85 if [ $tsts -eq 0 ]
       
    86 then
       
    87   echo -e "2) Tokenise test with example files (does it raise an exception):\n" | tee -a $out
       
    88   cat cw02.sc c3_add.sc > cw023_add.sc  
       
    89   if (scala_assert "c3.sc")
       
    90   then
       
    91       echo -e "   --> success (+ 3.0 Marks)\n" | tee -a $out
       
    92       marks=$(( marks + 3.0 ))
       
    93   else
       
    94       echo -e "   --> FAILED\n" | tee -a $out
       
    95       #cat $out | tee -a $out
       
    96   fi
       
    97 fi
       
    98 
       
    99 ### tokenise test for collatz2.while
       
   100 echo >> $out
       
   101 #echo -e "\n\n\n" >> $out
       
   102 
       
   103 if [ $tsts -eq 0 ]
       
   104 then
       
   105   echo -e "3) Check tokens for collatz2.while:\n" | tee -a $out
       
   106   cat cw02.sc c4_add.sc > cw024_add.sc  
       
   107   if (scala_assert "c4.sc")
       
   108   then
       
   109       echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
       
   110       marks=$(( marks + 2.0 ))
       
   111   else
       
   112       echo -e "   --> FAILED\n" | tee -a $out
       
   113       #cat $out | tee -a $out
       
   114   fi
       
   115 fi
       
   116 
       
   117 ### are constructors primitive
       
   118 echo >> $out
       
   119 #echo -e "\n\n\n" >> $out
       
   120 
       
   121 if [ $tsts -eq 0 ]
       
   122 then
       
   123     echo -e "4) Are regex constructors all primitive?\n" | tee -a $out
       
   124     echo -e "   For example, RANGE.toString == \"RANGE\"\n" | tee -a $out
       
   125     if (scala_assert "c5.sc")
       
   126     then
       
   127 	echo -e "   --> FAILED\n" | tee -a $out
       
   128 	tail -25 $out | pr -to10
       
   129 	echo -e "\n\n" >> $out
       
   130     else
       
   131 	echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
       
   132 	marks=$(( marks + 2.0 ))
       
   133     fi
       
   134 fi
       
   135 
       
   136 
       
   137 ## final marks
       
   138 echo >> $out
       
   139 echo "Overall mark for CW 2" | tee -a $out
       
   140 printf " %0.2f\n" $marks | tee -a $out
       
   141 
       
   142 
       
   143