|
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 |
|
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 |
|
15 echo "" >> $out |
|
16 |
|
17 # marks for CW7 part 2 |
|
18 marks=$(( 0 )) |
|
19 |
|
20 # compilation tests |
|
21 |
|
22 function scala_compile { |
|
23 (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) |
|
24 } |
|
25 |
|
26 # functional tests |
|
27 |
|
28 function scala_assert { |
|
29 (ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 } |
|
31 |
|
32 |
|
33 # purity test |
|
34 |
|
35 function scala_vars { |
|
36 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
37 } |
|
38 |
|
39 |
|
40 # knights3: purity test |
|
41 # |
|
42 echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
43 |
|
44 |
|
45 if (scala_vars knight3.scala) |
|
46 then |
|
47 echo " --> test failed" | tee -a $out |
|
48 tsts0=$(( 1 )) |
|
49 else |
|
50 echo " --> success" | tee -a $out |
|
51 tsts0=$(( 0 )) |
|
52 fi |
|
53 |
|
54 |
|
55 # compilation test |
|
56 if [ $tsts0 -eq 0 ] |
|
57 then |
|
58 echo "knight3.scala runs?" | tee -a $out |
|
59 |
|
60 if (scala_compile knight3.scala) |
|
61 then |
|
62 echo " --> success" | tee -a $out |
|
63 tsts1=$(( 0 )) |
|
64 else |
|
65 echo " --> scala knight3.scala did not run successfully" | tee -a $out |
|
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 |
|
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 |
|
79 |
|
80 if (scala_assert "knight3.scala" "knight3a_test.scala") |
|
81 then |
|
82 echo " --> success" | tee -a $out |
|
83 marks=$(( marks + 1 )) |
|
84 else |
|
85 echo " --> test failed" | tee -a $out |
|
86 fi |
|
87 fi |
|
88 |
|
89 |
|
90 # first-closed-tour test |
|
91 |
|
92 if [ $tsts1 -eq 0 ] |
|
93 then |
|
94 echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out |
|
95 |
|
96 if (scala_assert "knight3.scala" "knight3b_test.scala") |
|
97 then |
|
98 echo " --> success" | tee -a $out |
|
99 marks=$(( marks + 1 )) |
|
100 else |
|
101 echo " --> test failed" | tee -a $out |
|
102 fi |
|
103 fi |
|
104 |
|
105 |
|
106 |
|
107 if [ $tsts1 -eq 0 ] |
|
108 then |
|
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 |
|
111 |
|
112 if (scala_assert "knight3.scala" "knight3c_test.scala") |
|
113 then |
|
114 echo " --> success" | tee -a $out |
|
115 marks=$(( marks + 1 )) |
|
116 else |
|
117 echo " --> test failed" | tee -a $out |
|
118 fi |
|
119 fi |
|
120 |
|
121 |
|
122 ## final marks |
|
123 echo "Overall mark for CW 7, Part 2" | tee -a $out |
|
124 echo "$marks" | tee -a $out |