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