39 function scala_assert_slow { |
39 function scala_assert_slow { |
40 (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
40 (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
41 } |
41 } |
42 |
42 |
43 function scala_assert_thirty { |
43 function scala_assert_thirty { |
44 (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
44 (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
45 } |
45 } |
46 |
46 |
47 function scala_assert_quick { |
47 function scala_assert_quick { |
48 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
48 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
49 } |
49 } |
50 |
50 |
51 function scala_assert_long { |
51 function scala_assert_long { |
52 (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
52 (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
53 } |
53 } |
54 |
54 |
55 function scala_assert_elong { |
55 function scala_assert_elong { |
56 (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
56 (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
57 } |
57 } |
58 |
58 |
59 # purity test |
59 # purity test |
60 function scala_vars { |
60 function scala_vars { |
61 (sed 's/immutable/ok/g' c$out > cb$out; |
61 (sed 's/immutable/ok/g' c$out > cb$out; |
105 echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out |
105 echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out |
106 echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out |
106 echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out |
107 |
107 |
108 if (scala_assert "knight1.scala" "knight1_test1.scala") |
108 if (scala_assert "knight1.scala" "knight1_test1.scala") |
109 then |
109 then |
110 echo -e " --> success" | tee -a $out |
110 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
111 marks=$(( marks + 1.0 )) |
111 marks=$(( marks + 1.0 )) |
112 else |
112 else |
113 echo -e " --> \n ONE TEST FAILED\n"| tee -a $out |
113 echo -e " --> \n ONE TEST FAILED\n"| tee -a $out |
114 fi |
114 fi |
115 fi |
115 fi |
127 echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out |
127 echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out |
128 echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out |
128 echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out |
129 |
129 |
130 if (scala_assert "knight1.scala" "knight1_test2.scala") |
130 if (scala_assert "knight1.scala" "knight1_test2.scala") |
131 then |
131 then |
132 echo -e " --> success\n" | tee -a $out |
132 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
133 marks=$(( marks + 1 )) |
133 marks=$(( marks + 1 )) |
134 else |
134 else |
135 echo -e " --> ONE TEST FAILED\n" | tee -a $out |
135 echo -e " --> ONE TEST FAILED\n" | tee -a $out |
136 fi |
136 fi |
137 fi |
137 fi |
139 |
139 |
140 ### knight3 test |
140 ### knight3 test |
141 |
141 |
142 if [ $tsts -eq 0 ] |
142 if [ $tsts -eq 0 ] |
143 then |
143 then |
144 echo " count_tours from every position on the board 1 - 4 (0.5% marks)" | tee -a $out |
144 echo " count_tours from every position on the board 1 - 4" | tee -a $out |
145 echo " dim = 1: 1" | tee -a $out |
145 echo " dim = 1: 1" | tee -a $out |
146 echo " 2: 0,0,0,0" | tee -a $out |
146 echo " 2: 0,0,0,0" | tee -a $out |
147 echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out |
147 echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out |
148 echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out |
148 echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out |
149 START=$(date +%s) |
149 START=$(date +%s) |
150 |
150 |
151 if (scala_assert_thirty "knight1.scala" "knight1_test3a.scala") |
151 if (scala_assert "knight1.scala" "knight1_test3a.scala") |
152 then |
152 then |
153 END=$(date +%s) |
153 END=$(date +%s) |
154 DIFF=$(( $END - $START )) |
154 DIFF=$(( $END - $START )) |
155 #echo " This test ran for $DIFF seconds." | tee -a $out |
155 #echo " This test ran for $DIFF seconds." | tee -a $out |
156 echo -e " --> success\n" | tee -a $out |
156 echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out |
157 marks=$(( marks + 0.5 )) |
157 marks=$(( marks + 0.5 )) |
158 else |
158 else |
159 END=$(date +%s) |
159 END=$(date +%s) |
160 DIFF=$(( $END - $START )) |
160 DIFF=$(( $END - $START )) |
161 echo " This test ran for $DIFF seconds." | tee -a $out |
161 echo " This test ran for $DIFF seconds." | tee -a $out |
165 |
165 |
166 |
166 |
167 |
167 |
168 if [ $tsts -eq 0 ] |
168 if [ $tsts -eq 0 ] |
169 then |
169 then |
170 echo " count_tours from every position on the board of dim 5 for the first 3 rows (0.25% marks)" | tee -a $out |
170 echo " count_tours from every position on the board of dim 5 for the first 3 rows" | tee -a $out |
171 echo " dim = 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56)" | tee -a $out |
171 echo " dim = 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56)" | tee -a $out |
172 START=$(date +%s) |
172 START=$(date +%s) |
173 |
173 |
174 if (scala_assert_thirty "knight1.scala" "knight1_test3b.scala") |
174 if (scala_assert "knight1.scala" "knight1_test3b.scala") |
175 then |
175 then |
176 END=$(date +%s) |
176 END=$(date +%s) |
177 DIFF=$(( $END - $START )) |
177 DIFF=$(( $END - $START )) |
178 #echo " This test ran for $DIFF seconds." | tee -a $out |
178 #echo " This test ran for $DIFF seconds." | tee -a $out |
179 echo -e " --> success\n" | tee -a $out |
179 echo -e " --> success (+ 0.25 Marks)\\n" | tee -a $out |
180 marks=$(( marks + 0.25 )) |
180 marks=$(( marks + 0.25 )) |
181 else |
181 else |
182 END=$(date +%s) |
182 END=$(date +%s) |
183 DIFF=$(( $END - $START )) |
183 DIFF=$(( $END - $START )) |
184 echo " This test ran for $DIFF seconds." | tee -a $out |
184 echo " This test ran for $DIFF seconds." | tee -a $out |
190 |
190 |
191 if [ $tsts -eq 0 ] |
191 if [ $tsts -eq 0 ] |
192 then |
192 then |
193 echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out |
193 echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out |
194 echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out |
194 echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out |
195 echo " (0.25% marks) " | tee -a $out |
195 #echo " (0.25% marks) " | tee -a $out |
196 START=$(date +%s) |
196 START=$(date +%s) |
197 |
197 |
198 if (scala_assert_thirty "knight1.scala" "knight1_test3c.scala") |
198 if (scala_assert_thirty "knight1.scala" "knight1_test3c.scala") |
199 then |
199 then |
200 END=$(date +%s) |
200 END=$(date +%s) |
201 DIFF=$(( $END - $START )) |
201 DIFF=$(( $END - $START )) |
202 #echo " This test ran for $DIFF seconds." | tee -a $out |
202 #echo " This test ran for $DIFF seconds." | tee -a $out |
203 echo -e " --> success\n" | tee -a $out |
203 echo -e " --> success (+ 0.25 Marks)\n" | tee -a $out |
204 marks=$(( marks + 0.25 )) |
204 marks=$(( marks + 0.25 )) |
205 else |
205 else |
206 END=$(date +%s) |
206 END=$(date +%s) |
207 DIFF=$(( $END - $START )) |
207 DIFF=$(( $END - $START )) |
208 echo " This test ran for $DIFF seconds." | tee -a $out |
208 echo " This test ran for $DIFF seconds." | tee -a $out |
219 echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out |
219 echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out |
220 echo -e " first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out |
220 echo -e " first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out |
221 |
221 |
222 if (scala_assert "knight1.scala" "knight1_test4.scala") |
222 if (scala_assert "knight1.scala" "knight1_test4.scala") |
223 then |
223 then |
224 echo -e " --> success" | tee -a $out |
224 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
225 marks=$(( marks + 1.0 )) |
225 marks=$(( marks + 1.0 )) |
226 else |
226 else |
227 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
227 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
228 fi |
228 fi |
229 fi |
229 fi |
238 |
238 |
239 if (scala_assert_thirty "knight1.scala" "knight1_test5.scala") |
239 if (scala_assert_thirty "knight1.scala" "knight1_test5.scala") |
240 then |
240 then |
241 END=$(date +%s) |
241 END=$(date +%s) |
242 DIFF=$(( $END - $START )) |
242 DIFF=$(( $END - $START )) |
243 echo -e " This test ran for $DIFF seconds" | tee -a $out |
243 #echo -e " This test ran for $DIFF seconds" | tee -a $out |
244 echo -e " --> success" | tee -a $out |
244 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
245 marks=$(( marks + 1.0 )) |
245 marks=$(( marks + 1.0 )) |
246 else |
246 else |
247 END=$(date +%s) |
247 END=$(date +%s) |
248 DIFF=$(( $END - $START )) |
248 DIFF=$(( $END - $START )) |
249 echo -e " This test ran for $DIFF seconds" | tee -a $out |
249 echo -e " This test ran for $DIFF seconds" | tee -a $out |
298 echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out |
298 echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out |
299 echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out |
299 echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out |
300 |
300 |
301 if (scala_assert "knight2.scala" "knight2_test6.scala") |
301 if (scala_assert "knight2.scala" "knight2_test6.scala") |
302 then |
302 then |
303 echo -e " --> success" | tee -a $out |
303 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
304 marks=$(( marks + 1.0 )) |
304 marks=$(( marks + 1.0 )) |
305 else |
305 else |
306 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
306 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
307 fi |
307 fi |
308 fi |
308 fi |
317 |
317 |
318 if (scala_assert_thirty "knight2.scala" "knight2_test7.scala") |
318 if (scala_assert_thirty "knight2.scala" "knight2_test7.scala") |
319 then |
319 then |
320 END=$(date +%s) |
320 END=$(date +%s) |
321 DIFF=$(( $END - $START )) |
321 DIFF=$(( $END - $START )) |
322 echo -e " This test ran for $DIFF seconds" | tee -a $out |
322 #echo -e " This test ran for $DIFF seconds" | tee -a $out |
323 echo -e " --> success" | tee -a $out |
323 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
324 marks=$(( marks + 1.0 )) |
324 marks=$(( marks + 1.0 )) |
325 else |
325 else |
326 END=$(date +%s) |
326 END=$(date +%s) |
327 DIFF=$(( $END - $START )) |
327 DIFF=$(( $END - $START )) |
328 echo -e " This test ran for $DIFF seconds." | tee -a $out |
328 echo -e " This test ran for $DIFF seconds." | tee -a $out |
341 |
341 |
342 if (scala_assert_thirty "knight2.scala" "knight2_test8.scala") |
342 if (scala_assert_thirty "knight2.scala" "knight2_test8.scala") |
343 then |
343 then |
344 END=$(date +%s) |
344 END=$(date +%s) |
345 DIFF=$(( $END - $START )) |
345 DIFF=$(( $END - $START )) |
346 echo " This test ran for $DIFF seconds" | tee -a $out |
346 #echo " This test ran for $DIFF seconds" | tee -a $out |
347 echo -e " --> success" | tee -a $out |
347 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
348 marks=$(( marks + 1.0 )) |
348 marks=$(( marks + 1.0 )) |
349 else |
349 else |
350 END=$(date +%s) |
350 END=$(date +%s) |
351 DIFF=$(( $END - $START )) |
351 DIFF=$(( $END - $START )) |
352 echo " This test ran for $DIFF seconds." | tee -a $out |
352 echo " This test ran for $DIFF seconds." | tee -a $out |
397 |
397 |
398 if (scala_assert_thirty "knight3.scala" "knight3_test9.scala") |
398 if (scala_assert_thirty "knight3.scala" "knight3_test9.scala") |
399 then |
399 then |
400 END=$(date +%s) |
400 END=$(date +%s) |
401 DIFF=$(( $END - $START )) |
401 DIFF=$(( $END - $START )) |
402 echo -e " This test ran for $DIFF seconds." | tee -a $out |
402 #echo -e " This test ran for $DIFF seconds." | tee -a $out |
403 echo -e " --> success" | tee -a $out |
403 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
404 marks=$(( marks + 1.0 )) |
404 marks=$(( marks + 1.0 )) |
405 else |
405 else |
406 END=$(date +%s) |
406 END=$(date +%s) |
407 DIFF=$(( $END - $START )) |
407 DIFF=$(( $END - $START )) |
408 echo -e " This test ran for $DIFF seconds." | tee -a $out |
408 echo -e " This test ran for $DIFF seconds." | tee -a $out |
409 echo -e " --> TEST FAILED\n" | tee -a $out |
409 echo -e " --> TEST FAILED\n" | tee -a $out |
410 fi |
410 fi |
411 fi |
411 fi |
412 |
412 |
413 |
413 |
|
414 echo -e "" >> $out |
|
415 echo -e "Below is the feedback for your submission knight4.scala" >> $out |
|
416 echo -e "" >> $out |
|
417 |
|
418 # compilation test |
|
419 echo "knight4.scala runs?" | tee -a $out |
|
420 |
|
421 if (scala_compile knight4.scala) |
|
422 then |
|
423 echo " --> success" | tee -a $out |
|
424 tsts=$(( 0 )) |
|
425 else |
|
426 echo -e " --> SCALA DID NOT RUN knight3.scala\n" | tee -a $out |
|
427 tsts=$(( 1 )) |
|
428 fi |
|
429 |
|
430 |
|
431 # knights3: purity test |
|
432 # |
|
433 if [ $tsts -eq 0 ] |
|
434 then |
|
435 echo -e "knight4.scala does not contain VARS, RETURNS etc?" | tee -a $out |
|
436 |
|
437 if (scala_vars knight4.scala) |
|
438 then |
|
439 echo " --> TEST FAILED\n" | tee -a $out |
|
440 tsts=$(( 1 )) |
|
441 else |
|
442 echo " --> success" | tee -a $out |
|
443 tsts=$(( 0 )) |
|
444 fi |
|
445 else |
|
446 tsts=$(( 1 )) |
|
447 fi |
|
448 |
|
449 if [ $tsts -eq 0 ] |
|
450 then |
|
451 echo -e " one_tour_pred(8, List((0, 0)), 40, x => x._1 < 5) is ok?" | tee -a $out |
|
452 START=$(date +%s) |
|
453 |
|
454 if (scala_assert "knight4.scala" "knight4_test10.scala") |
|
455 then |
|
456 END=$(date +%s) |
|
457 DIFF=$(( $END - $START )) |
|
458 #echo -e " This test ran for $DIFF seconds." | tee -a $out |
|
459 echo -e " --> success (+ 2 Marks)\n" | tee -a $out |
|
460 marks=$(( marks + 2.0 )) |
|
461 else |
|
462 END=$(date +%s) |
|
463 DIFF=$(( $END - $START )) |
|
464 echo -e " This test ran for $DIFF seconds." | tee -a $out |
|
465 echo -e " --> \n ONE TEST FAILED\n" | tee -a $out |
|
466 fi |
|
467 fi |
|
468 |
|
469 |
414 ## final marks |
470 ## final marks |
415 echo -e "" >> $out |
471 echo -e "" >> $out |
416 echo -e "Overall mark for Main Part 4 (Scala)" | tee -a $out |
472 echo -e "Overall mark for Main Part 4 (Scala)" | tee -a $out |
417 printf " %0.2f\n" $marks | tee -a $out |
473 printf " %0.2f\n" $marks | tee -a $out |
418 |
474 |