|
1 #!/bin/zsh |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 out=${1:-output} |
|
7 |
|
8 echo "" > $out |
|
9 |
|
10 echo `date` >> $out |
|
11 echo -e "Below is the feedback and provisional marks for your submission" >> $out |
|
12 echo -e "of the Preliminary Part of Part 4 (Scala). Please note all marks are provisional until" >> $out |
|
13 echo -e "ratified by the assessment board -- this is not an official" >> $out |
|
14 echo -e "results transcript." >> $out |
|
15 echo -e "" >> $out |
|
16 |
|
17 echo -e "Below is the feedback for your submission knight1.scala" >> $out |
|
18 echo -e "" >> $out |
|
19 |
|
20 |
|
21 |
|
22 # marks for CW8 part 1 |
|
23 marks=$(( 0.0 )) |
|
24 |
|
25 |
|
26 function scala_compile { |
|
27 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1") # 2>> $out 1>> $out) |
|
28 } |
|
29 |
|
30 # functional tests |
|
31 |
|
32 function scala_compile { |
|
33 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
|
34 } |
|
35 |
|
36 # functional tests |
|
37 |
|
38 function scala_assert { |
|
39 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
40 } |
|
41 |
|
42 function scala_assert_slow { |
|
43 (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
44 } |
|
45 |
|
46 function scala_assert_thirty { |
|
47 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
48 } |
|
49 |
|
50 function scala_assert_quick { |
|
51 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
52 } |
|
53 |
|
54 function scala_assert_long { |
|
55 (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
56 } |
|
57 |
|
58 function scala_assert_elong { |
|
59 (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
60 } |
|
61 |
|
62 # purity test |
|
63 |
|
64 |
|
65 function scala_vars { |
|
66 (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) |
|
67 } |
|
68 |
|
69 |
|
70 # compilation test |
|
71 |
|
72 echo -e "knight1.scala runs?" | tee -a $out |
|
73 |
|
74 if (scala_compile knight1.scala) |
|
75 then |
|
76 echo -e " --> success " | tee -a $out |
|
77 tsts=$(( 0 )) |
|
78 else |
|
79 echo -e " --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out |
|
80 tsts=$(( 1 )) |
|
81 fi |
|
82 |
|
83 |
|
84 # knights1: purity test |
|
85 if [ $tsts -eq 0 ] |
|
86 then |
|
87 echo -e "knight1.scala does not contain VARS, RETURNS etc?" | tee -a $out |
|
88 |
|
89 if (scala_vars knight1.scala) |
|
90 then |
|
91 echo -e " --> FAIL\n" | tee -a $out |
|
92 tsts=$(( 1 )) |
|
93 else |
|
94 echo -e " --> success" | tee -a $out |
|
95 tsts=$(( 0 )) |
|
96 fi |
|
97 else |
|
98 tsts=$(( 1 )) |
|
99 fi |
|
100 |
|
101 |
|
102 |
|
103 ### knight1 test |
|
104 |
|
105 if [ $tsts -eq 0 ] |
|
106 then |
|
107 echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out |
|
108 echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out |
|
109 echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out |
|
110 |
|
111 if (scala_assert "knight1.scala" "knight1_test1.scala") |
|
112 then |
|
113 echo -e " --> success" | tee -a $out |
|
114 marks=$(( marks + 1.0 )) |
|
115 else |
|
116 echo -e " --> \n ONE TEST FAILED\n"| tee -a $out |
|
117 fi |
|
118 fi |
|
119 |
|
120 ### knight2 test |
|
121 |
|
122 if [ $tsts -eq 0 ] |
|
123 then |
|
124 echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" | tee -a $out |
|
125 echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out |
|
126 echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" | tee -a $out |
|
127 echo " legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0))" | tee -a $out |
|
128 echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out |
|
129 echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out |
|
130 echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out |
|
131 echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out |
|
132 |
|
133 if (scala_assert "knight1.scala" "knight1_test2.scala") |
|
134 then |
|
135 echo -e " --> success\n" | tee -a $out |
|
136 marks=$(( marks + 1 )) |
|
137 else |
|
138 echo -e " --> ONE TEST FAILED\n" | tee -a $out |
|
139 fi |
|
140 fi |
|
141 |
|
142 |
|
143 ### knight3 test |
|
144 |
|
145 if [ $tsts -eq 0 ] |
|
146 then |
|
147 echo " count_tours from every position on the board 1 - 4" | tee -a $out |
|
148 echo " dim = 1: 1" | tee -a $out |
|
149 echo " 2: 0,0,0,0" | tee -a $out |
|
150 echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out |
|
151 echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out |
|
152 START=$(date +%s) |
|
153 |
|
154 if (scala_assert "knight1.scala" "knight1_test3a.scala") |
|
155 then |
|
156 END=$(date +%s) |
|
157 DIFF=$(( $END - $START )) |
|
158 echo " It took $DIFF seconds" | tee -a $out |
|
159 echo -e " --> success\n" | tee -a $out |
|
160 marks=$(( marks + 0.5 )) |
|
161 else |
|
162 END=$(date +%s) |
|
163 DIFF=$(( $END - $START )) |
|
164 echo " It took $DIFF seconds" | tee -a $out |
|
165 echo -e " --> ONE TEST FAILED\n" | tee -a $out |
|
166 fi |
|
167 fi |
|
168 |
|
169 |
|
170 if [ $tsts -eq 0 ] |
|
171 then |
|
172 echo " count_tours from every position on the board of dim 5" | tee -a $out |
|
173 echo " dim = 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" | tee -a $out |
|
174 START=$(date +%s) |
|
175 |
|
176 if (scala_assert "knight1.scala" "knight1_test3b.scala") |
|
177 then |
|
178 END=$(date +%s) |
|
179 DIFF=$(( $END - $START )) |
|
180 echo " It took $DIFF seconds" | tee -a $out |
|
181 echo -e " --> success\n" | tee -a $out |
|
182 marks=$(( marks + 0.5 )) |
|
183 else |
|
184 END=$(date +%s) |
|
185 DIFF=$(( $END - $START )) |
|
186 echo " It took $DIFF seconds" | tee -a $out |
|
187 echo -e " --> ONE TEST FAILED\n" | tee -a $out |
|
188 fi |
|
189 fi |
|
190 |
|
191 |
|
192 if [ $tsts -eq 0 ] |
|
193 then |
|
194 echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out |
|
195 echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out |
|
196 START=$(date +%s) |
|
197 |
|
198 if (scala_assert "knight1.scala" "knight1_test3c.scala") |
|
199 then |
|
200 END=$(date +%s) |
|
201 DIFF=$(( $END - $START )) |
|
202 echo " It took $DIFF seconds" | tee -a $out |
|
203 echo -e " --> success\n" | tee -a $out |
|
204 marks=$(( marks + 1.0 )) |
|
205 else |
|
206 END=$(date +%s) |
|
207 DIFF=$(( $END - $START )) |
|
208 echo " It took $DIFF seconds" | tee -a $out |
|
209 echo -e " --> \n ONE TEST FAILED\n" | tee -a $out |
|
210 fi |
|
211 fi |
|
212 |
|
213 |
|
214 ## final marks |
|
215 echo -e "Overall mark for the Preliminary Part 4 (Scala)" | tee -a $out |
|
216 printf " %0.1f\n" $marks | tee -a $out |
|
217 |
|
218 |