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