257
|
1 |
#!/bin/bash
|
|
2 |
set -euo pipefail
|
|
3 |
|
|
4 |
|
|
5 |
out=${1:-output}
|
|
6 |
|
|
7 |
echo -e "" > $out
|
|
8 |
|
|
9 |
|
288
|
10 |
echo -e "Below is the feedback and provisional marks for your submission" >> $out
|
329
|
11 |
echo -e "of Preliminar 9. Please note all marks are provisional until" >> $out
|
288
|
12 |
echo -e "ratified by the assessment board -- this is not an official" >> $out
|
|
13 |
echo -e "results transcript." >> $out
|
329
|
14 |
echo -e "" >> $out
|
257
|
15 |
|
329
|
16 |
# marks for CW9 preliminary
|
257
|
17 |
marks=$(( 0 ))
|
|
18 |
|
|
19 |
|
|
20 |
# compilation tests
|
|
21 |
|
|
22 |
function scala_compile {
|
288
|
23 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
257
|
24 |
}
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
|
28 |
function scala_assert {
|
329
|
29 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
257
|
30 |
}
|
|
31 |
|
|
32 |
# purity test
|
|
33 |
|
|
34 |
function scala_vars {
|
329
|
35 |
# (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
36 |
(egrep '\bvar\b|\breturn\b|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
257
|
37 |
}
|
|
38 |
|
|
39 |
|
329
|
40 |
|
257
|
41 |
# var, return, ListBuffer test
|
|
42 |
#
|
|
43 |
echo -e "postfix.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
44 |
|
|
45 |
if (scala_vars postfix.scala)
|
|
46 |
then
|
329
|
47 |
echo -e " --> FAIL\n" | tee -a $out
|
257
|
48 |
tsts0=$(( 1 ))
|
|
49 |
else
|
288
|
50 |
echo -e " --> success" | tee -a $out
|
257
|
51 |
tsts0=$(( 0 ))
|
|
52 |
fi
|
|
53 |
|
|
54 |
# compilation test
|
|
55 |
if [ $tsts0 -eq 0 ]
|
|
56 |
then
|
288
|
57 |
echo -e "postfix.scala runs?" | tee -a $out
|
257
|
58 |
|
258
|
59 |
if (scala_compile postfix.scala)
|
257
|
60 |
then
|
288
|
61 |
echo -e " --> success" | tee -a $out
|
257
|
62 |
tsts1=$(( 0 ))
|
|
63 |
else
|
288
|
64 |
echo -e " --> SCALA DID NOT RUN postfix.scala" | tee -a $out
|
257
|
65 |
tsts1=$(( 1 ))
|
|
66 |
fi
|
|
67 |
else
|
|
68 |
tsts1=$(( 1 ))
|
|
69 |
fi
|
|
70 |
|
|
71 |
|
|
72 |
### postfix tests
|
|
73 |
|
|
74 |
if [ $tsts1 -eq 0 ]
|
|
75 |
then
|
|
76 |
echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
|
|
77 |
echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
|
|
78 |
echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
|
|
79 |
echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
|
|
80 |
|
|
81 |
if (scala_assert "postfix.scala" "postfix_test7.scala")
|
|
82 |
then
|
|
83 |
echo -e " --> success" | tee -a $out
|
|
84 |
marks=$(( marks + 1 ))
|
|
85 |
else
|
288
|
86 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
257
|
87 |
fi
|
|
88 |
fi
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
if [ $tsts1 -eq 0 ]
|
|
93 |
then
|
|
94 |
echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
|
|
95 |
echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
|
|
96 |
echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
|
|
97 |
echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
|
|
98 |
echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
|
|
99 |
echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
|
|
100 |
|
|
101 |
if (scala_assert "postfix.scala" "postfix_test8.scala")
|
|
102 |
then
|
|
103 |
echo -e " --> success" | tee -a $out
|
|
104 |
marks=$(( marks + 1 ))
|
|
105 |
else
|
329
|
106 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
257
|
107 |
fi
|
|
108 |
fi
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
### postfix2 tests
|
|
113 |
|
|
114 |
# var, return, ListBuffer test
|
|
115 |
#
|
|
116 |
echo -e "postfix2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
117 |
|
|
118 |
if (scala_vars postfix2.scala)
|
|
119 |
then
|
329
|
120 |
echo -e " --> FAIL\n" | tee -a $out
|
257
|
121 |
tsts0=$(( 1 ))
|
|
122 |
else
|
288
|
123 |
echo -e " --> success" | tee -a $out
|
257
|
124 |
tsts0=$(( 0 ))
|
|
125 |
fi
|
|
126 |
|
|
127 |
|
|
128 |
# compilation test
|
|
129 |
|
|
130 |
if [ $tsts0 -eq 0 ]
|
|
131 |
then
|
288
|
132 |
echo -e "postfix2.scala runs?" | tee -a $out
|
257
|
133 |
|
258
|
134 |
if (scala_compile postfix2.scala)
|
257
|
135 |
then
|
288
|
136 |
echo -e " --> success" | tee -a $out
|
257
|
137 |
tsts1=$(( 0 ))
|
|
138 |
else
|
288
|
139 |
echo -e " --> SCALA DID NOT RUN postfix2.scala" | tee -a $out
|
257
|
140 |
tsts1=$(( 1 ))
|
|
141 |
fi
|
|
142 |
else
|
|
143 |
tsts1=$(( 1 ))
|
|
144 |
fi
|
|
145 |
|
|
146 |
|
|
147 |
if [ $tsts1 -eq 0 ]
|
|
148 |
then
|
|
149 |
echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
|
|
150 |
echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
|
|
151 |
echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
|
|
152 |
echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
|
|
153 |
echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " | tee -a $out
|
|
154 |
echo -e " List(\"3\", \"4\", \"8\", \"*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" | tee -a $out
|
329
|
155 |
|
|
156 |
if (scala_assert "postfix2.scala" "postfix_test9.scala")
|
|
157 |
then
|
|
158 |
echo -e " --> success" | tee -a $out
|
|
159 |
marks=$(( marks + 1 ))
|
|
160 |
else
|
|
161 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
162 |
fi
|
|
163 |
fi
|
|
164 |
|
|
165 |
if [ $tsts1 -eq 0 ]
|
|
166 |
then
|
257
|
167 |
echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
|
|
168 |
echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
|
|
169 |
echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
|
|
170 |
echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
|
|
171 |
echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
|
|
172 |
echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
|
|
173 |
echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" | tee -a $out
|
|
174 |
echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" | tee -a $out
|
|
175 |
echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" | tee -a $out
|
|
176 |
echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" | tee -a $out
|
|
177 |
|
329
|
178 |
if (scala_assert "postfix2.scala" "postfix_test10.scala")
|
257
|
179 |
then
|
|
180 |
echo -e " --> success" | tee -a $out
|
329
|
181 |
marks=$(( marks + 1 ))
|
257
|
182 |
else
|
288
|
183 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
257
|
184 |
fi
|
|
185 |
fi
|
|
186 |
|
|
187 |
## final marks
|
288
|
188 |
echo -e "Overall mark for CW 9, Preliminary Part" | tee -a $out
|
|
189 |
echo -e "$marks" | tee -a $out
|