|
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 core assignment 8. 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 core CW8 |
|
18 marks=$(( 0 )) |
|
19 |
|
20 # compilation tests |
|
21 |
|
22 function scala_compile { |
|
23 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null) |
|
24 } |
|
25 |
|
26 # functional tests |
|
27 |
|
28 function scala_assert { |
|
29 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 } |
|
31 |
|
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 #} |
|
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 # knights1: purity test |
|
47 |
|
48 echo -e "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
49 |
|
50 if (scala_vars knight1.scala) |
|
51 then |
|
52 echo -e " --> TEST FAILED\n" | tee -a $out |
|
53 tsts0=$(( 1 )) |
|
54 else |
|
55 echo -e " --> success" | tee -a $out |
|
56 tsts0=$(( 0 )) |
|
57 fi |
|
58 |
|
59 |
|
60 # compilation test |
|
61 |
|
62 if [ $tsts0 -eq 0 ] |
|
63 then |
|
64 echo -e "knight1.scala runs?" | tee -a $out |
|
65 |
|
66 if (scala_compile knight1.scala) |
|
67 then |
|
68 echo -e " --> success " | tee -a $out |
|
69 tsts1=$(( 0 )) |
|
70 else |
|
71 echo -e " --> SCALA DID NOT RUN knight1.scala\n" | tee -a $out |
|
72 tsts1=$(( 1 )) |
|
73 fi |
|
74 else |
|
75 tsts1=$(( 1 )) |
|
76 fi |
|
77 |
|
78 |
|
79 ### knight4 test |
|
80 |
|
81 if [ $tsts1 -eq 0 ] |
|
82 then |
|
83 echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out |
|
84 echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out |
|
85 echo -e " first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out |
|
86 |
|
87 if (scala_assert "knight1.scala" "knight1_test4.scala") |
|
88 then |
|
89 echo -e " --> success" | tee -a $out |
|
90 marks=$(( marks + 1 )) |
|
91 else |
|
92 echo -e " --> TEST FAILED\n" | tee -a $out |
|
93 fi |
|
94 fi |
|
95 |
|
96 ### knight5 test |
|
97 |
|
98 if [ $tsts1 -eq 0 ] |
|
99 then |
|
100 echo -e " is first_tour(6, List((0, 0))) ok? " | tee -a $out |
|
101 echo -e " is first_tour(4, List((0, 0))) == None " | tee -a $out |
|
102 START=$(date +%s) |
|
103 |
|
104 if (scala_assert_long "knight1.scala" "knight1_test5.scala") |
|
105 then |
|
106 END=$(date +%s) |
|
107 DIFF=$(( $END - $START )) |
|
108 echo " It took $DIFF seconds" | tee -a $out |
|
109 echo -e " --> success" | tee -a $out |
|
110 marks=$(( marks + 1 )) |
|
111 else |
|
112 END=$(date +%s) |
|
113 DIFF=$(( $END - $START )) |
|
114 echo " It took $DIFF seconds" | tee -a $out |
|
115 echo -e " --> TEST FAILED\n" | tee -a $out |
|
116 fi |
|
117 fi |
|
118 |
|
119 |
|
120 |
|
121 # knights2: purity test |
|
122 # |
|
123 echo "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
124 |
|
125 |
|
126 if (scala_vars knight2.scala) |
|
127 then |
|
128 echo -e " --> TEST FAILED\n" | tee -a $out |
|
129 tsts0=$(( 1 )) |
|
130 else |
|
131 echo -e " --> success" | tee -a $out |
|
132 tsts0=$(( 0 )) |
|
133 fi |
|
134 |
|
135 |
|
136 # compilation test |
|
137 if [ $tsts0 -eq 0 ] |
|
138 then |
|
139 echo "knight2.scala runs?" | tee -a $out |
|
140 |
|
141 if (scala_compile knight2.scala) |
|
142 then |
|
143 echo -e " --> success" | tee -a $out |
|
144 tsts1=$(( 0 )) |
|
145 else |
|
146 echo -e " --> SCALA DID NOT RUN knight2.scala\n" | tee -a $out |
|
147 tsts1=$(( 1 )) |
|
148 fi |
|
149 else |
|
150 tsts1=$(( 1 )) |
|
151 fi |
|
152 |
|
153 # ordered move test |
|
154 |
|
155 if [ $tsts1 -eq 0 ] |
|
156 then |
|
157 echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out |
|
158 echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out |
|
159 echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out |
|
160 |
|
161 if (scala_assert "knight2.scala" "knight2_test6.scala") |
|
162 then |
|
163 echo -e " --> success" | tee -a $out |
|
164 marks=$(( marks + 1 )) |
|
165 else |
|
166 echo -e " --> TEST FAILED\n" | tee -a $out |
|
167 fi |
|
168 fi |
|
169 |
|
170 |
|
171 # first-closed-tour test |
|
172 |
|
173 if [ $tsts1 -eq 0 ] |
|
174 then |
|
175 echo -e " first_closed_tour_heuristics(6, List((3,3))) found and correct?" | tee -a $out |
|
176 START=$(date +%s) |
|
177 |
|
178 if (scala_assert "knight2.scala" "knight2_test7.scala") |
|
179 then |
|
180 END=$(date +%s) |
|
181 DIFF=$(( $END - $START )) |
|
182 echo " It took $DIFF seconds" | tee -a $out |
|
183 echo -e " --> success" | tee -a $out |
|
184 marks=$(( marks + 1 )) |
|
185 else |
|
186 END=$(date +%s) |
|
187 DIFF=$(( $END - $START )) |
|
188 echo " It took $DIFF seconds" | tee -a $out |
|
189 echo -e " --> TEST FAILED\n" | tee -a $out |
|
190 fi |
|
191 fi |
|
192 |
|
193 |
|
194 # first-tour test |
|
195 |
|
196 if [ $tsts1 -eq 0 ] |
|
197 then |
|
198 echo -e " first_tour_heuristics(8, List((0,0))) found and correct?" | tee -a $out |
|
199 echo -e " first_tour_heuristics(30, List((0,0))) found and correct?" | tee -a $out |
|
200 START=$(date +%s) |
|
201 |
|
202 if (scala_assert_long "knight2.scala" "knight2_test8.scala") |
|
203 then |
|
204 END=$(date +%s) |
|
205 DIFF=$(( $END - $START )) |
|
206 echo " It took $DIFF seconds" | tee -a $out |
|
207 echo -e " --> success" | tee -a $out |
|
208 marks=$(( marks + 1 )) |
|
209 else |
|
210 END=$(date +%s) |
|
211 DIFF=$(( $END - $START )) |
|
212 echo " It took $DIFF seconds" | tee -a $out |
|
213 echo -e " --> TEST FAILED\n" | tee -a $out |
|
214 fi |
|
215 fi |
|
216 |
|
217 |
|
218 |
|
219 # knights3: purity test |
|
220 # |
|
221 echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
222 |
|
223 |
|
224 if (scala_vars knight3.scala) |
|
225 then |
|
226 echo " --> TEST FAILED\n" | tee -a $out |
|
227 tsts0=$(( 1 )) |
|
228 else |
|
229 echo " --> success" | tee -a $out |
|
230 tsts0=$(( 0 )) |
|
231 fi |
|
232 |
|
233 # compilation test |
|
234 if [ $tsts0 -eq 0 ] |
|
235 then |
|
236 echo "knight3.scala runs?" | tee -a $out |
|
237 |
|
238 if (scala_compile knight3.scala) |
|
239 then |
|
240 echo " --> success" | tee -a $out |
|
241 tsts1=$(( 0 )) |
|
242 else |
|
243 echo -e " --> SCALA DID NOT RUN knight3.scala\n" | tee -a $out |
|
244 tsts1=$(( 1 )) |
|
245 fi |
|
246 else |
|
247 tsts1=$(( 1 )) |
|
248 fi |
|
249 |
|
250 |
|
251 if [ $tsts1 -eq 0 ] |
|
252 then |
|
253 echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out |
|
254 START=$(date +%s) |
|
255 |
|
256 if (scala_assert "knight3.scala" "knight3_test9.scala") |
|
257 then |
|
258 END=$(date +%s) |
|
259 DIFF=$(( $END - $START )) |
|
260 echo " It took $DIFF seconds" | tee -a $out |
|
261 echo -e " --> success" | tee -a $out |
|
262 marks=$(( marks + 1 )) |
|
263 else |
|
264 END=$(date +%s) |
|
265 DIFF=$(( $END - $START )) |
|
266 echo " It took $DIFF seconds" | tee -a $out |
|
267 echo -e " --> test failed" | tee -a $out |
|
268 fi |
|
269 fi |
|
270 |
|
271 |
|
272 ## final marks |
|
273 echo -e "" >> $out |
|
274 echo -e "Overall mark for CW 8 Core Part" | tee -a $out |
|
275 echo -e "$marks" | tee -a $out |