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