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