main_marking4/knight2_test.sh
changeset 424 daf561a83ba6
parent 423 e9d14d58be3c
child 425 957808dcb367
equal deleted inserted replaced
423:e9d14d58be3c 424:daf561a83ba6
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo "" > $out
       
    10 
       
    11 echo -e `date` >> $out
       
    12 echo -e  "" >> $out
       
    13 echo "Below is the feedback and provisional marks for your submission" >> $out
       
    14 echo "for the Main Part 4 (Scala).  Please note all marks are provisional until" >> $out
       
    15 echo "ratified by the assessment board -- this is not an official" >> $out
       
    16 echo "results transcript." >> $out
       
    17 echo "" >> $out
       
    18 
       
    19 # marks for Main CW4
       
    20 marks=$(( 0 ))
       
    21 
       
    22 # compilation tests
       
    23 
       
    24 function scala_compile {
       
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    26 }
       
    27 
       
    28 # functional tests
       
    29 
       
    30 function scala_assert {
       
    31   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    32 }
       
    33 
       
    34 function scala_assert_thirty {
       
    35   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
       
    36 }
       
    37 
       
    38 # purity test
       
    39 
       
    40 function scala_vars {
       
    41    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    42 }
       
    43 
       
    44 echo -e "" >> $out
       
    45 echo -e  "Below is the feedback for your submission knight1.scala" >> $out
       
    46 echo -e  "" >> $out
       
    47 
       
    48 
       
    49 # compilation test
       
    50 
       
    51 echo -e "knight1.scala is present?" | tee -a $out
       
    52 
       
    53 if [ -f "knight1.scala" ]; then
       
    54     echo -e "  --> success" | tee -a $out
       
    55     tsts=$(( 0 ))
       
    56 else 
       
    57     echo -e "  --> knight1.scala is not present\n" | tee -a $out
       
    58     tsts=$(( 1 )) 
       
    59 fi
       
    60 
       
    61 
       
    62 
       
    63 
       
    64 if [ $tsts -eq 0 ]
       
    65 then
       
    66     echo -e "knight1.scala runs?" | tee -a $out
       
    67     
       
    68     if (scala_compile knight1.scala)
       
    69     then
       
    70 	echo -e "  --> success " | tee -a $out
       
    71 	tsts=$(( 0 ))
       
    72     else
       
    73 	echo -e "  --> SCALA DID NOT RUN knight1.scala\n" | tee -a $out
       
    74 	tsts=$(( 1 )) 
       
    75     fi
       
    76 else
       
    77     tsts=$(( 1 ))  
       
    78 fi 
       
    79 
       
    80 # knights1: purity test
       
    81 
       
    82 
       
    83 if [ $tsts -eq 0 ]
       
    84 then 
       
    85     echo -e "knight1.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    86 
       
    87     if (scala_vars knight1.scala)
       
    88     then
       
    89 	echo -e "  --> TEST FAILED\n" | tee -a $out
       
    90 	tsts=$(( 1 ))
       
    91     else
       
    92 	echo -e "  --> success" | tee -a $out
       
    93 	tsts=$(( 0 )) 
       
    94     fi
       
    95 else
       
    96     tsts=$(( 1 ))  
       
    97 fi    
       
    98 
       
    99 
       
   100 ### knight4 test
       
   101 
       
   102 if [ $tsts -eq 0 ]
       
   103 then
       
   104   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out
       
   105   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out
       
   106   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out  
       
   107   
       
   108   if (scala_assert "knight1.scala" "knight1_test4.scala") 
       
   109   then
       
   110       echo -e "  --> success" | tee -a $out
       
   111       marks=$(( marks + 1 ))
       
   112   else
       
   113       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   114   fi
       
   115 fi
       
   116 
       
   117 sleep 4
       
   118 
       
   119 ### knight5 test
       
   120 
       
   121 if [ $tsts -eq 0 ]
       
   122 then
       
   123   echo -e " is first_tour(6, List((0,0))) ok? " | tee -a $out
       
   124   echo -e " is first_tour(4, List((0,0))) == None " | tee -a $out
       
   125   START=$(date +%s)
       
   126   
       
   127   if (scala_assert_thirty "knight1.scala" "knight1_test5.scala") 
       
   128   then
       
   129       END=$(date +%s)
       
   130       DIFF=$(( $END - $START ))
       
   131       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
       
   132       echo -e "  --> success" | tee -a $out
       
   133       marks=$(( marks + 1 ))
       
   134   else
       
   135       END=$(date +%s)
       
   136       DIFF=$(( $END - $START ))
       
   137       echo -e "  This test ran for $DIFF seconds" | tee -a $out 
       
   138       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   139   fi
       
   140 fi
       
   141 
       
   142 
       
   143 echo -e "" >> $out
       
   144 echo -e  "Below is the feedback for your submission knight2.scala" >> $out
       
   145 echo -e  "" >> $out
       
   146 
       
   147 
       
   148 # knights2: compilation test
       
   149 
       
   150 echo "knight2.scala runs?" | tee -a $out
       
   151 
       
   152 if (scala_compile knight2.scala)
       
   153 then
       
   154     echo -e "  --> success" | tee -a $out
       
   155     tsts=$(( 0 ))
       
   156 else
       
   157     echo -e "  --> SCALA DID NOT RUN knight2.scala\n" | tee -a $out
       
   158     tsts=$(( 1 )) 
       
   159 fi
       
   160 
       
   161 
       
   162 
       
   163 # knights2: purity test
       
   164 #
       
   165 if [ $tsts -eq 0 ]
       
   166 then 
       
   167     echo "knight2.scala does not VARS, RETURNS etc?" | tee -a $out
       
   168 
       
   169     if (scala_vars knight2.scala)
       
   170     then   
       
   171 	echo -e "  --> TEST FAILED\n" | tee -a $out
       
   172 	tsts=$(( 1 ))
       
   173     else
       
   174 	echo -e "  --> success" | tee -a $out
       
   175 	tsts=$(( 0 )) 
       
   176     fi
       
   177 else
       
   178     tsts=$(( 1 ))  
       
   179 fi
       
   180 
       
   181 
       
   182 # ordered move test
       
   183 
       
   184 if [ $tsts -eq 0 ]
       
   185 then
       
   186   echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
       
   187   echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
       
   188   echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
       
   189   
       
   190   if (scala_assert "knight2.scala" "knight2_test6.scala")
       
   191   then
       
   192       echo -e "  --> success" | tee -a $out
       
   193       marks=$(( marks + 1 ))
       
   194   else
       
   195       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   196   fi
       
   197 fi
       
   198 
       
   199 sleep 4
       
   200 
       
   201 # first-closed-tour test
       
   202 
       
   203 if [ $tsts -eq 0 ]
       
   204 then
       
   205   echo -e " first_closed_tour_heuristics(6, List((3,3))) found and correct?" | tee -a $out
       
   206   START=$(date +%s)
       
   207   
       
   208   if (scala_assert_thirty "knight2.scala" "knight2_test7.scala")
       
   209   then
       
   210       END=$(date +%s)
       
   211       DIFF=$(( $END - $START ))
       
   212       echo -e "  This test ran for $DIFF seconds" | tee -a $out 
       
   213       echo -e "  --> success" | tee -a $out
       
   214       marks=$(( marks + 1 ))
       
   215   else
       
   216       END=$(date +%s)
       
   217       DIFF=$(( $END - $START ))
       
   218       echo -e "  This test ran for $DIFF seconds." | tee -a $out 
       
   219       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   220   fi
       
   221 fi
       
   222 
       
   223 sleep 4
       
   224 
       
   225 # first-tour test
       
   226 
       
   227 if [ $tsts -eq 0 ]
       
   228 then
       
   229   echo -e " first_tour_heuristics(8, List((0,0))) found and correct?" | tee -a $out
       
   230   echo -e " first_tour_heuristics(30, List((0,0))) found and correct?" | tee -a $out
       
   231   START=$(date +%s)
       
   232   
       
   233   if (scala_assert_thirty "knight2.scala" "knight2_test8.scala")
       
   234   then
       
   235       END=$(date +%s)
       
   236       DIFF=$(( $END - $START ))
       
   237       echo "  This test ran for $DIFF seconds" | tee -a $out
       
   238       echo -e "  --> success" | tee -a $out
       
   239       marks=$(( marks + 1 ))
       
   240   else
       
   241       END=$(date +%s)
       
   242       DIFF=$(( $END - $START ))
       
   243       echo "  This test ran for $DIFF seconds." | tee -a $out
       
   244       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   245   fi
       
   246 fi
       
   247 
       
   248 echo -e "" >> $out
       
   249 echo -e  "Below is the feedback for your submission knight3.scala" >> $out
       
   250 echo -e  "" >> $out
       
   251 
       
   252 # compilation test
       
   253 echo "knight3.scala runs?" | tee -a $out
       
   254 
       
   255 if (scala_compile knight3.scala)
       
   256 then
       
   257     echo "  --> success" | tee -a $out
       
   258     tsts=$(( 0 ))
       
   259 else
       
   260     echo -e "  --> SCALA DID NOT RUN knight3.scala\n" | tee -a $out  
       
   261     tsts=$(( 1 )) 
       
   262 fi
       
   263 
       
   264 
       
   265 # knights3: purity test
       
   266 #
       
   267 if [ $tsts -eq 0 ]
       
   268 then 
       
   269     echo -e "knight3.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
   270 
       
   271     if (scala_vars knight3.scala)
       
   272     then
       
   273 	echo "  --> TEST FAILED\n" | tee -a $out
       
   274 	tsts=$(( 1 ))
       
   275     else
       
   276 	echo "  --> success" | tee -a $out
       
   277 	tsts=$(( 0 )) 
       
   278     fi
       
   279 else
       
   280     tsts=$(( 1 ))  
       
   281 fi
       
   282 
       
   283 sleep 4
       
   284 
       
   285 if [ $tsts -eq 0 ]
       
   286 then
       
   287   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out
       
   288   START=$(date +%s)
       
   289   
       
   290   if (scala_assert_thirty "knight3.scala" "knight3_test9.scala")
       
   291   then
       
   292       END=$(date +%s)
       
   293       DIFF=$(( $END - $START ))
       
   294       echo -e "  This test ran for $DIFF seconds." | tee -a $out
       
   295       echo -e "  --> success" | tee -a $out
       
   296       marks=$(( marks + 1 ))
       
   297   else
       
   298       END=$(date +%s)
       
   299       DIFF=$(( $END - $START ))
       
   300       echo -e "  This test ran for $DIFF seconds." | tee -a $out
       
   301       echo -e "  --> TEST FAILED\n" | tee -a $out 
       
   302   fi
       
   303 fi
       
   304 
       
   305 sleep 4
       
   306 
       
   307 ## final marks
       
   308 echo -e "" >> $out
       
   309 echo -e "Overall mark for Main Part 4 (Scala)" | tee -a $out
       
   310 echo -e "$marks" | tee -a $out