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 {
|
347
|
16 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
|
153
|
17 |
}
|
|
18 |
|
|
19 |
# functional tests
|
|
20 |
|
|
21 |
function scala_assert {
|
347
|
22 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
153
|
23 |
}
|
|
24 |
|
|
25 |
# purity test
|
|
26 |
|
|
27 |
function scala_vars {
|
376
|
28 |
(egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
|
153
|
29 |
}
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
# compilation test
|
221
|
34 |
|
347
|
35 |
echo -e "re.scala runs?" >> $out
|
153
|
36 |
|
347
|
37 |
if (scala_compile re.scala)
|
|
38 |
then
|
352
|
39 |
echo -e " --> passed" >> $out
|
347
|
40 |
tsts=$(( 0 ))
|
|
41 |
else
|
221
|
42 |
echo -e " --> SCALA DID NOT RUN RE.SCALA\n" >> $out
|
347
|
43 |
tsts=$(( 1 ))
|
153
|
44 |
fi
|
|
45 |
|
347
|
46 |
# var, return, ListBuffer test
|
|
47 |
#
|
|
48 |
|
|
49 |
if [ $tsts -eq 0 ]
|
|
50 |
then
|
|
51 |
echo -e "re.scala does not contain vars, returns etc?" >> $out
|
|
52 |
|
|
53 |
if (scala_vars re.scala)
|
|
54 |
then
|
|
55 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
|
56 |
tsts=$(( 1 ))
|
|
57 |
else
|
352
|
58 |
echo -e " --> passed" >> $out
|
347
|
59 |
tsts=$(( 0 ))
|
|
60 |
fi
|
|
61 |
fi
|
|
62 |
|
|
63 |
|
|
64 |
|
221
|
65 |
### re tests
|
153
|
66 |
|
347
|
67 |
if [ $tsts -eq 0 ]
|
153
|
68 |
then
|
221
|
69 |
echo -e " nullable(ZERO) == false" >> $out
|
|
70 |
echo -e " nullable(ONE) == true" >> $out
|
|
71 |
echo -e " nullable(CHAR('a')) == false" >> $out
|
|
72 |
echo -e " nullable(ZERO | ONE) == true" >> $out
|
|
73 |
echo -e " nullable(ZERO | CHAR('a')) == false" >> $out
|
|
74 |
echo -e " nullable(ONE ~ ONE) == true" >> $out
|
|
75 |
echo -e " nullable(ONE ~ CHAR('a')) == false" >> $out
|
|
76 |
echo -e " nullable(STAR(ZERO)) == true" >> $out
|
153
|
77 |
|
221
|
78 |
if (scala_assert "re.scala" "re_test1.scala")
|
153
|
79 |
then
|
221
|
80 |
echo -e " --> success" >> $out
|
153
|
81 |
else
|
221
|
82 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
83 |
fi
|
|
84 |
fi
|
|
85 |
|
|
86 |
|
|
87 |
|
347
|
88 |
if [ $tsts -eq 0 ]
|
153
|
89 |
then
|
221
|
90 |
echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" >> $out
|
|
91 |
echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) ==" >> $out
|
|
92 |
echo -e " ALT((ONE | ZERO) ~ CHAR('a'), ONE)" >> $out
|
|
93 |
echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" >> $out
|
|
94 |
echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" >> $out
|
153
|
95 |
|
221
|
96 |
if (scala_assert "re.scala" "re_test2.scala")
|
153
|
97 |
then
|
221
|
98 |
echo -e " --> success" >> $out
|
153
|
99 |
else
|
221
|
100 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
101 |
fi
|
|
102 |
fi
|
|
103 |
|
|
104 |
|
|
105 |
|
347
|
106 |
if [ $tsts -eq 0 ]
|
153
|
107 |
then
|
221
|
108 |
echo -e " simp(ZERO | ONE) == ONE" >> $out
|
|
109 |
echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" >> $out
|
|
110 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" >> $out
|
329
|
111 |
echo -e " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a'))" >> $out
|
|
112 |
echo -e " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a'))" >> $out
|
221
|
113 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" >> $out
|
|
114 |
echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" >> $out
|
|
115 |
echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" >> $out
|
329
|
116 |
echo -e " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" >> $out
|
221
|
117 |
echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" >> $out
|
|
118 |
echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," >> $out
|
|
119 |
echo -e " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" >> $out
|
315
|
120 |
echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" >> $out
|
|
121 |
echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" >> $out
|
|
122 |
echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" >> $out
|
|
123 |
echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" >> $out
|
221
|
124 |
if (scala_assert "re.scala" "re_test3.scala")
|
153
|
125 |
then
|
221
|
126 |
echo -e " --> success" >> $out
|
153
|
127 |
else
|
221
|
128 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
129 |
fi
|
|
130 |
fi
|
|
131 |
|
|
132 |
|
347
|
133 |
if [ $tsts -eq 0 ]
|
153
|
134 |
then
|
221
|
135 |
echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
|
|
136 |
echo -e " ders(\"aaaaa\".toList, EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" >> $out
|
|
137 |
echo -e " ders(List('b'), EVIL) == ONE" >> $out
|
|
138 |
echo -e " ders(\"bb\".toList, EVIL) == ZERO" >> $out
|
|
139 |
echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" >> $out
|
|
140 |
echo -e " matcher(EVIL, \"b\") == true" >> $out
|
|
141 |
echo -e " matcher(EVIL, \"bb\") == false" >> $out
|
|
142 |
echo -e " matcher(\"abc\", \"abc\") == true" >> $out
|
|
143 |
echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" >> $out
|
|
144 |
echo -e " matcher(ONE, \"\") == true" >> $out
|
|
145 |
echo -e " matcher(ZERO, \"\") == false" >> $out
|
|
146 |
echo -e " matcher(ONE | CHAR('a'), \"\") == true" >> $out
|
|
147 |
echo -e " matcher(ONE | CHAR('a'), \"a\") == true" >> $out
|
153
|
148 |
|
221
|
149 |
if (scala_assert "re.scala" "re_test4.scala")
|
153
|
150 |
then
|
221
|
151 |
echo -e " --> success" >> $out
|
153
|
152 |
else
|
221
|
153 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
154 |
fi
|
|
155 |
fi
|
|
156 |
|
|
157 |
|
347
|
158 |
if [ $tsts -eq 0 ]
|
153
|
159 |
then
|
221
|
160 |
echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
|
|
161 |
echo -e " size(der('a', der('a', EVIL))) == 28" >> $out
|
|
162 |
echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" >> $out
|
|
163 |
echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" >> $out
|
153
|
164 |
|
221
|
165 |
if (scala_assert "re.scala" "re_test5.scala")
|
153
|
166 |
then
|
221
|
167 |
echo -e " --> success" >> $out
|
153
|
168 |
else
|
221
|
169 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
153
|
170 |
fi
|
|
171 |
fi
|
|
172 |
|
|
173 |
|