1 #!/bin/zsh |
|
2 set -euo pipefail |
|
3 |
|
4 |
|
5 out=${1:-output} |
|
6 |
|
7 echo -e "" > $out |
|
8 |
|
9 echo `date` >> $out |
|
10 echo -e "Below is the feedback and provisional marks for your submission" >> $out |
|
11 echo -e "of the Preliminary Part of Part 3 (Scala). Please note all marks are provisional until" >> $out |
|
12 echo -e "ratified by the assessment board -- this is not an official" >> $out |
|
13 echo -e "results transcript." >> $out |
|
14 echo -e "" >> $out |
|
15 |
|
16 echo -e "Below is the feedback for your submission docdiff.scala" >> $out |
|
17 echo -e "" >> $out |
|
18 |
|
19 |
|
20 # marks for CW9 preliminary |
|
21 marks=$(( 0.0 )) |
|
22 |
|
23 |
|
24 # compilation tests |
|
25 |
|
26 function scala_compile { |
|
27 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
|
28 } |
|
29 |
|
30 # functional tests |
|
31 |
|
32 function scala_assert { |
|
33 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
34 } |
|
35 |
|
36 # purity test |
|
37 |
|
38 function scala_vars { |
|
39 (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) |
|
40 } |
|
41 |
|
42 # compilation test |
|
43 |
|
44 echo -e "postfix.scala runs?" | tee -a $out |
|
45 |
|
46 if (scala_compile postfix.scala) |
|
47 then |
|
48 echo -e " --> success" | tee -a $out |
|
49 tsts=$(( 0 )) |
|
50 else |
|
51 echo -e " --> SCALA DID NOT RUN postfix.scala\n" | tee -a $out |
|
52 tsts=$(( 1 )) |
|
53 fi |
|
54 |
|
55 |
|
56 |
|
57 # var, return, ListBuffer test |
|
58 # |
|
59 if [ $tsts -eq 0 ] |
|
60 then |
|
61 echo -e "postfix.scala does not contain VARS, RETURNS etc?" | tee -a $out |
|
62 |
|
63 if (scala_vars postfix.scala) |
|
64 then |
|
65 echo -e " --> FAIL\n" | tee -a $out |
|
66 tsts=$(( 1 )) |
|
67 else |
|
68 echo -e " --> success" | tee -a $out |
|
69 tsts=$(( 0 )) |
|
70 fi |
|
71 else |
|
72 tsts=$(( 1 )) |
|
73 fi |
|
74 |
|
75 |
|
76 |
|
77 ### postfix tests |
|
78 |
|
79 if [ $tsts -eq 0 ] |
|
80 then |
|
81 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out |
|
82 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out |
|
83 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out |
|
84 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out |
|
85 |
|
86 if (scala_assert "postfix.scala" "postfix_test1.scala") |
|
87 then |
|
88 echo -e " --> success" | tee -a $out |
|
89 marks=$(( marks + 1.0 )) |
|
90 else |
|
91 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
92 fi |
|
93 fi |
|
94 |
|
95 |
|
96 |
|
97 if [ $tsts -eq 0 ] |
|
98 then |
|
99 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out |
|
100 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out |
|
101 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out |
|
102 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out |
|
103 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out |
|
104 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out |
|
105 |
|
106 if (scala_assert "postfix.scala" "postfix_test2.scala") |
|
107 then |
|
108 echo -e " --> success" | tee -a $out |
|
109 marks=$(( marks + 1.0 )) |
|
110 else |
|
111 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
112 fi |
|
113 fi |
|
114 |
|
115 |
|
116 |
|
117 ### postfix2 tests |
|
118 |
|
119 echo -e "Below is the feedback for your submission postfix2.scala" >> $out |
|
120 echo -e "" >> $out |
|
121 |
|
122 # compilation test |
|
123 |
|
124 echo -e "postfix2.scala runs?" | tee -a $out |
|
125 |
|
126 if (scala_compile postfix2.scala) |
|
127 then |
|
128 echo -e " --> success" | tee -a $out |
|
129 tsts=$(( 0 )) |
|
130 else |
|
131 echo -e " --> SCALA DID NOT RUN postfix2.scala\n" | tee -a $out |
|
132 tsts=$(( 1 )) |
|
133 fi |
|
134 |
|
135 |
|
136 # var, return, ListBuffer test |
|
137 # |
|
138 if [ $tsts -eq 0 ] |
|
139 then |
|
140 echo -e "postfix2.scala does not contain VARS, RETURNS etc?" | tee -a $out |
|
141 |
|
142 if (scala_vars postfix2.scala) |
|
143 then |
|
144 echo -e " --> FAIL\n" | tee -a $out |
|
145 tsts=$(( 1 )) |
|
146 else |
|
147 echo -e " --> success" | tee -a $out |
|
148 tsts=$(( 0 )) |
|
149 fi |
|
150 else |
|
151 tsts=$(( 1 )) |
|
152 fi |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 if [ $tsts -eq 0 ] |
|
158 then |
|
159 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out |
|
160 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out |
|
161 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out |
|
162 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out |
|
163 echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " | tee -a $out |
|
164 echo -e " List(\"3\", \"4\", \"8\", \"*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" | tee -a $out |
|
165 |
|
166 if (scala_assert "postfix2.scala" "postfix_test3.scala") |
|
167 then |
|
168 echo -e " --> success" | tee -a $out |
|
169 marks=$(( marks + 0.5 )) |
|
170 else |
|
171 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
172 fi |
|
173 fi |
|
174 |
|
175 if [ $tsts -eq 0 ] |
|
176 then |
|
177 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out |
|
178 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out |
|
179 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out |
|
180 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out |
|
181 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out |
|
182 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out |
|
183 echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" | tee -a $out |
|
184 echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" | tee -a $out |
|
185 echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" | tee -a $out |
|
186 echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" | tee -a $out |
|
187 |
|
188 if (scala_assert "postfix2.scala" "postfix_test4.scala") |
|
189 then |
|
190 echo -e " --> success" | tee -a $out |
|
191 marks=$(( marks + 0.5 )) |
|
192 else |
|
193 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
194 fi |
|
195 fi |
|
196 |
|
197 ## final marks |
|
198 echo -e "Overall mark for the Preliminary Part 3 (Scala)" | tee -a $out |
|
199 printf " %0.1f\n" $marks | tee -a $out |
|
200 |
|