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