424
|
1 |
#!/bin/zsh
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
# to make the script fail safely
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
set -euo pipefail
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
out=${1:-output}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
echo -e "" > $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
echo -e `date` >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
echo -e "Below is the feedback and provisional marks for your submission" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
echo -e "for the Main Part 3 (Scala). Please note all marks are provisional until" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
echo -e "ratified by the assessment board -- this is not an official" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
echo -e "results transcript." >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
# marks for CW8
|
424
|
19 |
marks=$(( 0.0 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
# compilation tests
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
function scala_compile {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
# functional tests
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
function scala_assert {
|
463
|
30 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
function scala_assert_thirty {
|
463
|
34 |
(ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
# purity test
|
424
|
38 |
function scala_vars {
|
|
39 |
(sed 's/immutable/ok/g' c$out > cb$out;
|
|
40 |
egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
|
|
41 |
}
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
echo -e "Below is the feedback for your submission re.scala" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
### compilation test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
echo -e "re.scala runs?" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
if (scala_compile re.scala)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
echo -e " --> success" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
tsts=$(( 0 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
echo -e " --> SCALA DID NOT RUN re.scala" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
tsts=$(( 1 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
# var, return, ListBuffer test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
#
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
echo -e "re.scala does not contain VARS, RETURNS etc?" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
if (scala_vars re.scala)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
tsts=$(( 1 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
echo -e " --> success" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
tsts=$(( 0 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
tsts=$(( 1 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
|
426
|
83 |
### make sure datatypes are not tampered with
|
|
84 |
|
|
85 |
if [ $tsts -eq 0 ]
|
|
86 |
then
|
463
|
87 |
echo -e "re.scala has case classes for ALTs and SEQs?" | tee -a $out
|
426
|
88 |
|
|
89 |
if (scala_assert "re.scala" "re_test0.scala")
|
|
90 |
then
|
463
|
91 |
echo -e " --> passed" | tee -a $out
|
426
|
92 |
tsts=$(( 0 ))
|
|
93 |
else
|
463
|
94 |
echo -e " --> FAIL" | tee -a $out
|
426
|
95 |
tsts=$(( 1 ))
|
|
96 |
fi
|
|
97 |
else
|
|
98 |
tsts=$(( 1 ))
|
|
99 |
fi
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
100 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
101 |
|
463
|
102 |
### re1 nullable test
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
103 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
echo -e " nullable(ZERO) == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
echo -e " nullable(ONE) == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
echo -e " nullable(CHAR('a')) == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
echo -e " nullable(ZERO | ONE) == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
echo -e " nullable(ZERO | CHAR('a')) == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
echo -e " nullable(ONE ~ ONE) == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
112 |
echo -e " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
echo -e " nullable(STAR(ZERO)) == true" | tee -a $out
|
463
|
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
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
if (scala_assert "re.scala" "re_test1.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
then
|
463
|
119 |
echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out
|
424
|
120 |
marks=$(( marks + 0.5 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
121 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
|
463
|
126 |
### re2 der test
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
|
463
|
131 |
echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), SEQs(List(ONE)))" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
133 |
echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
echo -e " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
echo -e " der('a', r0) == (ONE ~ \"b\") ~ \"c\"" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
echo -e " der('b', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
echo -e " der('c', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
141 |
echo -e " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out
|
463
|
142 |
echo -e " der('a', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out
|
|
143 |
echo -e " der('b', r1) == ((ZERO ~ \"b\") | SEQs(List(ONE))) ~ \"c\"" | tee -a $out
|
|
144 |
echo -e " der('c', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
146 |
echo -e " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out
|
463
|
147 |
echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out
|
|
148 |
echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out
|
|
149 |
echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ONE)))" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
150 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
151 |
if (scala_assert "re.scala" "re_test2.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
152 |
then
|
463
|
153 |
echo -e " --> success (+ 1 Mark)\n" | tee -a $out
|
424
|
154 |
marks=$(( marks + 1.0 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
155 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
156 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
157 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
158 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
159 |
|
463
|
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
|
|
216 |
fi
|
|
217 |
fi
|
|
218 |
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
219 |
### re3 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
220 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
221 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
222 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
223 |
echo -e " simp(ZERO | ONE) == ONE" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
224 |
echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
225 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
226 |
echo -e " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
227 |
echo -e " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
228 |
echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
229 |
echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
230 |
echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
231 |
echo -e " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
232 |
echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
233 |
echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
234 |
echo -e " ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
235 |
echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
236 |
echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
237 |
echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
|
463
|
238 |
echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE, CHAR('a'))" | tee -a $out
|
|
239 |
echo -e " simp(ALTs(Nil)) == ZERO" | tee -a $out
|
|
240 |
echo -e " simp(SEQs(List(CHAR('a')))) == CHAR('a')" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
241 |
if (scala_assert "re.scala" "re_test3.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
242 |
then
|
463
|
243 |
echo -e " --> success (+ 1 Mark)\n" | tee -a $out
|
424
|
244 |
marks=$(( marks + 1.0 ))
|
|
245 |
else
|
|
246 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
|
247 |
fi
|
|
248 |
fi
|
|
249 |
|
|
250 |
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
251 |
### re4 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
252 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
253 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
254 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
255 |
echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
|
463
|
256 |
echo -e " ders((\"a\" * 5).toList,EVIL) == SEQs(List(STAR(CHAR('a')), STAR(STAR(CHAR('a'))), CHAR('b')))" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
257 |
echo -e " ders(List('b'),EVIL) == ONE" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
258 |
echo -e " ders(List('b','b'),EVIL) == ZERO" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
259 |
echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
260 |
echo -e " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
261 |
echo -e " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
262 |
echo -e " matcher(EVIL, \"b\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
263 |
echo -e " matcher(EVIL, \"bb\") == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
264 |
echo -e " matcher(\"abc\", \"abc\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
265 |
echo -e " matcher(\"abc\", \"ab\") == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
266 |
echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
267 |
echo -e " matcher(ONE, \"\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
268 |
echo -e " matcher(ZERO, \"\") == false" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
269 |
echo -e " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
270 |
echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
271 |
|
463
|
272 |
if (scala_assert "re.scala" "re_test7.scala")
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
273 |
then
|
463
|
274 |
echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out
|
|
275 |
marks=$(( marks + 0.5 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
276 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
277 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
278 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
279 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
280 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
281 |
### re5 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
282 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
283 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
284 |
then
|
463
|
285 |
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
|
|
287 |
echo -e " size(der('a', der('a', der('a', EVIL)))) == 83" | tee -a $out
|
|
288 |
echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 7" | tee -a $out
|
|
289 |
echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 7" | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
290 |
|
463
|
291 |
if (scala_assert "re.scala" "re_test8.scala")
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
292 |
then
|
463
|
293 |
echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out
|
424
|
294 |
marks=$(( marks + 0.5 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
295 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
296 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
297 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
298 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
299 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
300 |
### re6 'power' test 1
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
301 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
302 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
303 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
304 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
305 |
echo -e " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
306 |
echo -e " ...the Iterator produces the rexp" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
307 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
308 |
echo -e " SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
309 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
310 |
echo -e " where SEQ is nested 50 times." | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
311 |
echo -e "" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
312 |
echo -e " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
313 |
echo -e " ... the Iterator produces a rexp of size 2097151" | tee -a $out
|
463
|
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
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
318 |
START=$(date +%s)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
319 |
|
463
|
320 |
if (scala_assert_thirty "re.scala" "re_test9.scala")
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
321 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
322 |
END=$(date +%s)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
323 |
DIFF=$(( $END - $START ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
324 |
echo " This test ran for $DIFF seconds" | tee -a $out
|
463
|
325 |
echo -e " --> success (+ 1.0 Mark)\n" | tee -a $out
|
|
326 |
marks=$(( marks + 1.0 ))
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
327 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
328 |
END=$(date +%s)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
329 |
DIFF=$(( $END - $START ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
330 |
echo " This test ran for $DIFF seconds" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
331 |
echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
332 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
333 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
334 |
|
424
|
335 |
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
336 |
|
463
|
337 |
|
|
338 |
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
339 |
## final marks
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
340 |
echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out
|
424
|
341 |
printf " %0.1f\n" $marks | tee -a $out
|
390
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
342 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
343 |
|
424
|
344 |
|