|
1 #!/bin/zsh |
|
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 -e `date` >> $out |
|
12 echo -e "" >> $out |
|
13 echo -e "Below is the feedback and provisional marks for your submission" >> $out |
|
14 echo -e "of the Main Part 2 (Scala). Please note all marks are provisional until" >> $out |
|
15 echo -e "ratified by the assessment board -- this is not an official" >> $out |
|
16 echo -e "results transcript." >> $out |
|
17 echo -e "" >> $out |
|
18 |
|
19 # marks for core CW7 |
|
20 marks=$(( 0.0 )) |
|
21 |
|
22 echo -e "" >> $out |
|
23 echo -e "Below is the feedback for your submission danube.scala" >> $out |
|
24 echo -e "" >> $out |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 # compilation tests |
|
30 |
|
31 function scala_compile { |
|
32 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
|
33 } |
|
34 |
|
35 # functional tests |
|
36 |
|
37 function scala_assert { |
|
38 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
39 } |
|
40 |
|
41 function scala_assert_thirty { |
|
42 (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
43 } |
|
44 |
|
45 # purity test |
|
46 |
|
47 function scala_vars { |
|
48 (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) |
|
49 } |
|
50 |
|
51 |
|
52 ### compilation test |
|
53 |
|
54 echo -e "danube.scala runs?" | tee -a $out |
|
55 |
|
56 if (scala_compile danube.scala) |
|
57 then |
|
58 echo -e " --> success" | tee -a $out |
|
59 tsts=$(( 0 )) |
|
60 else |
|
61 echo -e " --> SCALA DID NOT RUN danube.scala" | tee -a $out |
|
62 tsts=$(( 1 )) |
|
63 fi |
|
64 |
|
65 |
|
66 # var, .par return, ListBuffer test |
|
67 # |
|
68 |
|
69 if [ $tsts -eq 0 ] |
|
70 then |
|
71 echo -e "danube.scala does not contain VARS, RETURNS etc?" | tee -a $out |
|
72 |
|
73 if (scala_vars danube.scala) |
|
74 then |
|
75 echo -e " --> TEST FAILED\n" | tee -a $out |
|
76 tsts=$(( 1 )) |
|
77 else |
|
78 echo -e " --> success" | tee -a $out |
|
79 tsts=$(( 0 )) |
|
80 fi |
|
81 else |
|
82 tsts=$(( 1 )) |
|
83 fi |
|
84 |
|
85 |
|
86 |
|
87 ### danube get_cvs_url tests |
|
88 |
|
89 if [ $tsts -eq 0 ] |
|
90 then |
|
91 echo -e "danube.scala tests:" | tee -a $out |
|
92 echo -e " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out |
|
93 echo -e " get_csv_url(movies_url).length == 9742" | tee -a $out |
|
94 |
|
95 if (scala_assert "danube.scala" "danube_test1.scala") |
|
96 then |
|
97 echo -e " --> success" | tee -a $out |
|
98 marks=$(( marks + 1.0 )) |
|
99 else |
|
100 echo -e " --> TEST FAILED\n" | tee -a $out |
|
101 fi |
|
102 fi |
|
103 |
|
104 ### danube processing tests |
|
105 |
|
106 if [ $tsts -eq 0 ] |
|
107 then |
|
108 echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out |
|
109 echo -e " val movie_names = process_movies(movies)" | tee -a $out |
|
110 echo -e " " | tee -a $out |
|
111 echo -e " good_ratings.length == 48580 " | tee -a $out |
|
112 echo -e " movie_names.length == 9742 " | tee -a $out |
|
113 |
|
114 if (scala_assert "danube.scala" "danube_test2.scala") |
|
115 then |
|
116 echo -e " --> success" | tee -a $out |
|
117 marks=$(( marks + 1.0 )) |
|
118 else |
|
119 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
120 fi |
|
121 fi |
|
122 |
|
123 ### danube groupById test |
|
124 |
|
125 if [ $tsts -eq 0 ] |
|
126 then |
|
127 echo -e " val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out |
|
128 echo -e " val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out |
|
129 echo -e " groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out |
|
130 echo -e " groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out |
|
131 echo -e " where the order in the lists is unimportant" | tee -a $out |
|
132 echo -e " val ls3 = (11 to 1000 by 5).map(_.toString).toList" | tee -a $out |
|
133 echo -e " val ls4 = ls3 zip ls3.tail" | tee -a $out |
|
134 echo -e " val ls5 = ls4 ::: ls4.reverse" | tee -a $out |
|
135 echo -e " groupById(ls5, Map()) == Map(11 -> List(16,16), 16 -> List(21,21), ....)" | tee -a $out |
|
136 |
|
137 if (scala_assert "danube.scala" "danube_test3.scala") |
|
138 then |
|
139 echo -e -e " --> success" | tee -a $out |
|
140 marks=$(( marks + 1.0 )) |
|
141 else |
|
142 echo -e -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
143 fi |
|
144 fi |
|
145 |
|
146 ### danube favourites tests |
|
147 |
|
148 if [ $tsts -eq 0 ] |
|
149 then |
|
150 echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out |
|
151 echo -e " val ratings_map = groupById(good_ratings, Map())" | tee -a $out |
|
152 echo -e " favourites(ratings_map, \"912\").length == 80 " | tee -a $out |
|
153 echo -e " favourites(ratings_map, \"858\").length == 158 " | tee -a $out |
|
154 echo -e " favourites(ratings_map, \"260\").length == 201 " | tee -a $out |
|
155 |
|
156 if (scala_assert "danube.scala" "danube_test4.scala") |
|
157 then |
|
158 echo -e " --> success" | tee -a $out |
|
159 marks=$(( marks + 1.0 )) |
|
160 else |
|
161 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
162 fi |
|
163 fi |
|
164 |
|
165 ### danube suggestions tests |
|
166 |
|
167 if [ $tsts -eq 0 ] |
|
168 then |
|
169 echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out |
|
170 echo -e " val ratings_map = groupById(good_ratings, Map())" | tee -a $out |
|
171 echo -e " suggestions(ratings_map, \"912\").length == 4110 " | tee -a $out |
|
172 echo -e " suggestions(ratings_map, \"858\").length == 4883 " | tee -a $out |
|
173 echo -e " suggestions(ratings_map, \"260\").length == 4970 " | tee -a $out |
|
174 |
|
175 if (scala_assert "danube.scala" "danube_test5.scala") |
|
176 then |
|
177 echo -e " --> success" | tee -a $out |
|
178 marks=$(( marks + 1.0 )) |
|
179 else |
|
180 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
181 fi |
|
182 fi |
|
183 |
|
184 ### danube recommendation tests |
|
185 |
|
186 if [ $tsts -eq 0 ] |
|
187 then |
|
188 echo -e " recommendations(ratings_map, movies_map, \"1\").length == 2 " | tee -a $out |
|
189 echo -e " recommendations(ratings_map, movies_map, \"2\").length == 2 " | tee -a $out |
|
190 echo -e " recommendations(ratings_map, movies_map, \"3\").length == 2 " | tee -a $out |
|
191 echo -e " recommendations(ratings_map, movies_map, \"4\").length == 0 " | tee -a $out |
|
192 echo -e " recommendations(ratings_map, movies_map, \"5\").length == 2 " | tee -a $out |
|
193 |
|
194 if (scala_assert "danube.scala" "danube_test6.scala") |
|
195 then |
|
196 echo -e " --> success" | tee -a $out |
|
197 marks=$(( marks + 1.0 )) |
|
198 else |
|
199 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
200 fi |
|
201 fi |
|
202 |
|
203 ### danube most_recommended 1 |
|
204 gd=$(( 0 )) |
|
205 |
|
206 if [ $tsts -eq 0 ] |
|
207 then |
|
208 echo -e " val rmap = Map(\"1\" -> List(\"b\", \"a\"), " | tee -a $out |
|
209 echo -e " \"2\" -> List(\"y\", \"x\"), " | tee -a $out |
|
210 echo -e " \"3\" -> List(\"c\", \"a\")) " | tee -a $out |
|
211 echo -e " val nmap = Map(\"a\" -> \"A\", \"b\" -> \"B\", \"c\" -> \"C\", " | tee -a $out |
|
212 echo -e " \"x\" -> \"X\", \"y\" -> \"Y\") " | tee -a $out |
|
213 echo -e " most_recommended(rmap, nmap).toSet == " | tee -a $out |
|
214 echo -e " Set((\"A\",2), (\"B\",1), (\"C\",1), (\"X\",1), (\"Y\",1)) " | tee -a $out |
|
215 |
|
216 if (scala_assert "danube.scala" "danube_test7a.scala") |
|
217 then |
|
218 echo -e " --> success (0.5% Marks)" | tee -a $out |
|
219 marks=$(( marks + 0.5 )) |
|
220 else |
|
221 echo -e " --> TEST FAILED\n" | tee -a $out |
|
222 gd=$(( 1 )) |
|
223 fi |
|
224 fi |
|
225 |
|
226 ### danube most_recommended 2 |
|
227 |
|
228 sleep 10 |
|
229 |
|
230 if [ $gd -eq 0 ] |
|
231 then |
|
232 if [ $tsts -eq 0 ] |
|
233 then |
|
234 echo -e " most_recommended(ratings_map, movie_map) runs within allocated time? " | tee -a $out |
|
235 START=$(date +%s) |
|
236 |
|
237 if (scala_assert_thirty "danube.scala" "danube_test7b.scala") |
|
238 then |
|
239 END=$(date +%s) |
|
240 DIFF=$(( $END - $START )) |
|
241 echo " This test ran for $DIFF seconds." | tee -a $out |
|
242 echo -e " --> success (0.5% Marks)" | tee -a $out |
|
243 marks=$(( marks + 0.5 )) |
|
244 else |
|
245 END=$(date +%s) |
|
246 DIFF=$(( $END - $START )) |
|
247 echo " This test ran for $DIFF seconds." | tee -a $out |
|
248 echo -e " --> TEST FAILED\n" | tee -a $out |
|
249 fi |
|
250 fi |
|
251 fi |
|
252 |
|
253 sleep 10 |
|
254 |
|
255 |
|
256 ## final marks |
|
257 echo -e "Overall mark for Main Part 2 (Scala)" | tee -a $out |
|
258 printf " %0.1f\n" $marks | tee -a $out |
|
259 |
|
260 |