author | Christian Urban <christian.urban@kcl.ac.uk> |
Tue, 13 Oct 2020 10:21:21 +0100 | |
changeset 343 | c8fcc0e0a57f |
parent 281 | 87b9e3e2c1a7 |
permissions | -rwxr-xr-x |
158 | 1 |
#!/bin/bash |
2 |
||
3 |
# to make the script fail safely |
|
4 |
set -euo pipefail |
|
5 |
||
6 |
||
7 |
out=${1:-output} |
|
8 |
||
9 |
echo "" > $out |
|
10 |
||
266 | 11 |
echo `date` >> $out |
12 |
echo >> $out |
|
158 | 13 |
echo "Below is the feedback and provisional marks for your submission" >> $out |
281 | 14 |
echo "for the Preliminary Part of Assignment 6. Please note all marks are provisional until" >> $out |
158 | 15 |
echo "ratified by the assessment board -- this is not an official" >> $out |
16 |
echo "results transcript." >> $out |
|
17 |
echo "" >> $out |
|
18 |
||
266 | 19 |
echo "The feedback for your submission for collatz.scala" >> $out |
158 | 20 |
echo "" >> $out |
21 |
||
267
9e0216756771
updated myassert workaround
Christian Urban <urbanc@in.tum.de>
parents:
266
diff
changeset
|
22 |
# marks for CW6 basic part |
158 | 23 |
marks=$(( 0 )) |
24 |
||
25 |
# compilation tests |
|
26 |
||
27 |
function scala_compile { |
|
266 | 28 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) |
158 | 29 |
} |
30 |
||
31 |
# functional tests |
|
32 |
||
33 |
function scala_assert { |
|
281 | 34 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null) |
158 | 35 |
} |
36 |
||
37 |
# purity test |
|
38 |
||
39 |
function scala_vars { |
|
40 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
41 |
} |
|
42 |
||
43 |
||
44 |
# var, .par return, ListBuffer test |
|
45 |
# |
|
210 | 46 |
echo "collatz.scala does not contain vars, return etc?" | tee -a $out |
158 | 47 |
|
48 |
if (scala_vars collatz.scala) |
|
49 |
then |
|
210 | 50 |
echo " --> test failed" | tee -a $out |
158 | 51 |
tsts0=$(( 1 )) |
52 |
else |
|
53 |
echo " --> success" | tee -a $out |
|
54 |
tsts0=$(( 0 )) |
|
55 |
fi |
|
56 |
||
57 |
### compilation test |
|
58 |
||
59 |
||
60 |
if [ $tsts0 -eq 0 ] |
|
61 |
then |
|
62 |
echo "collatz.scala runs?" | tee -a $out |
|
63 |
||
64 |
if (scala_compile collatz.scala) |
|
65 |
then |
|
66 |
echo " --> success" | tee -a $out |
|
67 |
tsts=$(( 0 )) |
|
68 |
else |
|
210 | 69 |
echo " --> scala collatz.scala did not run successfully" | tee -a $out |
158 | 70 |
tsts=$(( 1 )) |
71 |
fi |
|
72 |
else |
|
73 |
tsts=$(( 1 )) |
|
74 |
fi |
|
75 |
||
266 | 76 |
echo >> $out |
77 |
||
158 | 78 |
### collatz tests |
79 |
||
80 |
if [ $tsts -eq 0 ] |
|
81 |
then |
|
82 |
echo "collatz.scala tests:" | tee -a $out |
|
210 | 83 |
echo " collatz(1) == 0" | tee -a $out |
84 |
echo " collatz(6) == 8" | tee -a $out |
|
85 |
echo " collatz(9) == 19" | tee -a $out |
|
86 |
echo " collatz(9000) == 47" | tee -a $out |
|
158 | 87 |
|
88 |
if (scala_assert "collatz.scala" "collatz_test1.scala") |
|
89 |
then |
|
90 |
echo " --> success" | tee -a $out |
|
343 | 91 |
marks=$(( marks + 1 )) |
158 | 92 |
else |
93 |
echo " --> one of the tests failed" | tee -a $out |
|
94 |
fi |
|
95 |
fi |
|
96 |
||
97 |
### collatz-max tests |
|
98 |
||
99 |
if [ $tsts -eq 0 ] |
|
100 |
then |
|
210 | 101 |
echo " collatz_max(10) == (19, 9)" | tee -a $out |
102 |
echo " collatz_max(100) == (118, 97)" | tee -a $out |
|
103 |
echo " collatz_max(1000) == (178, 871)" | tee -a $out |
|
104 |
echo " collatz_max(10000) == (261, 6171)" | tee -a $out |
|
105 |
echo " collatz_max(100000) == (350, 77031)" | tee -a $out |
|
106 |
echo " collatz_max(1000000) == (524, 837799)" | tee -a $out |
|
212 | 107 |
# echo " collatz_max(2) == (1, 2) || collatz_max(2) == (0, 1)" | tee -a $out |
108 |
echo " collatz_max(2) == (1, 2)" | tee -a $out |
|
210 | 109 |
echo " collatz_max(77000) == (339, 52527)" | tee -a $out |
158 | 110 |
|
111 |
if (scala_assert "collatz.scala" "collatz_test2.scala") |
|
112 |
then |
|
113 |
echo " --> success" | tee -a $out |
|
114 |
marks=$(( marks + 1 )) |
|
115 |
else |
|
116 |
echo " --> one of the tests failed" | tee -a $out |
|
117 |
fi |
|
118 |
fi |
|
119 |
||
343 | 120 |
### last-odd tests |
121 |
||
122 |
if [ $tsts -eq 0 ] |
|
123 |
then |
|
124 |
echo " last_odd(113) == 85" | tee -a $out |
|
125 |
echo " last_odd(84) == 21" | tee -a $out |
|
126 |
echo " last_odd(605) == 341" | tee -a $out |
|
127 |
||
128 |
if (scala_assert "collatz.scala" "collatz_test3.scala") |
|
129 |
then |
|
130 |
echo " --> success" | tee -a $out |
|
131 |
marks=$(( marks + 1 )) |
|
132 |
else |
|
133 |
echo " --> one of the tests failed" | tee -a $out |
|
134 |
fi |
|
135 |
fi |
|
136 |
||
158 | 137 |
|
138 |
||
139 |
## final marks |
|
266 | 140 |
echo >> $out |
343 | 141 |
echo "Overall mark for the Preliminary Part" | tee -a $out |
158 | 142 |
echo " $marks" | tee -a $out |
143 |
||
144 |