equal
deleted
inserted
replaced
2 |
2 |
3 # to make the script fail safely |
3 # to make the script fail safely |
4 set -euo pipefail |
4 set -euo pipefail |
5 |
5 |
6 |
6 |
7 out=${1:-output} |
7 |
|
8 scalafile=${1:-danube.scala} |
|
9 out=${2:-output} |
|
10 |
|
11 |
8 |
12 |
9 echo "" > $out |
13 echo "" > $out |
10 |
14 |
11 echo "Below is the feedback for your submission danube.scala" >> $out |
15 echo "Below is the feedback for your submission danube.scala" >> $out |
12 echo "" >> $out |
16 echo "" >> $out |
34 |
38 |
35 ### compilation test |
39 ### compilation test |
36 |
40 |
37 echo "danube.scala runs?" >> $out |
41 echo "danube.scala runs?" >> $out |
38 |
42 |
39 if (scala_compile danube.scala) |
43 if (scala_compile $scalafile) |
40 then |
44 then |
41 echo " --> passed" >> $out |
45 echo " --> passed" >> $out |
42 tsts=$(( 0 )) |
46 tsts=$(( 0 )) |
43 else |
47 else |
44 echo " --> SCALA DID NOT RUN danube.scala" >> $out |
48 echo " --> SCALA DID NOT RUN danube.scala" >> $out |
50 |
54 |
51 if [ $tsts -eq 0 ] |
55 if [ $tsts -eq 0 ] |
52 then |
56 then |
53 echo "danube.scala does not contain vars, returns etc?" >> $out |
57 echo "danube.scala does not contain vars, returns etc?" >> $out |
54 |
58 |
55 if (scala_vars danube.scala) |
59 if (scala_vars $scalafile) |
56 then |
60 then |
57 echo " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
61 echo " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
58 tsts=$(( 1 )) |
62 tsts=$(( 1 )) |
59 else |
63 else |
60 echo " --> passed" >> $out |
64 echo " --> passed" >> $out |
69 then |
73 then |
70 echo "danube.scala tests:" >> $out |
74 echo "danube.scala tests:" >> $out |
71 echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out |
75 echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out |
72 echo " get_csv_url(movies_url).length == 9742" >> $out |
76 echo " get_csv_url(movies_url).length == 9742" >> $out |
73 |
77 |
74 if (scala_assert "danube.scala" "danube_test1.scala") |
78 if (scala_assert $scalafile "danube_test1.scala") |
75 then |
79 then |
76 echo -e " --> success" >> $out |
80 echo -e " --> success" >> $out |
77 else |
81 else |
78 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
82 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
79 fi |
83 fi |
86 echo " val good_ratings = process_ratings(ratings)" >> $out |
90 echo " val good_ratings = process_ratings(ratings)" >> $out |
87 echo " val movie_names = process_movies(movies)" >> $out |
91 echo " val movie_names = process_movies(movies)" >> $out |
88 echo " " >> $out |
92 echo " " >> $out |
89 echo " good_ratings.length == 48580 " >> $out |
93 echo " good_ratings.length == 48580 " >> $out |
90 echo " movie_names.length == 9742 " >> $out |
94 echo " movie_names.length == 9742 " >> $out |
|
95 echo " " >> $out |
|
96 echo " val r_elems = List((\"1\",\"1\"), (\"1\",\"3\"), (\"1\",\"6\"), (\"1\",\"47\")) " >> $out |
|
97 echo " r_elems.forall(good_ratings.contains(_)) == true" >> $out |
91 |
98 |
92 if (scala_assert "danube.scala" "danube_test2.scala") |
99 if (scala_assert $scalafile "danube_test2.scala") |
93 then |
100 then |
94 echo -e " --> success" >> $out |
101 echo -e " --> success" >> $out |
95 else |
102 else |
96 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
103 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
97 fi |
104 fi |
109 echo -e " val ls3 = (1 to 1000).map(_.toString).toList" >> $out |
116 echo -e " val ls3 = (1 to 1000).map(_.toString).toList" >> $out |
110 echo -e " val ls4 = ls3 zip ls3.tail" >> $out |
117 echo -e " val ls4 = ls3 zip ls3.tail" >> $out |
111 echo -e " val ls5 = ls4 ::: ls4.reverse" >> $out |
118 echo -e " val ls5 = ls4 ::: ls4.reverse" >> $out |
112 echo -e " groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" >> $out |
119 echo -e " groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" >> $out |
113 |
120 |
114 if (scala_assert "danube.scala" "danube_test3.scala") |
121 if (scala_assert $scalafile "danube_test3.scala") |
115 then |
122 then |
116 echo -e " --> success" >> $out |
123 echo -e " --> success" >> $out |
117 else |
124 else |
118 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
125 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
119 fi |
126 fi |
127 echo -e " val ratings_map = groupById(good_ratings, Map())" >> $out |
134 echo -e " val ratings_map = groupById(good_ratings, Map())" >> $out |
128 echo -e " favourites(ratings_map, \"912\").length == 80 " >> $out |
135 echo -e " favourites(ratings_map, \"912\").length == 80 " >> $out |
129 echo -e " favourites(ratings_map, \"858\").length == 158 " >> $out |
136 echo -e " favourites(ratings_map, \"858\").length == 158 " >> $out |
130 echo -e " favourites(ratings_map, \"260\").length == 201 " >> $out |
137 echo -e " favourites(ratings_map, \"260\").length == 201 " >> $out |
131 |
138 |
132 if (scala_assert "danube.scala" "danube_test4.scala") |
139 if (scala_assert $scalafile "danube_test4.scala") |
133 then |
140 then |
134 echo -e " --> success" >> $out |
141 echo -e " --> success" >> $out |
135 else |
142 else |
136 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
143 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
137 fi |
144 fi |
145 echo -e " val ratings_map = groupById(good_ratings, Map())" >> $out |
152 echo -e " val ratings_map = groupById(good_ratings, Map())" >> $out |
146 echo -e " suggestions(ratings_map, \"912\").length == 4110 " >> $out |
153 echo -e " suggestions(ratings_map, \"912\").length == 4110 " >> $out |
147 echo -e " suggestions(ratings_map, \"858\").length == 4883 " >> $out |
154 echo -e " suggestions(ratings_map, \"858\").length == 4883 " >> $out |
148 echo -e " suggestions(ratings_map, \"260\").length == 4970 " >> $out |
155 echo -e " suggestions(ratings_map, \"260\").length == 4970 " >> $out |
149 |
156 |
150 if (scala_assert "danube.scala" "danube_test5.scala") |
157 if (scala_assert $scalafile "danube_test5.scala") |
151 then |
158 then |
152 echo -e " --> success" >> $out |
159 echo -e " --> success" >> $out |
153 else |
160 else |
154 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
161 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
155 fi |
162 fi |
163 echo -e " recommendations(ratings_map, movies_map, \"2\").length == 2 " >> $out |
170 echo -e " recommendations(ratings_map, movies_map, \"2\").length == 2 " >> $out |
164 echo -e " recommendations(ratings_map, movies_map, \"3\").length == 2 " >> $out |
171 echo -e " recommendations(ratings_map, movies_map, \"3\").length == 2 " >> $out |
165 echo -e " recommendations(ratings_map, movies_map, \"4\").length == 0 " >> $out |
172 echo -e " recommendations(ratings_map, movies_map, \"4\").length == 0 " >> $out |
166 echo -e " recommendations(ratings_map, movies_map, \"5\").length == 2 " >> $out |
173 echo -e " recommendations(ratings_map, movies_map, \"5\").length == 2 " >> $out |
167 |
174 |
168 if (scala_assert "danube.scala" "danube_test6.scala") |
175 if (scala_assert $scalafile "danube_test6.scala") |
169 then |
176 then |
170 echo -e " --> success" >> $out |
177 echo -e " --> success" >> $out |
171 else |
178 else |
172 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
179 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
173 fi |
180 fi |