1 #!/bin/bash |
|
2 set -e |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo "" > $out |
|
7 |
|
8 echo "Below is the feedback for your submission of CW 7, Part 3." >> $out |
|
9 echo "" >> $out |
|
10 |
|
11 function scala_vars { |
|
12 (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
|
13 } |
|
14 |
|
15 # compilation tests |
|
16 |
|
17 function scala_compile { |
|
18 (ulimit -t 30 ; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
|
19 } |
|
20 |
|
21 # functional tests |
|
22 |
|
23 # not sure yet what the right kind of stack should be |
|
24 |
|
25 function scala_assert { |
|
26 (ulimit -t 20 ; JAVA_OPTS="-Xmx1g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
27 } |
|
28 |
|
29 # purity test |
|
30 |
|
31 function scala_vars { |
|
32 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
33 } |
|
34 |
|
35 |
|
36 # knights3: purity test |
|
37 # |
|
38 echo "knight3.scala does not contain vars, returns etc?" >> $out |
|
39 |
|
40 if (scala_vars knight3.scala) |
|
41 then |
|
42 echo " --> fail: if you do not fix this, you will receive a mark of zero" >> $out |
|
43 tsts0=$(( 1 )) |
|
44 else |
|
45 echo " --> success" >> $out |
|
46 tsts0=$(( 0 )) |
|
47 fi |
|
48 |
|
49 |
|
50 # compilation test |
|
51 if [ $tsts0 -eq 0 ] |
|
52 then |
|
53 echo "knight3.scala runs?" >> $out |
|
54 |
|
55 if (scala_compile knight3.scala) |
|
56 then |
|
57 echo " --> success" >> $out |
|
58 tsts1=$(( 0 )) |
|
59 else |
|
60 echo " --> scala knight3.scala did not run successfully" >> $out |
|
61 tsts1=$(( 1 )) |
|
62 fi |
|
63 else |
|
64 tsts1=$(( 1 )) |
|
65 fi |
|
66 |
|
67 # ordered move test |
|
68 |
|
69 if [ $tsts1 -eq 0 ] |
|
70 then |
|
71 echo "Takes 20 seconds or less to execute: " >> $out |
|
72 echo " ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out |
|
73 echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out |
|
74 echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out |
|
75 |
|
76 if (scala_assert "knight3.scala" "knight3a_test.scala") |
|
77 then |
|
78 echo " --> success" >> $out |
|
79 else |
|
80 echo " --> test failed" >> $out |
|
81 fi |
|
82 fi |
|
83 |
|
84 |
|
85 # first-closed-tour test |
|
86 |
|
87 if [ $tsts1 -eq 0 ] |
|
88 then |
|
89 echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" >> $out |
|
90 |
|
91 if (scala_assert "knight3.scala" "knight3b_test.scala") |
|
92 then |
|
93 echo " --> success" >> $out |
|
94 else |
|
95 echo " --> test failed" >> $out |
|
96 fi |
|
97 fi |
|
98 |
|
99 |
|
100 |
|
101 if [ $tsts1 -eq 0 ] |
|
102 then |
|
103 echo "Takes 20 seconds or less to execute: " >> $out |
|
104 echo " first_tour_heuristic(8, List((0,0))) found and ok?" >> $out |
|
105 echo " first_tour_heuristic(40, List((0,0))) found and ok?" >> $out |
|
106 |
|
107 if (scala_assert "knight3.scala" "knight3c_test.scala") |
|
108 then |
|
109 echo " --> success" >> $out |
|
110 else |
|
111 echo " --> test failed" >> $out |
|
112 fi |
|
113 fi |
|
114 |
|
115 |
|
116 ## final marks |
|
117 ##echo "Overall mark for CW 7, Part 2" | tee -a $out |
|
118 ##echo "$marks" | tee -a $out |
|