227
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
|
|
7 |
out=${1:-output}
|
|
8 |
|
284
|
9 |
|
264
|
10 |
|
284
|
11 |
echo -e "" > $out
|
264
|
12 |
|
284
|
13 |
echo -e "Below is the feedback and provisional marks for your submission" >> $out
|
|
14 |
echo -e "for core assignment 7. 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
|
227
|
18 |
|
284
|
19 |
echo -e "Below is the feedback for your submission danube.scala" >> $out
|
|
20 |
echo -e "" >> $out
|
|
21 |
|
|
22 |
# marks for core CW7
|
|
23 |
marks=$(( 0 ))
|
227
|
24 |
|
|
25 |
|
|
26 |
# compilation tests
|
|
27 |
|
|
28 |
function scala_compile {
|
283
|
29 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
227
|
30 |
}
|
|
31 |
|
|
32 |
# functional tests
|
|
33 |
|
|
34 |
function scala_assert {
|
284
|
35 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
227
|
36 |
}
|
|
37 |
|
|
38 |
# purity test
|
|
39 |
|
|
40 |
function scala_vars {
|
264
|
41 |
(egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
|
227
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
# var, .par return, ListBuffer test
|
|
46 |
#
|
284
|
47 |
echo -e "danube.scala does not contain vars, returns etc?" | tee -a $out
|
227
|
48 |
|
|
49 |
if (scala_vars danube.scala)
|
|
50 |
then
|
284
|
51 |
echo -e " --> test failed" | tee -a $out
|
264
|
52 |
tsts0=$(( 1 ))
|
227
|
53 |
else
|
284
|
54 |
echo -e " --> success" | tee -a $out
|
227
|
55 |
tsts0=$(( 0 ))
|
|
56 |
fi
|
|
57 |
|
|
58 |
### compilation test
|
|
59 |
|
|
60 |
|
|
61 |
if [ $tsts0 -eq 0 ]
|
|
62 |
then
|
284
|
63 |
echo -e "danube.scala runs?" | tee -a $out
|
227
|
64 |
|
|
65 |
if (scala_compile danube.scala)
|
|
66 |
then
|
284
|
67 |
echo -e " --> success" | tee -a $out
|
227
|
68 |
tsts=$(( 0 ))
|
|
69 |
else
|
284
|
70 |
echo -e " --> SCALA DID NOT RUN danube.scala" | tee -a $out
|
227
|
71 |
tsts=$(( 1 ))
|
|
72 |
fi
|
|
73 |
else
|
|
74 |
tsts=$(( 1 ))
|
|
75 |
fi
|
|
76 |
|
|
77 |
### danube get_cvs_url tests
|
|
78 |
|
|
79 |
if [ $tsts -eq 0 ]
|
|
80 |
then
|
284
|
81 |
echo -e "danube.scala tests:" | tee -a $out
|
|
82 |
echo -e " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
|
|
83 |
echo -e " get_csv_url(movies_url).length == 9742" | tee -a $out
|
227
|
84 |
|
|
85 |
if (scala_assert "danube.scala" "danube_test1.scala")
|
|
86 |
then
|
284
|
87 |
echo -e " --> success" | tee -a $out
|
264
|
88 |
marks=$(( marks + 1 ))
|
227
|
89 |
else
|
284
|
90 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
227
|
91 |
fi
|
|
92 |
fi
|
|
93 |
|
|
94 |
### danube processing tests
|
|
95 |
|
|
96 |
if [ $tsts -eq 0 ]
|
|
97 |
then
|
284
|
98 |
echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out
|
|
99 |
echo -e " val movie_names = process_movies(movies)" | tee -a $out
|
|
100 |
echo -e " " | tee -a $out
|
|
101 |
echo -e " good_ratings.length == 48580 " | tee -a $out
|
|
102 |
echo -e " movie_names.length == 9742 " | tee -a $out
|
227
|
103 |
|
|
104 |
if (scala_assert "danube.scala" "danube_test2.scala")
|
|
105 |
then
|
284
|
106 |
echo -e " --> success" | tee -a $out
|
|
107 |
marks=$(( marks + 1 ))
|
|
108 |
else
|
|
109 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
110 |
fi
|
|
111 |
fi
|
|
112 |
|
|
113 |
### danube groupById test
|
|
114 |
|
|
115 |
if [ $tsts -eq 0 ]
|
|
116 |
then
|
|
117 |
echo -e " val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
|
|
118 |
echo -e " val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
|
|
119 |
echo -e " groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
|
|
120 |
echo -e " groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
|
|
121 |
echo -e " where the order in the lists is unimportant" | tee -a $out
|
|
122 |
echo -e " val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
|
|
123 |
echo -e " val ls4 = ls3 zip ls3.tail" | tee -a $out
|
|
124 |
echo -e " val ls5 = ls4 ::: ls4.reverse" | tee -a $out
|
|
125 |
echo -e " groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
|
|
126 |
|
|
127 |
if (scala_assert "danube.scala" "danube_test3.scala")
|
|
128 |
then
|
|
129 |
echo -e -e " --> success" | tee -a $out
|
264
|
130 |
marks=$(( marks + 1 ))
|
227
|
131 |
else
|
284
|
132 |
echo -e -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
133 |
fi
|
|
134 |
fi
|
|
135 |
|
|
136 |
### danube favourites tests
|
|
137 |
|
|
138 |
if [ $tsts -eq 0 ]
|
|
139 |
then
|
|
140 |
echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out
|
|
141 |
echo -e " val ratings_map = groupById(good_ratings, Map())" | tee -a $out
|
|
142 |
echo -e " favourites(ratings_map, \"912\").length == 80 " | tee -a $out
|
|
143 |
echo -e " favourites(ratings_map, \"858\").length == 158 " | tee -a $out
|
|
144 |
echo -e " favourites(ratings_map, \"260\").length == 201 " | tee -a $out
|
|
145 |
|
|
146 |
if (scala_assert "danube.scala" "danube_test4.scala")
|
|
147 |
then
|
|
148 |
echo -e " --> success" | tee -a $out
|
|
149 |
marks=$(( marks + 1 ))
|
|
150 |
else
|
|
151 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
152 |
fi
|
|
153 |
fi
|
|
154 |
|
|
155 |
### danube suggestions tests
|
|
156 |
|
|
157 |
if [ $tsts -eq 0 ]
|
|
158 |
then
|
|
159 |
echo -e " val good_ratings = process_ratings(ratings)" | tee -a $out
|
|
160 |
echo -e " val ratings_map = groupById(good_ratings, Map())" | tee -a $out
|
|
161 |
echo -e " suggestions(ratings_map, \"912\").length == 4110 " | tee -a $out
|
|
162 |
echo -e " suggestions(ratings_map, \"858\").length == 4883 " | tee -a $out
|
|
163 |
echo -e " suggestions(ratings_map, \"260\").length == 4970 " | tee -a $out
|
|
164 |
|
|
165 |
if (scala_assert "danube.scala" "danube_test5.scala")
|
|
166 |
then
|
|
167 |
echo -e " --> success" | tee -a $out
|
|
168 |
marks=$(( marks + 1 ))
|
|
169 |
else
|
|
170 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
171 |
fi
|
|
172 |
fi
|
|
173 |
|
|
174 |
### danube recommendation tests
|
|
175 |
|
|
176 |
if [ $tsts -eq 0 ]
|
|
177 |
then
|
|
178 |
echo -e " recommendations(ratings_map, movies_map, \"1\").length == 2 " | tee -a $out
|
|
179 |
echo -e " recommendations(ratings_map, movies_map, \"2\").length == 2 " | tee -a $out
|
|
180 |
echo -e " recommendations(ratings_map, movies_map, \"3\").length == 2 " | tee -a $out
|
|
181 |
echo -e " recommendations(ratings_map, movies_map, \"4\").length == 0 " | tee -a $out
|
|
182 |
echo -e " recommendations(ratings_map, movies_map, \"5\").length == 2 " | tee -a $out
|
|
183 |
|
|
184 |
if (scala_assert "danube.scala" "danube_test6.scala")
|
|
185 |
then
|
|
186 |
echo -e " --> success" | tee -a $out
|
|
187 |
marks=$(( marks + 1 ))
|
|
188 |
else
|
|
189 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
227
|
190 |
fi
|
|
191 |
fi
|
|
192 |
|
264
|
193 |
|
|
194 |
|
|
195 |
## final marks
|
284
|
196 |
echo -e "Overall mark for CW 7 Core Part" | tee -a $out
|
|
197 |
echo -e "$marks" | tee -a $out
|
264
|
198 |
|
|
199 |
|