|
1 #!/bin/bash |
|
2 set -euo pipefail |
|
3 |
|
4 |
|
5 out=${1:-output} |
|
6 |
|
7 echo -e "" > $out |
|
8 |
|
9 |
|
10 echo "Below is the feedback and provisional marks for your submission" >> $out |
|
11 echo "for assignment 9 Part 2. Please note all marks are provisional until" >> $out |
|
12 echo "ratified by the assessment board -- this is not an official" >> $out |
|
13 echo "results transcript." >> $out |
|
14 echo "" >> $out |
|
15 |
|
16 # marks for CW9 part 2 |
|
17 marks=$(( 0 )) |
|
18 |
|
19 |
|
20 # compilation tests |
|
21 |
|
22 function scala_compile { |
|
23 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) |
|
24 } |
|
25 |
|
26 # functional tests |
|
27 |
|
28 function scala_assert { |
|
29 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 } |
|
31 |
|
32 # purity test |
|
33 |
|
34 function scala_vars { |
|
35 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
36 } |
|
37 |
|
38 |
|
39 # var, return, ListBuffer test |
|
40 # |
|
41 echo -e "postfix.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
42 |
|
43 if (scala_vars postfix.scala) |
|
44 then |
|
45 echo " --> test failed" | tee -a $out |
|
46 tsts0=$(( 1 )) |
|
47 else |
|
48 echo " --> success" | tee -a $out |
|
49 tsts0=$(( 0 )) |
|
50 fi |
|
51 |
|
52 # compilation test |
|
53 if [ $tsts0 -eq 0 ] |
|
54 then |
|
55 echo "postfix.scala runs?" | tee -a $out |
|
56 |
|
57 if (scala_compile re.scala) |
|
58 then |
|
59 echo " --> success" | tee -a $out |
|
60 tsts1=$(( 0 )) |
|
61 else |
|
62 echo " --> scala postfix.scala did not run successfully" | tee -a $out |
|
63 tsts1=$(( 1 )) |
|
64 fi |
|
65 else |
|
66 tsts1=$(( 1 )) |
|
67 fi |
|
68 |
|
69 |
|
70 ### postfix tests |
|
71 |
|
72 if [ $tsts1 -eq 0 ] |
|
73 then |
|
74 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out |
|
75 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out |
|
76 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out |
|
77 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out |
|
78 |
|
79 if (scala_assert "postfix.scala" "postfix_test7.scala") |
|
80 then |
|
81 echo -e " --> success" | tee -a $out |
|
82 marks=$(( marks + 1 )) |
|
83 else |
|
84 echo -e " --> test failed" | tee -a $out |
|
85 fi |
|
86 fi |
|
87 |
|
88 |
|
89 |
|
90 if [ $tsts1 -eq 0 ] |
|
91 then |
|
92 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out |
|
93 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out |
|
94 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out |
|
95 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out |
|
96 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out |
|
97 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out |
|
98 |
|
99 if (scala_assert "postfix.scala" "postfix_test8.scala") |
|
100 then |
|
101 echo -e " --> success" | tee -a $out |
|
102 marks=$(( marks + 1 )) |
|
103 else |
|
104 echo " --> test failed" | tee -a $out |
|
105 fi |
|
106 fi |
|
107 |
|
108 |
|
109 |
|
110 ### postfix2 tests |
|
111 |
|
112 # var, return, ListBuffer test |
|
113 # |
|
114 # var, return, ListBuffer test |
|
115 # |
|
116 echo -e "postfix2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
117 |
|
118 if (scala_vars postfix2.scala) |
|
119 then |
|
120 echo " --> test failed" | tee -a $out |
|
121 tsts0=$(( 1 )) |
|
122 else |
|
123 echo " --> success" | tee -a $out |
|
124 tsts0=$(( 0 )) |
|
125 fi |
|
126 |
|
127 |
|
128 # compilation test |
|
129 |
|
130 # compilation test |
|
131 if [ $tsts0 -eq 0 ] |
|
132 then |
|
133 echo "postfix2.scala runs?" | tee -a $out |
|
134 |
|
135 if (scala_compile re.scala) |
|
136 then |
|
137 echo " --> success" | tee -a $out |
|
138 tsts1=$(( 0 )) |
|
139 else |
|
140 echo " --> scala postfix2.scala did not run successfully" | tee -a $out |
|
141 tsts1=$(( 1 )) |
|
142 fi |
|
143 else |
|
144 tsts1=$(( 1 )) |
|
145 fi |
|
146 |
|
147 |
|
148 if [ $tsts1 -eq 0 ] |
|
149 then |
|
150 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out |
|
151 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out |
|
152 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out |
|
153 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out |
|
154 echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " | tee -a $out |
|
155 echo -e " List(\"3\", \"4\", \"8\", \"*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" | tee -a $out |
|
156 echo -e " " | tee -a $out |
|
157 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out |
|
158 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out |
|
159 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out |
|
160 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out |
|
161 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out |
|
162 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out |
|
163 echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" | tee -a $out |
|
164 echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" | tee -a $out |
|
165 echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" | tee -a $out |
|
166 echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" | tee -a $out |
|
167 |
|
168 if (scala_assert "postfix2.scala" "postfix_test9.scala") |
|
169 then |
|
170 echo -e " --> success" | tee -a $out |
|
171 marks=$(( marks + 2 )) |
|
172 else |
|
173 echo " --> test failed" | tee -a $out |
|
174 fi |
|
175 fi |
|
176 |
|
177 ## final marks |
|
178 echo "Overall mark for CW 9, Part 2" | tee -a $out |
|
179 echo "$marks" | tee -a $out |