109 echo -e " nullable(ZERO | ONE) == true" | tee -a $out |
109 echo -e " nullable(ZERO | ONE) == true" | tee -a $out |
110 echo -e " nullable(ZERO | CHAR('a')) == false" | tee -a $out |
110 echo -e " nullable(ZERO | CHAR('a')) == false" | tee -a $out |
111 echo -e " nullable(ONE ~ ONE) == true" | tee -a $out |
111 echo -e " nullable(ONE ~ ONE) == true" | tee -a $out |
112 echo -e " nullable(ONE ~ CHAR('a')) == false" | tee -a $out |
112 echo -e " nullable(ONE ~ CHAR('a')) == false" | tee -a $out |
113 echo -e " nullable(STAR(ZERO)) == true" | tee -a $out |
113 echo -e " nullable(STAR(ZERO)) == true" | tee -a $out |
|
114 echo -e " nullable(ALTs(List(ONE, CHAR('a'), ZERO))) == true" | tee -a $out |
|
115 echo -e " nullable(SEQs(List(ONE, ALTs(List(ONE, CHAR('a'), ZERO)), STAR(ZERO)))) == true" | tee -a $out |
114 |
116 |
115 if (scala_assert "re.scala" "re_test1.scala") |
117 if (scala_assert "re.scala" "re_test1.scala") |
116 then |
118 then |
117 echo -e " --> success" | tee -a $out |
119 echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out |
118 marks=$(( marks + 0.5 )) |
120 marks=$(( marks + 0.5 )) |
119 else |
121 else |
120 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
122 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
121 fi |
123 fi |
122 fi |
124 fi |
123 |
125 |
124 ### re2 test |
126 ### re2 der test |
125 |
127 |
126 if [ $tsts -eq 0 ] |
128 if [ $tsts -eq 0 ] |
127 then |
129 then |
128 echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out |
130 echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out |
129 echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out |
131 echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), SEQs(List(ONE)))" | tee -a $out |
130 echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out |
132 echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out |
131 echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out |
133 echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out |
132 echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out |
134 echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out |
133 echo -e "" | tee -a $out |
135 echo -e "" | tee -a $out |
134 echo -e " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out |
136 echo -e " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out |
135 echo -e " der('a', r0) == (ONE ~ \"b\") ~ \"c\"" | tee -a $out |
137 echo -e " der('a', r0) == (ONE ~ \"b\") ~ \"c\"" | tee -a $out |
136 echo -e " der('b', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out |
138 echo -e " der('b', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out |
137 echo -e " der('c', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out |
139 echo -e " der('c', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out |
138 echo -e "" | tee -a $out |
140 echo -e "" | tee -a $out |
139 echo -e " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out |
141 echo -e " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out |
140 echo -e " der('a', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out |
142 echo -e " der('a', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out |
141 echo -e " der('b', r1) == ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out |
143 echo -e " der('b', r1) == ((ZERO ~ \"b\") | SEQs(List(ONE))) ~ \"c\"" | tee -a $out |
142 echo -e " der('c', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out |
144 echo -e " der('c', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out |
143 echo -e "" | tee -a $out |
145 echo -e "" | tee -a $out |
144 echo -e " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out |
146 echo -e " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out |
145 echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out |
147 echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out |
146 echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out |
148 echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out |
147 echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE)" | tee -a $out |
149 echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ONE)))" | tee -a $out |
148 |
150 |
149 if (scala_assert "re.scala" "re_test2.scala") |
151 if (scala_assert "re.scala" "re_test2.scala") |
150 then |
152 then |
151 echo -e " --> success" | tee -a $out |
153 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
152 marks=$(( marks + 1.0 )) |
154 marks=$(( marks + 1.0 )) |
153 else |
155 else |
154 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
156 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
157 fi |
|
158 fi |
|
159 |
|
160 ### re3 denest test |
|
161 |
|
162 if [ $tsts -eq 0 ] |
|
163 then |
|
164 echo -e " denest(List(ONE, ZERO, ALTs(List(ONE, CHAR('a'))))) == List(ONE, ONE, CHAR('a'))" | tee -a $out |
|
165 echo -e " denest(List(ONE ~ ONE, ZERO, ZERO | ONE)) == List(ONE ~ ONE, ZERO, ONE)" | tee -a $out |
|
166 |
|
167 if (scala_assert "re.scala" "re_test4.scala") |
|
168 then |
|
169 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
|
170 marks=$(( marks + 1.0 )) |
|
171 else |
|
172 echo -e " --> \n ONE TEST FAILED\n" | tee -a $out |
|
173 fi |
|
174 fi |
|
175 |
|
176 ### re3a flts test |
|
177 |
|
178 if [ $tsts -eq 0 ] |
|
179 then |
|
180 echo -e " flts(Nil) == Nil" | tee -a $out |
|
181 echo -e " flts(ZERO::ZERO::Nil) == List(ZERO)" | tee -a $out |
|
182 echo -e " flts(ZERO::ONE::ZERO::ONE::Nil) == List(ZERO)" | tee -a $out |
|
183 echo -e " flts(ONE::ALTs(List(ONE))::ONE::Nil) == List(ALTs(List(ONE)))" | tee -a $out |
|
184 echo -e " flts(ONE::ALTs(List(ONE))::ONE::ALTs(List(ONE))::Nil) == List(ALTs(List(ONE)), ALTs(List(ONE)))" | tee -a $out |
|
185 echo -e " flts(List(CHAR('a'), ONE, ONE, CHAR('b')), Nil) == List(CHAR('a'), CHAR('b'))" | tee -a $out |
|
186 echo -e " flts(List(ONE ~ CHAR('a'), CHAR('b') ~ ONE), Nil) == List(ONE, CHAR('a'), CHAR('b'), ONE)" | tee -a $out |
|
187 |
|
188 if (scala_assert "re.scala" "re_test3a.scala") |
|
189 then |
|
190 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
|
191 marks=$(( marks + 1.0 )) |
|
192 else |
|
193 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
194 fi |
|
195 fi |
|
196 |
|
197 ### re-smart test |
|
198 |
|
199 if [ $tsts -eq 0 ] |
|
200 then |
|
201 echo -e " SEQs_smart(Nil) == ONE" | tee -a $out |
|
202 echo -e " SEQs_smart(List(ZERO)) == ZERO" | tee -a $out |
|
203 echo -e " SEQs_smart(List(CHAR('a'))) == CHAR('a')" | tee -a $out |
|
204 echo -e " SEQs_smart(List(ONE ~ ONE)) == ONE ~ ONE" | tee -a $out |
|
205 echo -e " SEQs_smart(List(ONE, ONE)) == SEQs(List(ONE, ONE))" | tee -a $out |
|
206 echo -e " ALTs_smart(Nil) == ZERO" | tee -a $out |
|
207 echo -e " ALTs_smart(List(ONE ~ ONE)) == ONE ~ ONE" | tee -a $out |
|
208 echo -e " ALTs_smart(List(ZERO, ZERO)) == ALTs(List(ZERO, ZERO))" | tee -a $out |
|
209 |
|
210 if (scala_assert "re.scala" "re_test6.scala") |
|
211 then |
|
212 echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out |
|
213 marks=$(( marks + 0.5 )) |
|
214 else |
|
215 echo -e " --> \n ONE TEST FAILED\n" | tee -a $out |
155 fi |
216 fi |
156 fi |
217 fi |
157 |
218 |
158 ### re3 test |
219 ### re3 test |
159 |
220 |
172 echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out |
233 echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out |
173 echo -e " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out |
234 echo -e " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out |
174 echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out |
235 echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out |
175 echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out |
236 echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out |
176 echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out |
237 echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out |
177 echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" | tee -a $out |
238 echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE, CHAR('a'))" | tee -a $out |
178 |
239 echo -e " simp(ALTs(Nil)) == ZERO" | tee -a $out |
|
240 echo -e " simp(SEQs(List(CHAR('a')))) == CHAR('a')" | tee -a $out |
179 if (scala_assert "re.scala" "re_test3.scala") |
241 if (scala_assert "re.scala" "re_test3.scala") |
180 then |
242 then |
181 echo -e " --> success" | tee -a $out |
243 echo -e " --> success (+ 1 Mark)\n" | tee -a $out |
182 marks=$(( marks + 1.0 )) |
244 marks=$(( marks + 1.0 )) |
183 else |
245 else |
184 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
246 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
185 fi |
247 fi |
186 fi |
248 fi |
187 |
|
188 ### re3a flts test |
|
189 |
|
190 if [ $tsts -eq 0 ] |
|
191 then |
|
192 echo -e " flts(Nil) == Nil" | tee -a $out |
|
193 echo -e " flts(ZERO::ZERO::Nil) == Nil" | tee -a $out |
|
194 echo -e " flts(ZERO::ONE::ZERO::ONE::Nil) == List(ONE, ONE)" | tee -a $out |
|
195 echo -e " flts(ONE::ALTs(List(ONE))::ONE::Nil) == List(ONE, ONE, ONE)" | tee -a $out |
|
196 echo -e " flts(ONE::ALTs(List(ONE))::ONE::ALTs(List(ONE))::Nil) == List(ONE, ONE, ONE, ONE)" | tee -a $out |
|
197 |
|
198 if (scala_assert "re.scala" "re_test3a.scala") |
|
199 then |
|
200 echo -e " --> success" | tee -a $out |
|
201 marks=$(( marks + 1.0 )) |
|
202 else |
|
203 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
204 fi |
|
205 fi |
|
206 |
|
207 |
249 |
208 |
250 |
209 ### re4 test |
251 ### re4 test |
210 |
252 |
211 if [ $tsts -eq 0 ] |
253 if [ $tsts -eq 0 ] |
212 then |
254 then |
213 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
255 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
214 echo -e " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out |
256 echo -e " ders((\"a\" * 5).toList,EVIL) == SEQs(List(STAR(CHAR('a')), STAR(STAR(CHAR('a'))), CHAR('b')))" | tee -a $out |
215 echo -e " ders(List('b'),EVIL) == ONE" | tee -a $out |
257 echo -e " ders(List('b'),EVIL) == ONE" | tee -a $out |
216 echo -e " ders(List('b','b'),EVIL) == ZERO" | tee -a $out |
258 echo -e " ders(List('b','b'),EVIL) == ZERO" | tee -a $out |
217 echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out |
259 echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out |
218 echo -e " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out |
260 echo -e " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out |
219 echo -e " matcher(EVIL, \"a\" * 50) == false" | tee -a $out |
261 echo -e " matcher(EVIL, \"a\" * 50) == false" | tee -a $out |
225 echo -e " matcher(ONE, \"\") == true" | tee -a $out |
267 echo -e " matcher(ONE, \"\") == true" | tee -a $out |
226 echo -e " matcher(ZERO, \"\") == false" | tee -a $out |
268 echo -e " matcher(ZERO, \"\") == false" | tee -a $out |
227 echo -e " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out |
269 echo -e " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out |
228 echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out |
270 echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out |
229 |
271 |
230 if (scala_assert "re.scala" "re_test4.scala") |
272 if (scala_assert "re.scala" "re_test7.scala") |
231 then |
273 then |
232 echo -e " --> success" | tee -a $out |
274 echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out |
233 marks=$(( marks + 1.0 )) |
275 marks=$(( marks + 0.5 )) |
234 else |
276 else |
235 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
277 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
236 fi |
278 fi |
237 fi |
279 fi |
238 |
280 |
239 ### re5 test |
281 ### re5 test |
240 |
282 |
241 |
283 if [ $tsts -eq 0 ] |
242 if [ $tsts -eq 0 ] |
284 then |
243 then |
285 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
244 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
286 echo -e " size(der('a', der('a', EVIL))) == 36" | tee -a $out |
245 echo -e " size(der('a', der('a', EVIL))) == 28" | tee -a $out |
287 echo -e " size(der('a', der('a', der('a', EVIL)))) == 83" | tee -a $out |
246 echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out |
288 echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 7" | tee -a $out |
247 echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out |
289 echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 7" | tee -a $out |
248 echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out |
290 |
249 |
291 if (scala_assert "re.scala" "re_test8.scala") |
250 if (scala_assert "re.scala" "re_test5.scala") |
292 then |
251 then |
293 echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out |
252 echo -e " --> success" | tee -a $out |
|
253 marks=$(( marks + 0.5 )) |
294 marks=$(( marks + 0.5 )) |
254 else |
295 else |
255 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
296 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
256 fi |
297 fi |
257 fi |
298 fi |
268 echo -e "" | tee -a $out |
309 echo -e "" | tee -a $out |
269 echo -e " where SEQ is nested 50 times." | tee -a $out |
310 echo -e " where SEQ is nested 50 times." | tee -a $out |
270 echo -e "" | tee -a $out |
311 echo -e "" | tee -a $out |
271 echo -e " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out |
312 echo -e " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out |
272 echo -e " ... the Iterator produces a rexp of size 2097151" | tee -a $out |
313 echo -e " ... the Iterator produces a rexp of size 2097151" | tee -a $out |
|
314 echo -e "" | tee -a $out |
|
315 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
|
316 echo -e " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out |
|
317 echo -e " matcher(EVIL, \"a\" * 1000000 ++ "b") == true" | tee -a $out |
273 START=$(date +%s) |
318 START=$(date +%s) |
274 |
319 |
275 if (scala_assert_thirty "re.scala" "re_test6.scala") |
320 if (scala_assert_thirty "re.scala" "re_test9.scala") |
276 then |
321 then |
277 END=$(date +%s) |
|
278 DIFF=$(( $END - $START )) |
|
279 echo " This test ran for $DIFF seconds" | tee -a $out |
|
280 echo -e " --> success" | tee -a $out |
|
281 marks=$(( marks + 0.5 )) |
|
282 else |
|
283 END=$(date +%s) |
322 END=$(date +%s) |
284 DIFF=$(( $END - $START )) |
323 DIFF=$(( $END - $START )) |
285 echo " This test ran for $DIFF seconds" | tee -a $out |
324 echo " This test ran for $DIFF seconds" | tee -a $out |
286 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
325 echo -e " --> success (+ 1.0 Mark)\n" | tee -a $out |
287 fi |
326 marks=$(( marks + 1.0 )) |
288 fi |
|
289 |
|
290 |
|
291 ### re7 'power' test 2 |
|
292 |
|
293 if [ $tsts -eq 0 ] |
|
294 then |
|
295 echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out |
|
296 echo -e " matcher(EVIL, \"a\" * 1000000 ++ \"b\") == true" | tee -a $out |
|
297 echo -e " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out |
|
298 START=$(date +%s) |
|
299 |
|
300 if (scala_assert_thirty "re.scala" "re_test7.scala") |
|
301 then |
|
302 END=$(date +%s) |
|
303 DIFF=$(( $END - $START )) |
|
304 echo " This test ran for $DIFF seconds" | tee -a $out |
|
305 echo -e " --> success" | tee -a $out |
|
306 marks=$(( marks + 0.5 )) |
|
307 else |
327 else |
308 END=$(date +%s) |
328 END=$(date +%s) |
309 DIFF=$(( $END - $START )) |
329 DIFF=$(( $END - $START )) |
310 echo " This test ran for $DIFF seconds" | tee -a $out |
330 echo " This test ran for $DIFF seconds" | tee -a $out |
311 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
331 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
312 fi |
332 fi |
313 fi |
333 fi |
314 |
334 |
315 |
335 |
316 |
336 |
|
337 |
|
338 |
317 ## final marks |
339 ## final marks |
318 echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out |
340 echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out |
319 printf " %0.1f\n" $marks | tee -a $out |
341 printf " %0.1f\n" $marks | tee -a $out |
320 |
342 |
321 |
343 |