220
|
1 |
#!/bin/bash
|
|
2 |
set -euo pipefail
|
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
|
6 |
echo -e "" > $out
|
|
7 |
|
418
|
8 |
echo -e "Below is the feedback for your submission of knight{1,2,3}.scala" >> $out
|
220
|
9 |
echo -e "" >> $out
|
347
|
10 |
#echo -e "!! Important: !!" >> $out
|
|
11 |
#echo -e "Because of limitations with our testing infrastructure, we can only" >> $out
|
|
12 |
#echo -e "let code run for 10 seconds and then have to kill it. This might" >> $out
|
|
13 |
#echo -e "mean your code is correct, but still marked as Fail. Remember" >> $out
|
|
14 |
#echo -e "you can test your code on your own machine and benchmark it" >> $out
|
|
15 |
#echo -e "against the reference implementation." >> $out
|
|
16 |
#echo -e "" >> $out
|
|
17 |
|
220
|
18 |
|
|
19 |
# compilation tests
|
|
20 |
|
|
21 |
function scala_compile {
|
347
|
22 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
|
220
|
23 |
}
|
|
24 |
|
|
25 |
# functional tests
|
|
26 |
|
347
|
27 |
function scala_assert {
|
|
28 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
220
|
29 |
}
|
|
30 |
|
|
31 |
# purity test
|
|
32 |
|
|
33 |
function scala_vars {
|
376
|
34 |
(egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
|
220
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
# compilation test
|
|
42 |
|
347
|
43 |
|
|
44 |
echo -e "knight1.scala runs?" >> $out
|
220
|
45 |
|
347
|
46 |
if (scala_compile knight1.scala)
|
|
47 |
then
|
352
|
48 |
echo -e " --> passed" >> $out
|
220
|
49 |
tsts1=$(( 0 ))
|
|
50 |
else
|
|
51 |
echo -e " --> SCALA DID NOT RUN KNIGHT1.SCALA\n" >> $out
|
|
52 |
tsts1=$(( 1 ))
|
|
53 |
fi
|
|
54 |
|
347
|
55 |
|
|
56 |
# knights1: purity test
|
|
57 |
|
|
58 |
if [ $tsts1 -eq 0 ]
|
|
59 |
then
|
|
60 |
echo -e "knight1.scala does not contain vars, returns etc?" >> $out
|
|
61 |
|
|
62 |
if (scala_vars knight1.scala)
|
|
63 |
then
|
|
64 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
|
65 |
tsts1=$(( 1 ))
|
|
66 |
else
|
352
|
67 |
echo -e " --> passed" >> $out
|
347
|
68 |
tsts1=$(( 0 ))
|
|
69 |
fi
|
|
70 |
fi
|
|
71 |
|
|
72 |
|
220
|
73 |
### knight1 test
|
|
74 |
|
376
|
75 |
#if [ $tsts1 -eq 0 ]
|
|
76 |
#then
|
|
77 |
# #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
|
78 |
# echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
|
|
79 |
# echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
|
|
80 |
# echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out
|
|
81 |
#
|
|
82 |
# if (scala_assert "knight1.scala" "knight_test1.scala")
|
|
83 |
# then
|
|
84 |
# echo -e " --> success" >> $out
|
|
85 |
# else
|
|
86 |
# echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
87 |
# fi
|
|
88 |
#fi
|
220
|
89 |
|
|
90 |
### knight2 test
|
|
91 |
|
376
|
92 |
#if [ $tsts1 -eq 0 ]
|
|
93 |
#then
|
|
94 |
# #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
|
95 |
# echo -e " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
|
|
96 |
# echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
|
|
97 |
# echo -e " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
|
|
98 |
# echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
|
|
99 |
# echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
|
|
100 |
# echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
|
|
101 |
# echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
|
|
102 |
#
|
|
103 |
# if (scala_assert "knight1.scala" "knight_test2.scala")
|
|
104 |
# then
|
|
105 |
# echo -e " --> success" >> $out
|
|
106 |
# else
|
|
107 |
# echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
108 |
# fi
|
|
109 |
#fi
|
220
|
110 |
|
|
111 |
|
|
112 |
### knight3 test
|
|
113 |
|
376
|
114 |
#if [ $tsts1 -eq 0 ]
|
|
115 |
#then
|
|
116 |
# #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
|
117 |
# echo -e " count_tours from every position on the board" >> $out
|
|
118 |
# echo -e " dim = 1: 1" >> $out
|
|
119 |
# echo -e " 2: 0,0,0,0" >> $out
|
|
120 |
# echo -e " 3: 0,0,0,0,0,0,0,0,0" >> $out
|
|
121 |
# echo -e " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
|
|
122 |
# #echo -e " 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" >> $out
|
|
123 |
# echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
|
|
124 |
# echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
|
|
125 |
# echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
|
|
126 |
#
|
|
127 |
# if (scala_assert "knight1.scala" "knight_test3.scala")
|
|
128 |
# then
|
|
129 |
# echo -e " --> success" >> $out
|
|
130 |
# else
|
|
131 |
# echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
132 |
# fi
|
|
133 |
#fi
|
220
|
134 |
|
|
135 |
### knight4 test
|
|
136 |
|
|
137 |
if [ $tsts1 -eq 0 ]
|
|
138 |
then
|
347
|
139 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
220
|
140 |
echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
|
|
141 |
echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
|
|
142 |
echo -e " first(List((1,0),(2,0),(3,0)), f) == None" >> $out
|
|
143 |
|
347
|
144 |
if (scala_assert "knight1.scala" "knight_test4.scala")
|
220
|
145 |
then
|
|
146 |
echo -e " --> success" >> $out
|
|
147 |
else
|
|
148 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
149 |
fi
|
|
150 |
fi
|
|
151 |
|
|
152 |
|
|
153 |
### knight5 test
|
|
154 |
|
|
155 |
if [ $tsts1 -eq 0 ]
|
|
156 |
then
|
347
|
157 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
220
|
158 |
echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
|
|
159 |
echo -e " is first_tour(4, List((0, 0))) == None " >> $out
|
|
160 |
|
347
|
161 |
if (scala_assert "knight1.scala" "knight_test5.scala")
|
220
|
162 |
then
|
|
163 |
echo -e " --> success" >> $out
|
|
164 |
else
|
|
165 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
166 |
fi
|
|
167 |
fi
|
|
168 |
|
296
|
169 |
|
|
170 |
echo -e "" >> $out
|
|
171 |
echo -e "" >> $out
|
|
172 |
|
|
173 |
|
347
|
174 |
# compilation test
|
|
175 |
echo -e "knight2.scala runs?" >> $out
|
296
|
176 |
|
347
|
177 |
if (scala_compile knight2.scala)
|
296
|
178 |
then
|
352
|
179 |
echo -e " --> passed" >> $out
|
347
|
180 |
tsts2=$(( 0 ))
|
296
|
181 |
else
|
347
|
182 |
echo -e " --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out
|
|
183 |
tsts2=$(( 1 ))
|
296
|
184 |
fi
|
|
185 |
|
|
186 |
|
347
|
187 |
# knights2: purity test
|
|
188 |
#
|
|
189 |
|
|
190 |
if [ $tsts2 -eq 0 ]
|
|
191 |
then
|
|
192 |
echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
|
296
|
193 |
|
347
|
194 |
if (scala_vars knight2.scala)
|
|
195 |
then
|
|
196 |
echo -e " --> Fail (make triple-sure your program conforms to the required format)" >> $out
|
|
197 |
tsts2=$(( 1 ))
|
|
198 |
else
|
352
|
199 |
echo -e " --> passed" >> $out
|
347
|
200 |
tsts2=$(( 0 ))
|
|
201 |
fi
|
296
|
202 |
fi
|
|
203 |
|
|
204 |
|
|
205 |
# ordered move test
|
|
206 |
|
347
|
207 |
if [ $tsts2 -eq 0 ]
|
296
|
208 |
then
|
347
|
209 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
296
|
210 |
echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
|
|
211 |
echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
|
|
212 |
echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
|
|
213 |
|
347
|
214 |
if (scala_assert "knight2.scala" "knight_test6.scala")
|
296
|
215 |
then
|
|
216 |
echo -e " --> success" >> $out
|
|
217 |
else
|
|
218 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
219 |
fi
|
|
220 |
fi
|
|
221 |
|
|
222 |
|
|
223 |
# first-closed-tour test
|
|
224 |
|
347
|
225 |
if [ $tsts2 -eq 0 ]
|
296
|
226 |
then
|
347
|
227 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
329
|
228 |
echo -e " first_closed_tour_heuristics(6, List((3,3))) found and correct?" >> $out
|
296
|
229 |
|
347
|
230 |
if (scala_assert "knight2.scala" "knight_test7.scala")
|
296
|
231 |
then
|
|
232 |
echo -e " --> success" >> $out
|
|
233 |
else
|
|
234 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
235 |
fi
|
|
236 |
fi
|
|
237 |
|
|
238 |
|
|
239 |
|
347
|
240 |
if [ $tsts2 -eq 0 ]
|
296
|
241 |
then
|
347
|
242 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
329
|
243 |
echo -e " first_tour_heuristics(8, List((0,0))) found and correct?" >> $out
|
|
244 |
echo -e " first_tour_heuristics(30, List((0,0))) found and correct?" >> $out
|
296
|
245 |
|
347
|
246 |
if (scala_assert "knight2.scala" "knight_test8.scala")
|
296
|
247 |
then
|
|
248 |
echo -e " --> success" >> $out
|
|
249 |
else
|
|
250 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
251 |
fi
|
|
252 |
fi
|
|
253 |
|
|
254 |
|
|
255 |
echo -e "" >> $out
|
|
256 |
echo -e "" >> $out
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
# compilation test
|
347
|
261 |
|
|
262 |
echo "knight3.scala runs?" >> $out
|
296
|
263 |
|
347
|
264 |
if (scala_compile knight3.scala)
|
|
265 |
then
|
352
|
266 |
echo " --> passed" >> $out
|
347
|
267 |
tsts3=$(( 0 ))
|
|
268 |
else
|
296
|
269 |
echo -e " --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out
|
347
|
270 |
tsts3=$(( 1 ))
|
|
271 |
fi
|
|
272 |
|
|
273 |
# knights3: purity test
|
|
274 |
#
|
|
275 |
if [ $tsts3 -eq 0 ]
|
|
276 |
then
|
|
277 |
echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
|
|
278 |
|
|
279 |
if (scala_vars knight3.scala)
|
|
280 |
then
|
|
281 |
echo " --> Fail (make triple-sure your program conforms to the required format)xsxs" >> $out
|
|
282 |
tsts3=$(( 1 ))
|
|
283 |
else
|
352
|
284 |
echo " --> passed" >> $out
|
347
|
285 |
tsts3=$(( 0 ))
|
|
286 |
fi
|
296
|
287 |
fi
|
|
288 |
|
|
289 |
|
347
|
290 |
if [ $tsts3 -eq 0 ]
|
296
|
291 |
then
|
347
|
292 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
296
|
293 |
echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out
|
|
294 |
|
347
|
295 |
if (scala_assert "knight3.scala" "knight_test9.scala")
|
296
|
296 |
then
|
|
297 |
echo -e " --> success" >> $out
|
|
298 |
else
|
|
299 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
300 |
fi
|
|
301 |
fi
|
|
302 |
|