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 |
|
|
11 |
echo "Below is the feedback and provisional marks for your submission" >> $out
|
|
12 |
echo "for assignment 6 Part 1 + 2. Please note all marks are provisional until" >> $out
|
|
13 |
echo "ratified by the assessment board -- this is not an official" >> $out
|
|
14 |
echo "results transcript." >> $out
|
|
15 |
echo "" >> $out
|
|
16 |
|
|
17 |
echo "Below is the feedback for your submission for collatz.scala" >> $out
|
|
18 |
echo "" >> $out
|
|
19 |
|
|
20 |
# marks for CW6 parts 1 + 2
|
|
21 |
marks=$(( 0 ))
|
|
22 |
|
|
23 |
# compilation tests
|
|
24 |
|
|
25 |
function scala_compile {
|
210
|
26 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
|
158
|
27 |
}
|
|
28 |
|
|
29 |
# functional tests
|
|
30 |
|
|
31 |
function scala_assert {
|
210
|
32 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
158
|
33 |
}
|
|
34 |
|
|
35 |
# purity test
|
|
36 |
|
|
37 |
function scala_vars {
|
|
38 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
# var, .par return, ListBuffer test
|
|
43 |
#
|
210
|
44 |
echo "collatz.scala does not contain vars, return etc?" | tee -a $out
|
158
|
45 |
|
|
46 |
if (scala_vars collatz.scala)
|
|
47 |
then
|
210
|
48 |
echo " --> test failed" | tee -a $out
|
158
|
49 |
tsts0=$(( 1 ))
|
|
50 |
else
|
|
51 |
echo " --> success" | tee -a $out
|
|
52 |
tsts0=$(( 0 ))
|
|
53 |
fi
|
|
54 |
|
|
55 |
### compilation test
|
|
56 |
|
|
57 |
|
|
58 |
if [ $tsts0 -eq 0 ]
|
|
59 |
then
|
|
60 |
echo "collatz.scala runs?" | tee -a $out
|
|
61 |
|
|
62 |
if (scala_compile collatz.scala)
|
|
63 |
then
|
|
64 |
echo " --> success" | tee -a $out
|
|
65 |
tsts=$(( 0 ))
|
|
66 |
else
|
210
|
67 |
echo " --> scala collatz.scala did not run successfully" | tee -a $out
|
158
|
68 |
tsts=$(( 1 ))
|
|
69 |
fi
|
|
70 |
else
|
|
71 |
tsts=$(( 1 ))
|
|
72 |
fi
|
|
73 |
|
|
74 |
### collatz tests
|
|
75 |
|
|
76 |
if [ $tsts -eq 0 ]
|
|
77 |
then
|
|
78 |
echo "collatz.scala tests:" | tee -a $out
|
210
|
79 |
echo " collatz(1) == 0" | tee -a $out
|
|
80 |
echo " collatz(6) == 8" | tee -a $out
|
|
81 |
echo " collatz(9) == 19" | tee -a $out
|
|
82 |
echo " collatz(9000) == 47" | tee -a $out
|
158
|
83 |
|
|
84 |
if (scala_assert "collatz.scala" "collatz_test1.scala")
|
|
85 |
then
|
|
86 |
echo " --> success" | tee -a $out
|
|
87 |
marks=$(( marks + 2 ))
|
|
88 |
else
|
|
89 |
echo " --> one of the tests failed" | tee -a $out
|
|
90 |
fi
|
|
91 |
fi
|
|
92 |
|
|
93 |
### collatz-max tests
|
|
94 |
|
|
95 |
if [ $tsts -eq 0 ]
|
|
96 |
then
|
210
|
97 |
echo " collatz_max(10) == (19, 9)" | tee -a $out
|
|
98 |
echo " collatz_max(100) == (118, 97)" | tee -a $out
|
|
99 |
echo " collatz_max(1000) == (178, 871)" | tee -a $out
|
|
100 |
echo " collatz_max(10000) == (261, 6171)" | tee -a $out
|
|
101 |
echo " collatz_max(100000) == (350, 77031)" | tee -a $out
|
|
102 |
echo " collatz_max(1000000) == (524, 837799)" | tee -a $out
|
212
|
103 |
# echo " collatz_max(2) == (1, 2) || collatz_max(2) == (0, 1)" | tee -a $out
|
|
104 |
echo " collatz_max(2) == (1, 2)" | tee -a $out
|
210
|
105 |
echo " collatz_max(77000) == (339, 52527)" | tee -a $out
|
158
|
106 |
|
|
107 |
if (scala_assert "collatz.scala" "collatz_test2.scala")
|
|
108 |
then
|
|
109 |
echo " --> success" | tee -a $out
|
|
110 |
marks=$(( marks + 1 ))
|
|
111 |
else
|
|
112 |
echo " --> one of the tests failed" | tee -a $out
|
|
113 |
fi
|
|
114 |
fi
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
## final marks
|
|
119 |
echo "Overall mark for Part 1" | tee -a $out
|
|
120 |
echo " $marks" | tee -a $out
|
|
121 |
|
|
122 |
|