227
|
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 {
|
228
|
23 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out)
|
227
|
24 |
}
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
|
28 |
function scala_assert {
|
228
|
29 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
227
|
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 |
else
|
|
48 |
echo " --> success" | tee -a $out
|
|
49 |
tsts0=$(( 0 ))
|
|
50 |
fi
|
|
51 |
|
|
52 |
### compilation test
|
|
53 |
|
|
54 |
|
|
55 |
if [ $tsts0 -eq 0 ]
|
|
56 |
then
|
|
57 |
echo "danube.scala runs?" | tee -a $out
|
|
58 |
|
|
59 |
if (scala_compile danube.scala)
|
|
60 |
then
|
|
61 |
echo " --> success" | tee -a $out
|
|
62 |
tsts=$(( 0 ))
|
|
63 |
else
|
|
64 |
echo " --> scala did not run danube.scala" | tee -a $out
|
|
65 |
tsts=$(( 1 ))
|
|
66 |
fi
|
|
67 |
else
|
|
68 |
tsts=$(( 1 ))
|
|
69 |
fi
|
|
70 |
|
|
71 |
### danube get_cvs_url tests
|
|
72 |
|
|
73 |
if [ $tsts -eq 0 ]
|
|
74 |
then
|
|
75 |
echo "danube.scala tests:" | tee -a $out
|
|
76 |
echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
|
|
77 |
echo " get_csv_url(movies_url).length == 9742" | tee -a $out
|
|
78 |
|
|
79 |
if (scala_assert "danube.scala" "danube_test1.scala")
|
|
80 |
then
|
|
81 |
echo " --> success" | tee -a $out
|
|
82 |
marks=$(( marks + 1 ))
|
|
83 |
else
|
|
84 |
echo " --> one of the tests failed" | tee -a $out
|
|
85 |
fi
|
|
86 |
fi
|
|
87 |
|
|
88 |
### danube processing tests
|
|
89 |
|
|
90 |
if [ $tsts -eq 0 ]
|
|
91 |
then
|
|
92 |
echo " val good_ratings = process_ratings(ratings)" | tee -a $out
|
|
93 |
echo " val movie_names = process_movies(movies)" | tee -a $out
|
|
94 |
echo " " | tee -a $out
|
|
95 |
echo " good_ratings.length == 48580 " | tee -a $out
|
|
96 |
echo " movie_names.length == 9742 " | tee -a $out
|
|
97 |
|
|
98 |
if (scala_assert "danube.scala" "danube_test2.scala")
|
|
99 |
then
|
|
100 |
echo " --> success" | tee -a $out
|
|
101 |
marks=$(( marks + 1 ))
|
|
102 |
else
|
|
103 |
echo " --> one of the tests failed" | tee -a $out
|
|
104 |
fi
|
|
105 |
fi
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
## final marks
|
|
110 |
echo "Overall mark for CW 7, Part 1 + 2" | tee -a $out
|
|
111 |
echo "$marks" | tee -a $out
|
|
112 |
|
|
113 |
|