153
|
1 |
#!/bin/bash
|
221
|
2 |
set -euo pipefail
|
|
3 |
|
153
|
4 |
|
|
5 |
out=${1:-output}
|
|
6 |
|
221
|
7 |
echo -e "" > $out
|
153
|
8 |
|
347
|
9 |
echo -e "Below is the feedback for your submission of re.scala." >> $out
|
221
|
10 |
echo -e "" >> $out
|
153
|
11 |
|
|
12 |
|
|
13 |
# compilation tests
|
|
14 |
|
|
15 |
function scala_compile {
|
477
|
16 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile -Xprint:parser "$1" 2> c$out 1> c$out)
|
153
|
17 |
}
|
|
18 |
|
|
19 |
# functional tests
|
|
20 |
|
|
21 |
function scala_assert {
|
475
|
22 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null)
|
153
|
23 |
}
|
|
24 |
|
|
25 |
# purity test
|
|
26 |
function scala_vars {
|
475
|
27 |
(sed 's/immutable/ok/g' c$out > cb$out;
|
|
28 |
egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
|
153
|
29 |
}
|
|
30 |
|
|
31 |
|
|
32 |
# compilation test
|
221
|
33 |
|
347
|
34 |
echo -e "re.scala runs?" >> $out
|
153
|
35 |
|
347
|
36 |
if (scala_compile re.scala)
|
|
37 |
then
|
352
|
38 |
echo -e " --> passed" >> $out
|
347
|
39 |
tsts=$(( 0 ))
|
|
40 |
else
|
221
|
41 |
echo -e " --> SCALA DID NOT RUN RE.SCALA\n" >> $out
|
347
|
42 |
tsts=$(( 1 ))
|
153
|
43 |
fi
|
|
44 |
|
347
|
45 |
# var, return, ListBuffer test
|
|
46 |
#
|
|
47 |
|
|
48 |
if [ $tsts -eq 0 ]
|
|
49 |
then
|
|
50 |
echo -e "re.scala does not contain vars, returns etc?" >> $out
|
|
51 |
|
|
52 |
if (scala_vars re.scala)
|
|
53 |
then
|
433
|
54 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
347
|
55 |
tsts=$(( 1 ))
|
|
56 |
else
|
352
|
57 |
echo -e " --> passed" >> $out
|
347
|
58 |
tsts=$(( 0 ))
|
|
59 |
fi
|
|
60 |
fi
|
|
61 |
|
426
|
62 |
### make sure datatypes are not tampered with
|
347
|
63 |
|
426
|
64 |
if [ $tsts -eq 0 ]
|
|
65 |
then
|
|
66 |
echo -e "re.scala has case classes for ALTs and SEQs?" >> $out
|
|
67 |
|
|
68 |
if (scala_assert "re.scala" "re_test0.scala")
|
|
69 |
then
|
|
70 |
echo -e " --> passed" >> $out
|
|
71 |
tsts=$(( 0 ))
|
|
72 |
else
|
|
73 |
echo -e " --> FAIL (make sure the case clases are as given in the template)" >> $out
|
|
74 |
tsts=$(( 1 ))
|
|
75 |
fi
|
|
76 |
fi
|
347
|
77 |
|
221
|
78 |
### re tests
|
153
|
79 |
|
347
|
80 |
if [ $tsts -eq 0 ]
|
153
|
81 |
then
|
221
|
82 |
echo -e " nullable(ZERO) == false" >> $out
|
|
83 |
echo -e " nullable(ONE) == true" >> $out
|
|
84 |
echo -e " nullable(CHAR('a')) == false" >> $out
|
|
85 |
echo -e " nullable(ZERO | ONE) == true" >> $out
|
|
86 |
echo -e " nullable(ZERO | CHAR('a')) == false" >> $out
|
|
87 |
echo -e " nullable(ONE ~ ONE) == true" >> $out
|
|
88 |
echo -e " nullable(ONE ~ CHAR('a')) == false" >> $out
|
|
89 |
echo -e " nullable(STAR(ZERO)) == true" >> $out
|
433
|
90 |
echo -e " nullable(ALTs(List(ONE, CHAR('a'), ZERO))) == true" >> $out
|
|
91 |
echo -e " nullable(SEQs(List(ONE, ALTs(List(ONE, CHAR('a'), ZERO)), STAR(ZERO)))) == true" >> $out
|
153
|
92 |
|
221
|
93 |
if (scala_assert "re.scala" "re_test1.scala")
|
153
|
94 |
then
|
221
|
95 |
echo -e " --> success" >> $out
|
153
|
96 |
else
|
221
|
97 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
98 |
fi
|
|
99 |
fi
|
|
100 |
|
|
101 |
|
347
|
102 |
if [ $tsts -eq 0 ]
|
153
|
103 |
then
|
221
|
104 |
echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" >> $out
|
|
105 |
echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) ==" >> $out
|
453
|
106 |
echo -e " ALT((ONE | ZERO) ~ CHAR('a'), SEQs(List(ONE)))" >> $out
|
433
|
107 |
echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" >> $out
|
221
|
108 |
echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" >> $out
|
|
109 |
echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" >> $out
|
153
|
110 |
|
221
|
111 |
if (scala_assert "re.scala" "re_test2.scala")
|
153
|
112 |
then
|
221
|
113 |
echo -e " --> success" >> $out
|
153
|
114 |
else
|
221
|
115 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
116 |
fi
|
|
117 |
fi
|
|
118 |
|
|
119 |
|
347
|
120 |
if [ $tsts -eq 0 ]
|
153
|
121 |
then
|
221
|
122 |
echo -e " simp(ZERO | ONE) == ONE" >> $out
|
|
123 |
echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" >> $out
|
|
124 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" >> $out
|
424
|
125 |
echo -e " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" >> $out
|
|
126 |
echo -e " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" >> $out
|
221
|
127 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" >> $out
|
|
128 |
echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" >> $out
|
|
129 |
echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" >> $out
|
329
|
130 |
echo -e " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" >> $out
|
221
|
131 |
echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" >> $out
|
|
132 |
echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," >> $out
|
|
133 |
echo -e " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" >> $out
|
315
|
134 |
echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" >> $out
|
|
135 |
echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" >> $out
|
|
136 |
echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" >> $out
|
403
|
137 |
echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE, CHAR('a'))" >> $out
|
433
|
138 |
echo -e " simp(ALTs(Nil)) == ZERO" >> $out
|
455
|
139 |
echo -e " simp(SEQs(List(CHAR('a')))) == CHAR('a')" >> $out
|
221
|
140 |
if (scala_assert "re.scala" "re_test3.scala")
|
153
|
141 |
then
|
221
|
142 |
echo -e " --> success" >> $out
|
153
|
143 |
else
|
221
|
144 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
145 |
fi
|
|
146 |
fi
|
|
147 |
|
|
148 |
|
347
|
149 |
if [ $tsts -eq 0 ]
|
153
|
150 |
then
|
433
|
151 |
echo -e " denest(List(ONE, ZERO, ALTs(List(ONE, CHAR('a'))))) == List(ONE, ONE, CHAR('a'))" >> $out
|
|
152 |
echo -e " denest(List(ONE ~ ONE, ZERO, ZERO | ONE)) == List(ONE ~ ONE, ZERO, ONE)" >> $out
|
|
153 |
|
|
154 |
if (scala_assert "re.scala" "re_test4.scala")
|
|
155 |
then
|
|
156 |
echo -e " --> success" >> $out
|
|
157 |
else
|
|
158 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
159 |
fi
|
|
160 |
fi
|
|
161 |
|
|
162 |
|
|
163 |
if [ $tsts -eq 0 ]
|
|
164 |
then
|
|
165 |
echo -e " flts(List(CHAR('a'), ZERO, ONE), Nil) == List(ZERO)" >> $out
|
|
166 |
echo -e " flts(List(CHAR('a'), ONE, ONE, CHAR('b')), Nil) == List(CHAR('a'), CHAR('b'))" >> $out
|
|
167 |
echo -e " flts(List(ONE ~ CHAR('a'), CHAR('b') ~ ONE), Nil) == List(ONE, CHAR('a'), CHAR('b'), ONE)" >> $out
|
|
168 |
|
|
169 |
if (scala_assert "re.scala" "re_test5.scala")
|
|
170 |
then
|
|
171 |
echo -e " --> success" >> $out
|
|
172 |
else
|
|
173 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
174 |
fi
|
|
175 |
fi
|
|
176 |
|
|
177 |
|
|
178 |
if [ $tsts -eq 0 ]
|
|
179 |
then
|
|
180 |
echo -e " SEQs_smart(Nil) == ONE" >> $out
|
|
181 |
echo -e " SEQs_smart(List(ZERO)) == ZERO" >> $out
|
|
182 |
echo -e " SEQs_smart(List(CHAR('a'))) == CHAR('a')" >> $out
|
|
183 |
echo -e " SEQs_smart(List(ONE ~ ONE)) == ONE ~ ONE" >> $out
|
|
184 |
echo -e " SEQs_smart(List(ONE, ONE)) == SEQs(List(ONE, ONE))" >> $out
|
|
185 |
echo -e " ALTs_smart(Nil) == ZERO" >> $out
|
456
|
186 |
echo -e " ALTs_smart(List(ONE ~ ONE)) == ONE ~ ONE" >> $out
|
433
|
187 |
echo -e " ALTs_smart(List(ZERO, ZERO)) == ALTs(List(ZERO, ZERO))" >> $out
|
|
188 |
|
|
189 |
if (scala_assert "re.scala" "re_test6.scala")
|
|
190 |
then
|
|
191 |
echo -e " --> success" >> $out
|
|
192 |
else
|
|
193 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
194 |
fi
|
|
195 |
fi
|
|
196 |
|
|
197 |
|
|
198 |
if [ $tsts -eq 0 ]
|
|
199 |
then
|
221
|
200 |
echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
|
445
|
201 |
echo -e " ders(\"aaaaa\".toList, EVIL) == SEQs(List(STAR(CHAR('a')), STAR(STAR(CHAR('a'))), CHAR('b')))" >> $out
|
221
|
202 |
echo -e " ders(List('b'), EVIL) == ONE" >> $out
|
|
203 |
echo -e " ders(\"bb\".toList, EVIL) == ZERO" >> $out
|
|
204 |
echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" >> $out
|
|
205 |
echo -e " matcher(EVIL, \"b\") == true" >> $out
|
|
206 |
echo -e " matcher(EVIL, \"bb\") == false" >> $out
|
|
207 |
echo -e " matcher(\"abc\", \"abc\") == true" >> $out
|
|
208 |
echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" >> $out
|
|
209 |
echo -e " matcher(ONE, \"\") == true" >> $out
|
|
210 |
echo -e " matcher(ZERO, \"\") == false" >> $out
|
|
211 |
echo -e " matcher(ONE | CHAR('a'), \"\") == true" >> $out
|
|
212 |
echo -e " matcher(ONE | CHAR('a'), \"a\") == true" >> $out
|
153
|
213 |
|
433
|
214 |
if (scala_assert "re.scala" "re_test7.scala")
|
153
|
215 |
then
|
221
|
216 |
echo -e " --> success" >> $out
|
153
|
217 |
else
|
221
|
218 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
219 |
fi
|
|
220 |
fi
|
|
221 |
|
|
222 |
|
347
|
223 |
if [ $tsts -eq 0 ]
|
153
|
224 |
then
|
221
|
225 |
echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
|
433
|
226 |
echo -e " size(der('a', der('a', EVIL))) == 36" >> $out
|
|
227 |
echo -e " size(der('a', der('a', der('a', EVIL)))) == 83" >> $out
|
|
228 |
echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 7" >> $out
|
|
229 |
echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 7" >> $out
|
153
|
230 |
|
433
|
231 |
if (scala_assert "re.scala" "re_test8.scala")
|
153
|
232 |
then
|
221
|
233 |
echo -e " --> success" >> $out
|
153
|
234 |
else
|
221
|
235 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
236 |
fi
|
|
237 |
fi
|
|
238 |
|
|
239 |
|