| 243 |      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 "Below is the feedback and provisional marks for your submission" >> $out
 | 
| 258 |     12 | echo "for assignment 8 Advanced Part 2.  Please note all marks are provisional until" >> $out
 | 
| 243 |     13 | echo "ratified by the assessment board -- this is not an official" >> $out
 | 
|  |     14 | echo "results transcript." >> $out
 | 
|  |     15 | echo "" >> $out
 | 
|  |     16 | 
 | 
| 258 |     17 | # marks for CW8 part 2
 | 
| 243 |     18 | marks=$(( 0 ))
 | 
|  |     19 | 
 | 
|  |     20 | # compilation tests
 | 
|  |     21 | 
 | 
|  |     22 | function scala_compile {
 | 
| 258 |     23 |     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
 | 
| 243 |     24 | }
 | 
|  |     25 | 
 | 
|  |     26 | # functional tests
 | 
|  |     27 | 
 | 
|  |     28 | function scala_assert {
 | 
| 259 |     29 |     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 243 |     30 | }
 | 
|  |     31 | 
 | 
| 258 |     32 | function scala_assert_long {
 | 
|  |     33 |   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
|  |     34 | }
 | 
|  |     35 | 
 | 
|  |     36 | function scala_assert_elong {
 | 
|  |     37 |   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
|  |     38 | }
 | 
| 243 |     39 | 
 | 
|  |     40 | # purity test
 | 
|  |     41 | 
 | 
|  |     42 | function scala_vars {
 | 
|  |     43 |    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
 | 
|  |     44 | }
 | 
|  |     45 | 
 | 
|  |     46 | 
 | 
| 258 |     47 | # knights2: purity test
 | 
| 243 |     48 | #
 | 
| 258 |     49 | echo "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
 | 
| 243 |     50 | 
 | 
|  |     51 | 
 | 
| 258 |     52 | if (scala_vars knight2.scala)
 | 
| 243 |     53 | then
 | 
|  |     54 |   echo "  --> test failed" | tee -a $out
 | 
|  |     55 |   tsts0=$(( 1 ))
 | 
|  |     56 | else
 | 
|  |     57 |   echo "  --> success" | tee -a $out
 | 
|  |     58 |   tsts0=$(( 0 )) 
 | 
|  |     59 | fi
 | 
|  |     60 | 
 | 
|  |     61 | 
 | 
|  |     62 | # compilation test
 | 
|  |     63 | if  [ $tsts0 -eq 0 ]
 | 
|  |     64 | then    
 | 
| 258 |     65 |   echo "knight2.scala runs?" | tee -a $out
 | 
| 243 |     66 | 
 | 
| 258 |     67 |   if (scala_compile knight2.scala)
 | 
| 243 |     68 |   then
 | 
|  |     69 |     echo "  --> success" | tee -a $out
 | 
|  |     70 |     tsts1=$(( 0 ))
 | 
|  |     71 |   else
 | 
| 258 |     72 |     echo "  --> scala knight2.scala did not run successfully" | tee -a $out
 | 
| 243 |     73 |     tsts1=$(( 1 )) 
 | 
|  |     74 |   fi
 | 
|  |     75 | else
 | 
|  |     76 |   tsts1=$(( 1 ))     
 | 
|  |     77 | fi
 | 
|  |     78 | 
 | 
|  |     79 | # ordered move test
 | 
|  |     80 | 
 | 
|  |     81 | if [ $tsts1 -eq 0 ]
 | 
|  |     82 | then
 | 
|  |     83 |   echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
 | 
|  |     84 |   echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
 | 
|  |     85 |   echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
 | 
|  |     86 |   
 | 
| 258 |     87 |   if (scala_assert "knight2.scala" "knight_test6.scala")
 | 
| 243 |     88 |   then
 | 
|  |     89 |       echo "  --> success" | tee -a $out
 | 
|  |     90 |       marks=$(( marks + 1 ))
 | 
|  |     91 |   else
 | 
|  |     92 |     echo "  --> test failed" | tee -a $out
 | 
|  |     93 |   fi
 | 
|  |     94 | fi
 | 
|  |     95 | 
 | 
|  |     96 | 
 | 
|  |     97 | # first-closed-tour test
 | 
|  |     98 | 
 | 
|  |     99 | if [ $tsts1 -eq 0 ]
 | 
|  |    100 | then
 | 
|  |    101 |   echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
 | 
|  |    102 |   
 | 
| 258 |    103 |   if (scala_assert "knight2.scala" "knight_test7.scala")
 | 
| 243 |    104 |   then
 | 
|  |    105 |       echo "  --> success" | tee -a $out
 | 
|  |    106 |       marks=$(( marks + 1 ))
 | 
|  |    107 |   else
 | 
|  |    108 |       echo "  --> test failed" | tee -a $out
 | 
|  |    109 |   fi
 | 
|  |    110 | fi
 | 
|  |    111 | 
 | 
|  |    112 | 
 | 
|  |    113 | 
 | 
|  |    114 | if [ $tsts1 -eq 0 ]
 | 
|  |    115 | then
 | 
|  |    116 |   echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    117 |   echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    118 |   
 | 
| 258 |    119 |   if (scala_assert "knight2.scala" "knight_test8.scala")
 | 
| 243 |    120 |   then
 | 
|  |    121 |       echo "  --> success" | tee -a $out
 | 
|  |    122 |       marks=$(( marks + 1 ))
 | 
|  |    123 |   else
 | 
|  |    124 |     echo "  --> test failed" | tee -a $out
 | 
|  |    125 |   fi
 | 
|  |    126 | fi
 | 
|  |    127 | 
 | 
|  |    128 | 
 | 
| 258 |    129 | 
 | 
|  |    130 | # knights3: purity test
 | 
|  |    131 | #
 | 
|  |    132 | echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
 | 
|  |    133 | 
 | 
|  |    134 | 
 | 
|  |    135 | if (scala_vars knight3.scala)
 | 
|  |    136 | then
 | 
|  |    137 |   echo "  --> test failed" | tee -a $out
 | 
| 259 |    138 |   tsts0=$(( 1 ))
 | 
| 258 |    139 | else
 | 
|  |    140 |   echo "  --> success" | tee -a $out
 | 
|  |    141 |   tsts0=$(( 0 )) 
 | 
|  |    142 | fi
 | 
|  |    143 | 
 | 
|  |    144 | # compilation test
 | 
|  |    145 | if  [ $tsts0 -eq 0 ]
 | 
|  |    146 | then    
 | 
|  |    147 |   echo "knight3.scala runs?" | tee -a $out
 | 
|  |    148 | 
 | 
|  |    149 |   if (scala_compile knight3.scala)
 | 
|  |    150 |   then
 | 
|  |    151 |     echo "  --> success" | tee -a $out
 | 
|  |    152 |     tsts1=$(( 0 ))
 | 
|  |    153 |   else
 | 
|  |    154 |     echo -e "  --> test failed" | tee -a $out  
 | 
|  |    155 |     tsts1=$(( 1 )) 
 | 
|  |    156 |   fi
 | 
|  |    157 | else
 | 
|  |    158 |   tsts1=$(( 1 ))     
 | 
|  |    159 | fi
 | 
|  |    160 | 
 | 
|  |    161 | 
 | 
|  |    162 | if [ $tsts1 -eq 0 ]
 | 
|  |    163 | then
 | 
|  |    164 |   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out
 | 
|  |    165 |   
 | 
|  |    166 |   if (scala_assert_long "knight3.scala" "knight_test9.scala")
 | 
|  |    167 |   then
 | 
|  |    168 |       echo -e "  --> success" | tee -a $out
 | 
|  |    169 |       marks=$(( marks + 1 ))
 | 
|  |    170 |   else
 | 
|  |    171 |       echo -e "  --> test  failed" | tee -a $out 
 | 
|  |    172 |   fi
 | 
|  |    173 | fi
 | 
|  |    174 | 
 | 
|  |    175 | 
 | 
| 243 |    176 | ## final marks
 | 
| 258 |    177 | echo "Overall mark for CW 8, Part 2" | tee -a $out
 | 
| 243 |    178 | echo "$marks" | tee -a $out
 |