|
1 #!/bin/bash |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 |
|
7 out=${1:-output} |
|
8 |
|
9 # read marks for CW7 part 1 |
|
10 marks=$(( `tail -1 $out` )) |
|
11 |
|
12 echo $marks |
|
13 |
|
14 echo "" >> $out |
|
15 |
|
16 echo "Below is the feedback for your submission danube.scala" >> $out |
|
17 echo "" >> $out |
|
18 |
|
19 |
|
20 # compilation tests |
|
21 |
|
22 function scala_compile { |
|
23 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
|
24 } |
|
25 |
|
26 # functional tests |
|
27 |
|
28 function scala_assert { |
|
29 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 } |
|
31 |
|
32 # purity test |
|
33 |
|
34 function scala_vars { |
|
35 (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
|
36 } |
|
37 |
|
38 |
|
39 # var, .par return, ListBuffer test |
|
40 # |
|
41 echo "danube.scala does not contain vars, returns etc?" | tee -a $out |
|
42 |
|
43 if (scala_vars danube.scala) |
|
44 then |
|
45 echo " --> test failed" | tee -a $out |
|
46 tsts0=$(( 1 )) |
|
47 echo " --> fail (make triple-sure your program conforms to the required format)" | tee -a $out |
|
48 tsts0=$(( 0 )) |
|
49 else |
|
50 echo " --> success" | tee -a $out |
|
51 tsts0=$(( 0 )) |
|
52 fi |
|
53 |
|
54 ### compilation test |
|
55 |
|
56 |
|
57 if [ $tsts0 -eq 0 ] |
|
58 then |
|
59 echo "danube.scala runs?" | tee -a $out |
|
60 |
|
61 if (scala_compile danube.scala) |
|
62 then |
|
63 echo " --> success" | tee -a $out |
|
64 tsts=$(( 0 )) |
|
65 else |
|
66 echo " --> scala did not run danube.scala" | tee -a $out |
|
67 tsts=$(( 1 )) |
|
68 fi |
|
69 else |
|
70 tsts=$(( 1 )) |
|
71 fi |
|
72 |
|
73 ### danube get_cvs_url tests |
|
74 |
|
75 if [ $tsts -eq 0 ] |
|
76 then |
|
77 echo "danube.scala tests:" | tee -a $out |
|
78 echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out |
|
79 echo " get_csv_url(movies_url).length == 9742" | tee -a $out |
|
80 |
|
81 if (scala_assert "danube.scala" "danube_test1.scala") |
|
82 then |
|
83 echo " --> success" | tee -a $out |
|
84 marks=$(( marks + 1 )) |
|
85 else |
|
86 echo " --> one of the tests failed" | tee -a $out |
|
87 fi |
|
88 fi |
|
89 |
|
90 ### danube processing tests |
|
91 |
|
92 if [ $tsts -eq 0 ] |
|
93 then |
|
94 echo " val good_ratings = process_ratings(ratings)" | tee -a $out |
|
95 echo " val movie_names = process_movies(movies)" | tee -a $out |
|
96 echo " " | tee -a $out |
|
97 echo " good_ratings.length == 48580 " | tee -a $out |
|
98 echo " movie_names.length == 9742 " | tee -a $out |
|
99 |
|
100 if (scala_assert "danube.scala" "danube_test2.scala") |
|
101 then |
|
102 echo " --> success" | tee -a $out |
|
103 marks=$(( marks + 1 )) |
|
104 else |
|
105 echo " --> one of the tests failed" | tee -a $out |
|
106 fi |
|
107 fi |
|
108 |
|
109 |
|
110 |
|
111 ## final marks |
|
112 echo "Overall mark for CW 7, Part 1 + 2" | tee -a $out |
|
113 echo "$marks" | tee -a $out |
|
114 |
|
115 |