249
|
1 |
#!/bin/bash
|
|
2 |
set -euo pipefail
|
|
3 |
|
|
4 |
|
|
5 |
out=${1:-output}
|
|
6 |
|
|
7 |
echo -e "" > $out
|
|
8 |
|
300
|
9 |
echo -e "Below is the feedback for your submission of CW 9, Preliminary Part." >> $out
|
249
|
10 |
echo -e "" >> $out
|
|
11 |
|
|
12 |
|
|
13 |
# compilation tests
|
|
14 |
|
|
15 |
function scala_compile {
|
266
|
16 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
249
|
17 |
}
|
|
18 |
|
|
19 |
# functional tests
|
|
20 |
|
|
21 |
function scala_assert {
|
300
|
22 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
249
|
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 |
#
|
|
34 |
echo -e "postfix.scala does not contain vars, returns etc?" >> $out
|
|
35 |
|
|
36 |
if (scala_vars postfix.scala)
|
|
37 |
then
|
300
|
38 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
249
|
39 |
tsts0=$(( 0 ))
|
|
40 |
else
|
|
41 |
echo -e " --> success" >> $out
|
|
42 |
tsts0=$(( 0 ))
|
|
43 |
fi
|
|
44 |
|
|
45 |
|
|
46 |
# compilation test
|
|
47 |
|
|
48 |
if [ $tsts0 -eq 0 ]
|
|
49 |
then
|
|
50 |
echo -e "postfix.scala runs?" >> $out
|
|
51 |
|
|
52 |
if (scala_compile postfix.scala)
|
|
53 |
then
|
|
54 |
echo -e " --> yes" >> $out
|
|
55 |
tsts1=$(( 0 ))
|
|
56 |
else
|
|
57 |
echo -e " --> SCALA DID NOT RUN POSTFIX.SCALA\n" >> $out
|
|
58 |
tsts1=$(( 1 ))
|
|
59 |
fi
|
|
60 |
else
|
|
61 |
tsts1=$(( 1 ))
|
|
62 |
fi
|
|
63 |
|
|
64 |
### postfix tests
|
|
65 |
|
|
66 |
if [ $tsts1 -eq 0 ]
|
|
67 |
then
|
250
|
68 |
echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
|
249
|
69 |
echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
|
|
70 |
echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
|
250
|
71 |
echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
|
249
|
72 |
|
|
73 |
if (scala_assert "postfix.scala" "postfix_test7.scala")
|
|
74 |
then
|
|
75 |
echo -e " --> success" >> $out
|
|
76 |
else
|
|
77 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
78 |
fi
|
|
79 |
fi
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
if [ $tsts1 -eq 0 ]
|
|
84 |
then
|
|
85 |
echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
|
|
86 |
echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
|
|
87 |
echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
|
|
88 |
echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
|
|
89 |
echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
|
|
90 |
echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
|
|
91 |
|
|
92 |
if (scala_assert "postfix.scala" "postfix_test8.scala")
|
|
93 |
then
|
|
94 |
echo -e " --> success" >> $out
|
|
95 |
else
|
|
96 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
97 |
fi
|
|
98 |
fi
|
|
99 |
|
300
|
100 |
echo -e "" >> $out
|
249
|
101 |
|
|
102 |
### postfix2 tests
|
|
103 |
|
|
104 |
# var, return, ListBuffer test
|
|
105 |
#
|
|
106 |
echo -e "\n\npostfix2.scala does not contain vars, returns etc?" >> $out
|
|
107 |
|
|
108 |
if (scala_vars postfix2.scala)
|
|
109 |
then
|
300
|
110 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
249
|
111 |
tsts0=$(( 0 ))
|
|
112 |
else
|
|
113 |
echo -e " --> success" >> $out
|
|
114 |
tsts0=$(( 0 ))
|
|
115 |
fi
|
|
116 |
|
|
117 |
|
|
118 |
# compilation test
|
|
119 |
|
|
120 |
if [ $tsts0 -eq 0 ]
|
|
121 |
then
|
|
122 |
echo -e "postfix2.scala runs?" >> $out
|
|
123 |
|
|
124 |
if (scala_compile postfix2.scala)
|
|
125 |
then
|
|
126 |
echo -e " --> yes" >> $out
|
|
127 |
tsts1=$(( 0 ))
|
|
128 |
else
|
|
129 |
echo -e " --> SCALA DID NOT RUN POSTFIX2.SCALA\n" >> $out
|
|
130 |
tsts1=$(( 1 ))
|
|
131 |
fi
|
|
132 |
else
|
|
133 |
tsts1=$(( 1 ))
|
|
134 |
fi
|
|
135 |
|
|
136 |
|
|
137 |
if [ $tsts1 -eq 0 ]
|
|
138 |
then
|
250
|
139 |
echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
|
249
|
140 |
echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
|
|
141 |
echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
|
250
|
142 |
echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
|
249
|
143 |
echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " >> $out
|
250
|
144 |
echo -e " List(\"3\", \"4\", \"8\", \"\*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" >> $out
|
249
|
145 |
echo -e " " >> $out
|
|
146 |
echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
|
|
147 |
echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
|
|
148 |
echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
|
|
149 |
echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
|
|
150 |
echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
|
|
151 |
echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
|
|
152 |
echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out
|
|
153 |
echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out
|
|
154 |
echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out
|
|
155 |
echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out
|
|
156 |
|
|
157 |
if (scala_assert "postfix2.scala" "postfix_test9.scala")
|
|
158 |
then
|
|
159 |
echo -e " --> success" >> $out
|
|
160 |
else
|
|
161 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
162 |
fi
|
|
163 |
fi
|
|
164 |
|