| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      1 | #!/bin/zsh
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      2 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      3 | # to make the script fail safely
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      4 | set -euo pipefail
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      5 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      6 | out=${1:-output}
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      7 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      8 | echo "" > $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |      9 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     10 | echo `date` >> $out
 | 
| 387 |     11 | echo -e "" >> $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     12 | echo -e "Below is the feedback and provisional marks for your submission" >> $out
 | 
| 421 |     13 | echo -e "of the Main Part 4 (Scala).  Please note all marks are provisional until" >> $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     14 | echo -e "ratified by the assessment board -- this is not an official" >> $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     15 | echo -e "results transcript." >> $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     16 | echo -e "" >> $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     17 | 
 | 
| 387 |     18 | echo -e "" >> $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     19 | echo -e "Below is the feedback for your submission knight1.scala" >> $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     20 | echo -e "" >> $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     21 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     22 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     23 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     24 | # marks for CW8 part 1
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     25 | marks=$(( 0.0 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     26 | 
 | 
| 387 |     27 | # compilation tests
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     28 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     29 | function scala_compile {
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     30 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     31 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     32 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     33 | # functional tests
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     34 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     35 | function scala_assert {
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     36 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     37 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     38 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     39 | function scala_assert_slow {
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     40 |   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     41 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     42 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     43 | function scala_assert_thirty {
 | 
| 460 |     44 |   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     45 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     46 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     47 | function scala_assert_quick {
 | 
| 460 |     48 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)    
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     49 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     50 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     51 | function scala_assert_long {
 | 
| 460 |     52 |   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)    
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     53 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     54 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     55 | function scala_assert_elong {
 | 
| 460 |     56 |   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     57 | }
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     58 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     59 | # purity test
 | 
| 421 |     60 | function scala_vars {
 | 
|  |     61 |    (sed 's/immutable/ok/g' c$out > cb$out;
 | 
|  |     62 |     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
 | 
|  |     63 | }
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     64 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     65 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     66 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     67 | # compilation test
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     68 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     69 | echo -e "knight1.scala runs?" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     70 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     71 | if (scala_compile knight1.scala)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     72 | then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     73 |     echo -e "  --> success " | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     74 |     tsts=$(( 0 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     75 | else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     76 |     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     77 |     tsts=$(( 1 )) 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     78 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     79 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     80 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     81 | # knights1: purity test
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     82 | if  [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     83 |   then   
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     84 |   echo -e "knight1.scala does not contain VARS, RETURNS etc?" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     85 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     86 |   if (scala_vars knight1.scala)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     87 |   then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     88 |      echo -e "  --> FAIL\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     89 |      tsts=$(( 1 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     90 |   else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     91 |      echo -e "  --> success" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     92 |      tsts=$(( 0 )) 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     93 |   fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     94 | else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     95 |   tsts=$(( 1 ))  
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     96 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     97 | 
 | 
| 387 |     98 | echo >> $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |     99 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    100 | ### knight1 test
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    101 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    102 | if [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    103 | then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    104 |     echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    105 |     echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    106 |     echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out                          
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    107 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    108 |     if (scala_assert "knight1.scala" "knight1_test1.scala")
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    109 |     then
 | 
| 460 |    110 |         echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    111 | 	marks=$(( marks + 1.0 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    112 |     else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    113 |         echo -e "  --> \n ONE TEST FAILED\n"| tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    114 |     fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    115 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    116 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    117 | ### knight2 test
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    118 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    119 | if [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    120 | then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    121 |   echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    122 |   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    123 |   echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    124 |   echo " legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    125 |   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    126 |   echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    127 |   echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    128 |   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    129 |   
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    130 |   if (scala_assert "knight1.scala" "knight1_test2.scala")
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    131 |   then
 | 
| 460 |    132 |      echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    133 |      marks=$(( marks + 1 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    134 |   else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    135 |      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    136 |   fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    137 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    138 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    139 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    140 | ### knight3 test
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    141 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    142 | if [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    143 | then
 | 
| 460 |    144 |   echo " count_tours from every position on the board 1 - 4" | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    145 |   echo " dim = 1: 1" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    146 |   echo "       2: 0,0,0,0" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    147 |   echo "       3: 0,0,0,0,0,0,0,0,0" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    148 |   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    149 |   START=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    150 |   
 | 
| 460 |    151 |   if (scala_assert "knight1.scala" "knight1_test3a.scala") 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    152 |   then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    153 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    154 |      DIFF=$(( $END - $START ))
 | 
| 387 |    155 |      #echo " This test ran for $DIFF seconds." | tee -a $out  
 | 
| 460 |    156 |      echo -e "  --> success (+ 0.5 Marks)\n" | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    157 |      marks=$(( marks + 0.5 ))
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    158 |   else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    159 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    160 |      DIFF=$(( $END - $START ))
 | 
| 387 |    161 |      echo " This test ran for $DIFF seconds." | tee -a $out 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    162 |      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    163 |   fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    164 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    165 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    166 | 
 | 
| 387 |    167 | 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    168 | if [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    169 | then
 | 
| 460 |    170 |   echo " count_tours from every position on the board of dim 5 for the first 3 rows" | tee -a $out
 | 
| 387 |    171 |   echo " dim = 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56)" | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    172 |   START=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    173 |   
 | 
| 460 |    174 |   if (scala_assert "knight1.scala" "knight1_test3b.scala") 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    175 |   then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    176 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    177 |      DIFF=$(( $END - $START ))
 | 
| 387 |    178 |      #echo " This test ran for $DIFF seconds." | tee -a $out  
 | 
| 460 |    179 |      echo -e "  --> success (+ 0.25 Marks)\\n" | tee -a $out
 | 
| 421 |    180 |      marks=$(( marks + 0.25 ))
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    181 |   else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    182 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    183 |      DIFF=$(( $END - $START ))
 | 
| 387 |    184 |      echo " This test ran for $DIFF seconds." | tee -a $out 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    185 |      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    186 |   fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    187 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    188 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    189 | 
 | 
| 387 |    190 | 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    191 | if [ $tsts -eq 0 ]
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    192 | then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    193 |   echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    194 |   echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out
 | 
| 460 |    195 |   #echo " (0.25% marks) " | tee -a $out
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    196 |   START=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    197 |   
 | 
| 387 |    198 |   if (scala_assert_thirty "knight1.scala" "knight1_test3c.scala") 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    199 |   then
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    200 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    201 |      DIFF=$(( $END - $START ))
 | 
| 387 |    202 |      #echo " This test ran for $DIFF seconds." | tee -a $out 
 | 
| 460 |    203 |      echo -e "  --> success (+ 0.25 Marks)\n" | tee -a $out
 | 
| 421 |    204 |      marks=$(( marks + 0.25 ))
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    205 |   else
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    206 |      END=$(date +%s)
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    207 |      DIFF=$(( $END - $START ))
 | 
| 387 |    208 |      echo " This test ran for $DIFF seconds." | tee -a $out 
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    209 |      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    210 |   fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    211 | fi
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    212 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    213 | 
 | 
| 421 |    214 | ### knight4 test
 | 
|  |    215 | 
 | 
|  |    216 | if [ $tsts -eq 0 ]
 | 
|  |    217 | then
 | 
|  |    218 |   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out
 | 
|  |    219 |   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out
 | 
|  |    220 |   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out  
 | 
|  |    221 |   
 | 
|  |    222 |   if (scala_assert "knight1.scala" "knight1_test4.scala") 
 | 
|  |    223 |   then
 | 
| 460 |    224 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    225 |       marks=$(( marks + 1.0 ))
 | 
|  |    226 |   else
 | 
|  |    227 |       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    228 |   fi
 | 
|  |    229 | fi
 | 
|  |    230 | 
 | 
|  |    231 | ### knight5 test
 | 
|  |    232 | 
 | 
|  |    233 | if [ $tsts -eq 0 ]
 | 
|  |    234 | then
 | 
|  |    235 |   echo -e " is first_tour(6, List((0,0))) ok? " | tee -a $out
 | 
|  |    236 |   echo -e " is first_tour(4, List((0,0))) == None " | tee -a $out
 | 
|  |    237 |   START=$(date +%s)
 | 
|  |    238 |   
 | 
|  |    239 |   if (scala_assert_thirty "knight1.scala" "knight1_test5.scala") 
 | 
|  |    240 |   then
 | 
|  |    241 |       END=$(date +%s)
 | 
|  |    242 |       DIFF=$(( $END - $START ))
 | 
| 460 |    243 |       #echo -e "  This test ran for $DIFF seconds" | tee -a $out  
 | 
|  |    244 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    245 |       marks=$(( marks + 1.0 ))
 | 
|  |    246 |   else
 | 
|  |    247 |       END=$(date +%s)
 | 
|  |    248 |       DIFF=$(( $END - $START ))
 | 
|  |    249 |       echo -e "  This test ran for $DIFF seconds" | tee -a $out 
 | 
|  |    250 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
|  |    251 |   fi
 | 
|  |    252 | fi
 | 
|  |    253 | 
 | 
|  |    254 | echo -e "" >> $out
 | 
|  |    255 | echo -e  "Below is the feedback for your submission knight2.scala" >> $out
 | 
|  |    256 | echo -e  "" >> $out
 | 
|  |    257 | 
 | 
|  |    258 | 
 | 
|  |    259 | # knights2: compilation test
 | 
|  |    260 | 
 | 
|  |    261 | echo "knight2.scala runs?" | tee -a $out
 | 
|  |    262 | 
 | 
|  |    263 | if (scala_compile knight2.scala)
 | 
|  |    264 | then
 | 
|  |    265 |     echo -e "  --> success" | tee -a $out
 | 
|  |    266 |     tsts=$(( 0 ))
 | 
|  |    267 | else
 | 
|  |    268 |     echo -e "  --> SCALA DID NOT RUN knight2.scala\n" | tee -a $out
 | 
|  |    269 |     tsts=$(( 1 )) 
 | 
|  |    270 | fi
 | 
| 386 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    271 | 
 | 
| 
Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset |    272 | 
 | 
| 387 |    273 | 
 | 
| 421 |    274 | # knights2: purity test
 | 
|  |    275 | #
 | 
|  |    276 | if [ $tsts -eq 0 ]
 | 
|  |    277 | then 
 | 
|  |    278 |     echo "knight2.scala does not VARS, RETURNS etc?" | tee -a $out
 | 
|  |    279 | 
 | 
|  |    280 |     if (scala_vars knight2.scala)
 | 
|  |    281 |     then   
 | 
|  |    282 | 	echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
|  |    283 | 	tsts=$(( 1 ))
 | 
|  |    284 |     else
 | 
|  |    285 | 	echo -e "  --> success" | tee -a $out
 | 
|  |    286 | 	tsts=$(( 0 )) 
 | 
|  |    287 |     fi
 | 
|  |    288 | else
 | 
|  |    289 |     tsts=$(( 1 ))  
 | 
|  |    290 | fi
 | 
|  |    291 | 
 | 
|  |    292 | 
 | 
|  |    293 | # ordered move test
 | 
|  |    294 | 
 | 
|  |    295 | if [ $tsts -eq 0 ]
 | 
|  |    296 | then
 | 
|  |    297 |   echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
 | 
|  |    298 |   echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
 | 
|  |    299 |   echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
 | 
|  |    300 |   
 | 
|  |    301 |   if (scala_assert "knight2.scala" "knight2_test6.scala")
 | 
|  |    302 |   then
 | 
| 460 |    303 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    304 |       marks=$(( marks + 1.0 ))
 | 
|  |    305 |   else
 | 
|  |    306 |       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    307 |   fi
 | 
|  |    308 | fi
 | 
|  |    309 | 
 | 
|  |    310 | 
 | 
|  |    311 | # first-closed-tour test
 | 
|  |    312 | 
 | 
|  |    313 | if [ $tsts -eq 0 ]
 | 
|  |    314 | then
 | 
|  |    315 |   echo -e " first_closed_tour_heuristics(6, List((3,3))) found and correct?" | tee -a $out
 | 
|  |    316 |   START=$(date +%s)
 | 
|  |    317 |   
 | 
|  |    318 |   if (scala_assert_thirty "knight2.scala" "knight2_test7.scala")
 | 
|  |    319 |   then
 | 
|  |    320 |       END=$(date +%s)
 | 
|  |    321 |       DIFF=$(( $END - $START ))
 | 
| 460 |    322 |       #echo -e "  This test ran for $DIFF seconds" | tee -a $out 
 | 
|  |    323 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    324 |       marks=$(( marks + 1.0 ))
 | 
|  |    325 |   else
 | 
|  |    326 |       END=$(date +%s)
 | 
|  |    327 |       DIFF=$(( $END - $START ))
 | 
|  |    328 |       echo -e "  This test ran for $DIFF seconds." | tee -a $out 
 | 
|  |    329 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
|  |    330 |   fi
 | 
|  |    331 | fi
 | 
|  |    332 | 
 | 
|  |    333 | 
 | 
|  |    334 | # first-tour test
 | 
|  |    335 | 
 | 
|  |    336 | if [ $tsts -eq 0 ]
 | 
|  |    337 | then
 | 
|  |    338 |   echo -e " first_tour_heuristics(8, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    339 |   echo -e " first_tour_heuristics(30, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    340 |   START=$(date +%s)
 | 
|  |    341 |   
 | 
|  |    342 |   if (scala_assert_thirty "knight2.scala" "knight2_test8.scala")
 | 
|  |    343 |   then
 | 
|  |    344 |       END=$(date +%s)
 | 
|  |    345 |       DIFF=$(( $END - $START ))
 | 
| 460 |    346 |       #echo "  This test ran for $DIFF seconds" | tee -a $out
 | 
|  |    347 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    348 |       marks=$(( marks + 1.0 ))
 | 
|  |    349 |   else
 | 
|  |    350 |       END=$(date +%s)
 | 
|  |    351 |       DIFF=$(( $END - $START ))
 | 
|  |    352 |       echo "  This test ran for $DIFF seconds." | tee -a $out
 | 
|  |    353 |       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    354 |   fi
 | 
|  |    355 | fi
 | 
|  |    356 | 
 | 
|  |    357 | echo -e "" >> $out
 | 
|  |    358 | echo -e  "Below is the feedback for your submission knight3.scala" >> $out
 | 
|  |    359 | echo -e  "" >> $out
 | 
|  |    360 | 
 | 
|  |    361 | # compilation test
 | 
|  |    362 | echo "knight3.scala runs?" | tee -a $out
 | 
|  |    363 | 
 | 
|  |    364 | if (scala_compile knight3.scala)
 | 
|  |    365 | then
 | 
|  |    366 |     echo "  --> success" | tee -a $out
 | 
|  |    367 |     tsts=$(( 0 ))
 | 
|  |    368 | else
 | 
|  |    369 |     echo -e "  --> SCALA DID NOT RUN knight3.scala\n" | tee -a $out  
 | 
|  |    370 |     tsts=$(( 1 )) 
 | 
|  |    371 | fi
 | 
|  |    372 | 
 | 
|  |    373 | 
 | 
|  |    374 | # knights3: purity test
 | 
|  |    375 | #
 | 
|  |    376 | if [ $tsts -eq 0 ]
 | 
|  |    377 | then 
 | 
|  |    378 |     echo -e "knight3.scala does not contain VARS, RETURNS etc?" | tee -a $out
 | 
|  |    379 | 
 | 
|  |    380 |     if (scala_vars knight3.scala)
 | 
|  |    381 |     then
 | 
|  |    382 | 	echo "  --> TEST FAILED\n" | tee -a $out
 | 
|  |    383 | 	tsts=$(( 1 ))
 | 
|  |    384 |     else
 | 
|  |    385 | 	echo "  --> success" | tee -a $out
 | 
|  |    386 | 	tsts=$(( 0 )) 
 | 
|  |    387 |     fi
 | 
|  |    388 | else
 | 
|  |    389 |     tsts=$(( 1 ))  
 | 
|  |    390 | fi
 | 
|  |    391 | 
 | 
|  |    392 | 
 | 
|  |    393 | if [ $tsts -eq 0 ]
 | 
|  |    394 | then
 | 
|  |    395 |   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    396 |   START=$(date +%s)
 | 
|  |    397 |   
 | 
|  |    398 |   if (scala_assert_thirty "knight3.scala" "knight3_test9.scala")
 | 
|  |    399 |   then
 | 
|  |    400 |       END=$(date +%s)
 | 
|  |    401 |       DIFF=$(( $END - $START ))
 | 
| 460 |    402 |       #echo -e "  This test ran for $DIFF seconds." | tee -a $out
 | 
|  |    403 |       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
 | 
| 421 |    404 |       marks=$(( marks + 1.0 ))
 | 
|  |    405 |   else
 | 
|  |    406 |       END=$(date +%s)
 | 
|  |    407 |       DIFF=$(( $END - $START ))
 | 
|  |    408 |       echo -e "  This test ran for $DIFF seconds." | tee -a $out
 | 
|  |    409 |       echo -e "  --> TEST FAILED\n" | tee -a $out 
 | 
|  |    410 |   fi
 | 
|  |    411 | fi
 | 
|  |    412 | 
 | 
|  |    413 | 
 | 
| 460 |    414 | echo -e "" >> $out
 | 
|  |    415 | echo -e  "Below is the feedback for your submission knight4.scala" >> $out
 | 
|  |    416 | echo -e  "" >> $out
 | 
|  |    417 | 
 | 
|  |    418 | # compilation test
 | 
|  |    419 | echo "knight4.scala runs?" | tee -a $out
 | 
|  |    420 | 
 | 
|  |    421 | if (scala_compile knight4.scala)
 | 
|  |    422 | then
 | 
|  |    423 |     echo "  --> success" | tee -a $out
 | 
|  |    424 |     tsts=$(( 0 ))
 | 
|  |    425 | else
 | 
|  |    426 |     echo -e "  --> SCALA DID NOT RUN knight3.scala\n" | tee -a $out  
 | 
|  |    427 |     tsts=$(( 1 )) 
 | 
|  |    428 | fi
 | 
|  |    429 | 
 | 
|  |    430 | 
 | 
|  |    431 | # knights3: purity test
 | 
|  |    432 | #
 | 
|  |    433 | if [ $tsts -eq 0 ]
 | 
|  |    434 | then 
 | 
|  |    435 |     echo -e "knight4.scala does not contain VARS, RETURNS etc?" | tee -a $out
 | 
|  |    436 | 
 | 
|  |    437 |     if (scala_vars knight4.scala)
 | 
|  |    438 |     then
 | 
|  |    439 | 	echo "  --> TEST FAILED\n" | tee -a $out
 | 
|  |    440 | 	tsts=$(( 1 ))
 | 
|  |    441 |     else
 | 
|  |    442 | 	echo "  --> success" | tee -a $out
 | 
|  |    443 | 	tsts=$(( 0 )) 
 | 
|  |    444 |     fi
 | 
|  |    445 | else
 | 
|  |    446 |     tsts=$(( 1 ))  
 | 
|  |    447 | fi
 | 
|  |    448 | 
 | 
|  |    449 | if [ $tsts -eq 0 ]
 | 
|  |    450 | then
 | 
|  |    451 |   echo -e " one_tour_pred(8, List((0, 0)), 40, x => x._1 < 5) is ok?" | tee -a $out
 | 
|  |    452 |   START=$(date +%s)
 | 
|  |    453 | 
 | 
|  |    454 |   if (scala_assert "knight4.scala" "knight4_test10.scala")
 | 
|  |    455 |   then
 | 
|  |    456 |       END=$(date +%s)
 | 
|  |    457 |       DIFF=$(( $END - $START ))
 | 
|  |    458 |       #echo -e "  This test ran for $DIFF seconds." | tee -a $out
 | 
|  |    459 |       echo -e "  --> success (+ 2 Marks)\n" | tee -a $out
 | 
|  |    460 |       marks=$(( marks + 2.0 ))
 | 
|  |    461 |   else
 | 
|  |    462 |       END=$(date +%s)
 | 
|  |    463 |       DIFF=$(( $END - $START ))
 | 
|  |    464 |       echo -e "  This test ran for $DIFF seconds." | tee -a $out
 | 
|  |    465 |       echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
 | 
|  |    466 |   fi
 | 
|  |    467 | fi
 | 
|  |    468 | 
 | 
|  |    469 | 
 | 
| 421 |    470 | ## final marks
 | 
|  |    471 | echo -e "" >> $out
 | 
|  |    472 | echo -e "Overall mark for Main Part 4 (Scala)" | tee -a $out
 | 
|  |    473 | printf " %0.2f\n" $marks | tee -a $out
 | 
|  |    474 | 
 | 
|  |    475 | 
 |