168
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
out=${1:-output}
|
|
7 |
|
|
8 |
echo "" > $out
|
|
9 |
|
|
10 |
|
|
11 |
echo "Below is the feedback and provisional marks for your submission" >> $out
|
245
|
12 |
echo "for assignment 9 Part 1. Please note all marks are provisional until" >> $out
|
168
|
13 |
echo "ratified by the assessment board -- this is not an official" >> $out
|
|
14 |
echo "results transcript." >> $out
|
|
15 |
echo "" >> $out
|
|
16 |
|
245
|
17 |
# marks for CW9 part 1
|
168
|
18 |
marks=$(( 0 ))
|
|
19 |
|
|
20 |
# compilation tests
|
|
21 |
|
|
22 |
function scala_compile {
|
245
|
23 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
|
168
|
24 |
}
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
|
28 |
function scala_assert {
|
246
|
29 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
245
|
30 |
}
|
|
31 |
|
|
32 |
function scala_assert_long {
|
|
33 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
168
|
34 |
}
|
|
35 |
|
|
36 |
# purity test
|
|
37 |
|
|
38 |
function scala_vars {
|
|
39 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
# var, return, ListBuffer test
|
|
44 |
#
|
|
45 |
echo "re.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
46 |
|
|
47 |
if (scala_vars re.scala)
|
|
48 |
then
|
|
49 |
echo " --> test failed" | tee -a $out
|
|
50 |
tsts0=$(( 1 ))
|
|
51 |
else
|
|
52 |
echo " --> success" | tee -a $out
|
|
53 |
tsts0=$(( 0 ))
|
|
54 |
fi
|
|
55 |
|
|
56 |
|
|
57 |
# compilation test
|
|
58 |
if [ $tsts0 -eq 0 ]
|
|
59 |
then
|
|
60 |
echo "re.scala runs?" | tee -a $out
|
|
61 |
|
|
62 |
if (scala_compile re.scala)
|
|
63 |
then
|
|
64 |
echo " --> success" | tee -a $out
|
|
65 |
tsts1=$(( 0 ))
|
|
66 |
else
|
|
67 |
echo " --> scala re.scala did not run successfully" | tee -a $out
|
|
68 |
tsts1=$(( 1 ))
|
|
69 |
fi
|
|
70 |
else
|
|
71 |
tsts1=$(( 1 ))
|
|
72 |
fi
|
|
73 |
|
245
|
74 |
### re1 test
|
168
|
75 |
|
|
76 |
if [ $tsts1 -eq 0 ]
|
|
77 |
then
|
|
78 |
echo " nullable(ZERO) == false" | tee -a $out
|
|
79 |
echo " nullable(ONE) == true" | tee -a $out
|
|
80 |
echo " nullable(CHAR('a')) == false" | tee -a $out
|
|
81 |
echo " nullable(ZERO | ONE) == true" | tee -a $out
|
|
82 |
echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out
|
|
83 |
echo " nullable(ONE ~ ONE) == true" | tee -a $out
|
|
84 |
echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
|
|
85 |
echo " nullable(STAR(ZERO)) == true" | tee -a $out
|
|
86 |
|
245
|
87 |
if (scala_assert "re.scala" "re_test1.scala")
|
168
|
88 |
then
|
|
89 |
echo " --> success" | tee -a $out
|
|
90 |
marks=$(( marks + 1 ))
|
|
91 |
else
|
|
92 |
echo " --> test failed" | tee -a $out
|
|
93 |
fi
|
|
94 |
fi
|
|
95 |
|
245
|
96 |
### re2 test
|
168
|
97 |
|
|
98 |
if [ $tsts1 -eq 0 ]
|
|
99 |
then
|
|
100 |
echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
|
|
101 |
echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
|
|
102 |
echo " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
|
|
103 |
echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
|
|
104 |
echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
|
245
|
105 |
echo "" | tee -a $out
|
|
106 |
echo " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out
|
|
107 |
echo " assert(der('a', r0) == (ONE ~ \"b\") ~ \"c\")" | tee -a $out
|
|
108 |
echo " assert(der('b', r0) == (ZERO ~ \"b\") ~ \"c\")" | tee -a $out
|
|
109 |
echo " assert(der('c', r0) == (ZERO ~ \"b\") ~ \"c\")" | tee -a $out
|
|
110 |
echo "" | tee -a $out
|
|
111 |
echo " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out
|
|
112 |
echo " assert(der('a', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\")" | tee -a $out
|
|
113 |
echo " assert(der('b', r1) == ((ZERO ~ \"b\") | ONE) ~ \"c\")" | tee -a $out
|
|
114 |
echo " assert(der('c', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\")" | tee -a $out
|
|
115 |
echo "" | tee -a $out
|
|
116 |
echo " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out
|
|
117 |
echo " assert(der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO))" | tee -a $out
|
|
118 |
echo " assert(der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO))" | tee -a $out
|
|
119 |
echo " assert(der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE))" | tee -a $out
|
|
120 |
|
|
121 |
if (scala_assert "re.scala" "re_test2.scala")
|
168
|
122 |
then
|
|
123 |
echo " --> success" | tee -a $out
|
|
124 |
marks=$(( marks + 1 ))
|
|
125 |
else
|
|
126 |
echo " --> test failed" | tee -a $out
|
|
127 |
fi
|
|
128 |
fi
|
|
129 |
|
245
|
130 |
### re3 test
|
168
|
131 |
|
|
132 |
if [ $tsts1 -eq 0 ]
|
|
133 |
then
|
|
134 |
echo " simp(ZERO | ONE) == ONE" | tee -a $out
|
|
135 |
echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
|
|
136 |
echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
|
245
|
137 |
echo " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
|
|
138 |
echo " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
|
168
|
139 |
echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
|
|
140 |
echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
|
|
141 |
echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
|
|
142 |
echo " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
|
|
143 |
echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
|
|
144 |
echo " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
|
|
145 |
echo " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
|
|
146 |
echo " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
|
|
147 |
echo " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
|
|
148 |
echo " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
|
245
|
149 |
echo " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" tee -a $out
|
|
150 |
|
|
151 |
if (scala_assert "re.scala" "re_test3.scala")
|
168
|
152 |
then
|
|
153 |
echo " --> success" | tee -a $out
|
245
|
154 |
marks=$(( marks + 1 ))
|
168
|
155 |
else
|
|
156 |
echo " --> test failed" | tee -a $out
|
|
157 |
fi
|
|
158 |
fi
|
|
159 |
|
245
|
160 |
### re4 test
|
168
|
161 |
|
|
162 |
if [ $tsts1 -eq 0 ]
|
|
163 |
then
|
|
164 |
echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
|
|
165 |
echo " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
|
|
166 |
echo " ders(List('b'),EVIL) == ONE" | tee -a $out
|
|
167 |
echo " ders(List('b','b'),EVIL) == ZERO" | tee -a $out
|
|
168 |
echo " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out
|
|
169 |
echo " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
|
|
170 |
echo " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
|
|
171 |
echo " matcher(EVIL, \"b\") == true" | tee -a $out
|
|
172 |
echo " matcher(EVIL, \"bb\") == false" | tee -a $out
|
|
173 |
echo " matcher(\"abc\", \"abc\") == true" | tee -a $out
|
245
|
174 |
echo " matcher(\"abc\", \"ab\") == true" | tee -a $out
|
168
|
175 |
echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
|
|
176 |
echo " matcher(ONE, \"\") == true" | tee -a $out
|
|
177 |
echo " matcher(ZERO, \"\") == false" | tee -a $out
|
|
178 |
echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
|
|
179 |
echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
|
|
180 |
|
245
|
181 |
if (scala_assert "re.scala" "re_test4.scala")
|
168
|
182 |
then
|
|
183 |
echo " --> success" | tee -a $out
|
|
184 |
marks=$(( marks + 1 ))
|
|
185 |
else
|
|
186 |
echo " --> test failed" | tee -a $out
|
|
187 |
fi
|
|
188 |
fi
|
|
189 |
|
245
|
190 |
### re5 test
|
|
191 |
|
168
|
192 |
|
|
193 |
if [ $tsts1 -eq 0 ]
|
|
194 |
then
|
|
195 |
echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
|
|
196 |
echo " size(der('a', der('a', EVIL))) == 28" | tee -a $out
|
|
197 |
echo " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out
|
|
198 |
echo " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out
|
|
199 |
echo " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
|
|
200 |
|
245
|
201 |
if (scala_assert "re.scala" "re_test5.scala")
|
|
202 |
then
|
|
203 |
echo " --> success" | tee -a $out
|
|
204 |
marks=$(( marks + 1 ))
|
|
205 |
else
|
|
206 |
echo " --> test failed" | tee -a $out
|
|
207 |
fi
|
|
208 |
fi
|
|
209 |
|
|
210 |
### re6 'power' test
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
if [ $tsts1 -eq 0 ]
|
|
215 |
then
|
|
216 |
echo " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
|
|
217 |
echo " ...the Iterator produces the rexp" | tee -a $out
|
|
218 |
echo "" | tee -a $out
|
|
219 |
echo " SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
|
|
220 |
echo "" | tee -a $out
|
|
221 |
echo " where SEQ is nested 50 times." | tee -a $out
|
|
222 |
echo "" | tee -a $out
|
|
223 |
echo " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out
|
|
224 |
echo " ... the Iterator produces a rexp of size 2097151" | tee -a $out
|
|
225 |
echo "" | tee -a $out
|
|
226 |
echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
|
|
227 |
echo " matcher(EVIL, \"a\" * 1000000 ++ \"b\") == true" | tee -a $out
|
|
228 |
echo " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out
|
|
229 |
|
|
230 |
|
|
231 |
if (time scala_assert_long "re.scala" "re_test6.scala")
|
168
|
232 |
then
|
|
233 |
echo " --> success" | tee -a $out
|
|
234 |
marks=$(( marks + 1 ))
|
|
235 |
else
|
|
236 |
echo " --> test failed" | tee -a $out
|
|
237 |
fi
|
|
238 |
fi
|
|
239 |
|
|
240 |
|
|
241 |
## final marks
|
245
|
242 |
echo "Overall mark for CW 9, Part 1" | tee -a $out
|
168
|
243 |
echo "$marks" | tee -a $out
|
|
244 |
|
|
245 |
|