| 
145
 | 
     1  | 
#!/bin/bash
  | 
| 
245
 | 
     2  | 
  | 
| 
 | 
     3  | 
# to make the script fail safely
  | 
| 
 | 
     4  | 
set -euo pipefail
  | 
| 
 | 
     5  | 
  | 
| 
145
 | 
     6  | 
  | 
| 
 | 
     7  | 
out=${1:-output}
 | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
echo "" > $out
  | 
| 
 | 
    10  | 
  | 
| 
245
 | 
    11  | 
echo "Below is the feedback and provisional marks for your submission" >> $out
  | 
| 
 | 
    12  | 
echo "for assignment 7 Part 2.  Please note all marks are provisional until" >> $out
  | 
| 
 | 
    13  | 
echo "ratified by the assessment board -- this is not an official" >> $out
  | 
| 
 | 
    14  | 
echo "results transcript." >> $out
  | 
| 
145
 | 
    15  | 
echo "" >> $out
  | 
| 
 | 
    16  | 
  | 
| 
245
 | 
    17  | 
# marks for CW7 part 2
  | 
| 
 | 
    18  | 
marks=$(( 0 ))
  | 
| 
145
 | 
    19  | 
  | 
| 
 | 
    20  | 
# compilation tests
  | 
| 
 | 
    21  | 
  | 
| 
 | 
    22  | 
function scala_compile {
 | 
| 
245
 | 
    23  | 
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
  | 
| 
145
 | 
    24  | 
}
  | 
| 
 | 
    25  | 
  | 
| 
 | 
    26  | 
# functional tests
  | 
| 
 | 
    27  | 
  | 
| 
245
 | 
    28  | 
function scala_assert {
 | 
| 
 | 
    29  | 
    (ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
  | 
| 
 | 
    30  | 
}
  | 
| 
168
 | 
    31  | 
  | 
| 
145
 | 
    32  | 
  | 
| 
 | 
    33  | 
# purity test
  | 
| 
 | 
    34  | 
  | 
| 
 | 
    35  | 
function scala_vars {
 | 
| 
153
 | 
    36  | 
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
  | 
| 
145
 | 
    37  | 
}
  | 
| 
 | 
    38  | 
  | 
| 
 | 
    39  | 
  | 
| 
 | 
    40  | 
# knights3: purity test
  | 
| 
 | 
    41  | 
#
  | 
| 
245
 | 
    42  | 
echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
  | 
| 
 | 
    43  | 
  | 
| 
145
 | 
    44  | 
  | 
| 
 | 
    45  | 
if (scala_vars knight3.scala)
  | 
| 
 | 
    46  | 
then
  | 
| 
245
 | 
    47  | 
  echo "  --> test failed" | tee -a $out
  | 
| 
145
 | 
    48  | 
  tsts0=$(( 1 ))
  | 
| 
 | 
    49  | 
else
  | 
| 
245
 | 
    50  | 
  echo "  --> success" | tee -a $out
  | 
| 
145
 | 
    51  | 
  tsts0=$(( 0 )) 
  | 
| 
 | 
    52  | 
fi
  | 
| 
 | 
    53  | 
  | 
| 
 | 
    54  | 
  | 
| 
 | 
    55  | 
# compilation test
  | 
| 
 | 
    56  | 
if  [ $tsts0 -eq 0 ]
  | 
| 
 | 
    57  | 
then    
  | 
| 
245
 | 
    58  | 
  echo "knight3.scala runs?" | tee -a $out
  | 
| 
145
 | 
    59  | 
  | 
| 
 | 
    60  | 
  if (scala_compile knight3.scala)
  | 
| 
 | 
    61  | 
  then
  | 
| 
245
 | 
    62  | 
    echo "  --> success" | tee -a $out
  | 
| 
145
 | 
    63  | 
    tsts1=$(( 0 ))
  | 
| 
 | 
    64  | 
  else
  | 
| 
245
 | 
    65  | 
    echo "  --> scala knight3.scala did not run successfully" | tee -a $out
  | 
| 
145
 | 
    66  | 
    tsts1=$(( 1 )) 
  | 
| 
 | 
    67  | 
  fi
  | 
| 
 | 
    68  | 
else
  | 
| 
 | 
    69  | 
  tsts1=$(( 1 ))     
  | 
| 
 | 
    70  | 
fi
  | 
| 
 | 
    71  | 
  | 
| 
 | 
    72  | 
# ordered move test
  | 
| 
 | 
    73  | 
  | 
| 
 | 
    74  | 
if [ $tsts1 -eq 0 ]
  | 
| 
 | 
    75  | 
then
  | 
| 
245
 | 
    76  | 
  echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
  | 
| 
 | 
    77  | 
  echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
  | 
| 
 | 
    78  | 
  echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
  | 
| 
145
 | 
    79  | 
  
  | 
| 
 | 
    80  | 
  if (scala_assert "knight3.scala" "knight3a_test.scala")
  | 
| 
 | 
    81  | 
  then
  | 
| 
245
 | 
    82  | 
      echo "  --> success" | tee -a $out
  | 
| 
 | 
    83  | 
      marks=$(( marks + 1 ))
  | 
| 
145
 | 
    84  | 
  else
  | 
| 
245
 | 
    85  | 
    echo "  --> test failed" | tee -a $out
  | 
| 
145
 | 
    86  | 
  fi
  | 
| 
 | 
    87  | 
fi
  | 
| 
 | 
    88  | 
  | 
| 
 | 
    89  | 
  | 
| 
 | 
    90  | 
# first-closed-tour test
  | 
| 
 | 
    91  | 
  | 
| 
 | 
    92  | 
if [ $tsts1 -eq 0 ]
  | 
| 
 | 
    93  | 
then
  | 
| 
245
 | 
    94  | 
  echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
  | 
| 
145
 | 
    95  | 
  
  | 
| 
 | 
    96  | 
  if (scala_assert "knight3.scala" "knight3b_test.scala")
  | 
| 
 | 
    97  | 
  then
  | 
| 
245
 | 
    98  | 
      echo "  --> success" | tee -a $out
  | 
| 
 | 
    99  | 
      marks=$(( marks + 1 ))
  | 
| 
145
 | 
   100  | 
  else
  | 
| 
245
 | 
   101  | 
      echo "  --> test failed" | tee -a $out
  | 
| 
145
 | 
   102  | 
  fi
  | 
| 
 | 
   103  | 
fi
  | 
| 
 | 
   104  | 
  | 
| 
 | 
   105  | 
  | 
| 
 | 
   106  | 
  | 
| 
 | 
   107  | 
if [ $tsts1 -eq 0 ]
  | 
| 
 | 
   108  | 
then
  | 
| 
245
 | 
   109  | 
  echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
  | 
| 
 | 
   110  | 
  echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
  | 
| 
145
 | 
   111  | 
  
  | 
| 
 | 
   112  | 
  if (scala_assert "knight3.scala" "knight3c_test.scala")
  | 
| 
 | 
   113  | 
  then
  | 
| 
245
 | 
   114  | 
      echo "  --> success" | tee -a $out
  | 
| 
 | 
   115  | 
      marks=$(( marks + 1 ))
  | 
| 
145
 | 
   116  | 
  else
  | 
| 
245
 | 
   117  | 
    echo "  --> test failed" | tee -a $out
  | 
| 
145
 | 
   118  | 
  fi
  | 
| 
 | 
   119  | 
fi
  | 
| 
 | 
   120  | 
  | 
| 
 | 
   121  | 
  | 
| 
 | 
   122  | 
## final marks
  | 
| 
245
 | 
   123  | 
echo "Overall mark for CW 7, Part 2" | tee -a $out
  | 
| 
 | 
   124  | 
echo "$marks" | tee -a $out
  |