author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Wed, 11 Jan 2017 14:56:16 +0000 | |
changeset 102 | 085bf16963c6 |
parent 96 | abfcb6111d33 |
permissions | -rwxr-xr-x |
82 | 1 |
#!/bin/bash |
2 |
set -e |
|
3 |
||
4 |
out=${1:-output} |
|
5 |
||
6 |
echo "" > $out |
|
7 |
||
8 |
echo "Below is the feedback and provisional mark for your submission" >> $out |
|
86 | 9 |
echo "for CW 7, Part 1. Please note all marks are provisional until" >> $out |
82 | 10 |
echo "ratified by the assessment board -- this is not an official" >> $out |
11 |
echo "results transcript." >> $out |
|
12 |
echo "" >> $out |
|
13 |
||
84 | 14 |
function scala_vars { |
102
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
15 |
(egrep 'var|return|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
84 | 16 |
} |
82 | 17 |
|
18 |
||
19 |
# compilation tests |
|
20 |
||
21 |
function scala_compile { |
|
85 | 22 |
(scala "$1" 2> /dev/null 1> /dev/null) |
82 | 23 |
} |
24 |
||
25 |
||
26 |
# functional tests |
|
27 |
||
28 |
function scala_assert { |
|
29 |
(scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 |
} |
|
31 |
||
32 |
||
84 | 33 |
# marks for CW2 |
82 | 34 |
marks=$(( 0 )) |
35 |
||
86 | 36 |
# knights1: var, comments test |
37 |
||
38 |
echo "knight1.scala does not contain vars, returns etc?" | tee -a $out |
|
82 | 39 |
|
84 | 40 |
if (scala_vars knight1.scala) |
82 | 41 |
then |
84 | 42 |
echo " --> fail" | tee -a $out |
85 | 43 |
tsts0=$(( 1 )) |
82 | 44 |
else |
86 | 45 |
echo " --> yes" | tee -a $out |
85 | 46 |
tsts0=$(( 0 )) |
82 | 47 |
fi |
48 |
||
49 |
||
84 | 50 |
# compilation test |
86 | 51 |
|
52 |
if [ $tsts0 -eq 0 ] |
|
85 | 53 |
then |
54 |
echo "knight1.scala runs?" | tee -a $out |
|
55 |
||
56 |
if (scala_compile knight1.scala.bak) |
|
57 |
then |
|
86 | 58 |
echo " --> yes" | tee -a $out |
85 | 59 |
tsts1=$(( 0 )) |
60 |
else |
|
61 |
echo " --> scala did not run knight1.scala" | tee -a $out |
|
62 |
tsts1=$(( 1 )) |
|
63 |
fi |
|
86 | 64 |
else |
65 |
tsts1=$(( 1 )) |
|
85 | 66 |
fi |
67 |
||
68 |
### knight1a test |
|
82 | 69 |
|
85 | 70 |
if [ $tsts1 -eq 0 ] |
71 |
then |
|
86 | 72 |
echo " is_legal(8, Nil) (3,4) == true " | tee -a $out |
73 |
echo " is_legal(8, (4,1) (1,0)) (4,1) == false " | tee -a $out |
|
74 |
echo " is_legal(2, Nil) (0,0) == true" | tee -a $out |
|
75 |
||
76 |
if (scala_assert "knight1.scala.bak" "../../../marking/knight1c_test.scala") |
|
77 |
then |
|
78 |
echo " --> success" | tee -a $out |
|
79 |
marks=$(( marks + 1 )) |
|
80 |
else |
|
81 |
echo " --> test failed" | tee -a $out |
|
82 |
fi |
|
83 |
fi |
|
84 |
||
85 |
if [ $tsts1 -eq 0 ] |
|
86 |
then |
|
85 | 87 |
echo " legal_moves(8, Nil, (2,2)) = (3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)" | tee -a $out |
88 |
echo " legal_moves(8, Nil, (7,7)) = (6,5), (5,6)" | tee -a $out |
|
89 |
echo " legal_moves(8, (4,1), (1,0), (2,2)) = (3,4), (4,3), (3,0), (0,1), (0,3), (1,4)" | tee -a $out |
|
90 |
echo " legal_moves(8, (6,6), (7,7)) = (6,5), (5,6)" | tee -a $out |
|
91 |
echo " legal_moves(1, Nil, (0,0)) = Nil" | tee -a $out |
|
92 |
echo " legal_moves(2, Nil, (0,0)) = Nil" | tee -a $out |
|
93 |
echo " legal_moves(3, Nil, (0,0)) = (1,2), (2,1)" | tee -a $out |
|
94 |
||
86 | 95 |
if (scala_assert "knight1.scala.bak" "../../../marking/knight1_test.scala") |
85 | 96 |
then |
97 |
echo " --> success" | tee -a $out |
|
98 |
marks=$(( marks + 1 )) |
|
99 |
else |
|
100 |
echo " --> test failed" | tee -a $out |
|
101 |
fi |
|
102 |
fi |
|
82 | 103 |
|
86 | 104 |
### knight1b test |
105 |
||
106 |
if [ $tsts1 -eq 0 ] |
|
107 |
then |
|
108 |
echo " all_tours from every position on the board" | tee -a $out |
|
109 |
echo " dim = 1: 1" | tee -a $out |
|
110 |
echo " 2: 0,0,0,0" | tee -a $out |
|
111 |
echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out |
|
112 |
echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out |
|
113 |
echo " 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" | tee -a $out |
|
114 |
echo " enum_tours(5, (0,2) ) = 56 and all correct?" | tee -a $out |
|
115 |
||
116 |
if (scala_assert "knight1.scala.bak" "../../../marking/knight1b_test.scala") |
|
117 |
then |
|
118 |
echo " --> success" | tee -a $out |
|
119 |
marks=$(( marks + 2 )) |
|
120 |
else |
|
121 |
echo " --> test failed" | tee -a $out |
|
122 |
fi |
|
123 |
fi |
|
124 |
||
125 |
||
126 |
||
127 |
# knights2: var, comments test |
|
128 |
||
129 |
echo "knight2.scala does not contain vars, returns etc?" | tee -a $out |
|
130 |
||
131 |
if (scala_vars knight2.scala) |
|
132 |
then |
|
133 |
echo " --> fail" | tee -a $out |
|
134 |
tsts0=$(( 1 )) |
|
135 |
else |
|
136 |
echo " --> yes" | tee -a $out |
|
137 |
tsts0=$(( 0 )) |
|
138 |
fi |
|
139 |
||
140 |
||
141 |
# compilation test |
|
142 |
if [ $tsts0 -eq 0 ] |
|
143 |
then |
|
144 |
echo "knight2.scala runs?" | tee -a $out |
|
145 |
||
146 |
if (scala_compile knight2.scala.bak) |
|
147 |
then |
|
148 |
echo " --> yes" | tee -a $out |
|
149 |
tsts1=$(( 0 )) |
|
150 |
else |
|
151 |
echo " --> scala did not run knight2.scala" | tee -a $out |
|
152 |
tsts1=$(( 1 )) |
|
153 |
fi |
|
154 |
else |
|
155 |
tsts1=$(( 1 )) |
|
156 |
fi |
|
157 |
||
84 | 158 |
### knight2 test |
82 | 159 |
|
86 | 160 |
if [ $tsts1 -eq 0 ] |
161 |
then |
|
162 |
echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out |
|
163 |
echo " first((1,0),(2,0),(3,0),(4,0), f) == Some(List((4,0)))" | tee -a $out |
|
164 |
echo " first((1,0),(2,0),(3,0), f) == None" | tee -a $out |
|
165 |
||
166 |
if (scala_assert "knight2.scala.bak" "../../../marking/knight2_test.scala") |
|
167 |
then |
|
168 |
echo " --> success" | tee -a $out |
|
169 |
marks=$(( marks + 1 )) |
|
170 |
else |
|
171 |
echo " --> test failed" | tee -a $out |
|
172 |
fi |
|
173 |
fi |
|
174 |
||
175 |
### knight2b test |
|
176 |
||
177 |
if [ $tsts1 -eq 0 ] |
|
178 |
then |
|
179 |
echo " is first_tour(8, (0, 0)) ok? " | tee -a $out |
|
180 |
echo " is first_tour(4, (0, 0)) == None " | tee -a $out |
|
181 |
||
182 |
if (scala_assert "knight2.scala.bak" "../../../marking/knight2b_test.scala") |
|
183 |
then |
|
184 |
echo " --> success" | tee -a $out |
|
185 |
marks=$(( marks + 2 )) |
|
186 |
else |
|
187 |
echo " --> test failed" | tee -a $out |
|
188 |
fi |
|
189 |
fi |
|
190 |
||
191 |
||
102
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
192 |
# knights3: var, comments test |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
193 |
# |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
194 |
#echo "knight3.scala does not contain vars, returns etc?" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
195 |
|
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
196 |
#if (scala_vars knight3.scala) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
197 |
#then |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
198 |
# echo " --> fail" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
199 |
# tsts0=$(( 1 )) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
200 |
#else |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
201 |
# echo " --> success" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
202 |
# tsts0=$(( 0 )) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
203 |
#fi |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
204 |
|
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
205 |
|
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
206 |
# compilation test |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
207 |
#if [ $tsts0 -eq 0 ] |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
208 |
#then |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
209 |
# echo "knight3.scala runs?" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
210 |
# |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
211 |
# if (scala_compile knight3.scala.bak) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
212 |
# then |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
213 |
# echo " --> success" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
214 |
# tsts1=$(( 0 )) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
215 |
# else |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
216 |
# echo " --> scala did not run knight3.scala" | tee -a $out |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
217 |
# tsts1=$(( 1 )) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
218 |
# fi |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
219 |
#else |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
220 |
# tsts1=$(( 1 )) |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
221 |
#fi |
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
222 |
|
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
223 |
|
82 | 224 |
## final marks |
102
085bf16963c6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
96
diff
changeset
|
225 |
echo "Overall mark for CW 2, Part 1 " | tee -a $out |
82 | 226 |
echo "$marks" | tee -a $out |