243
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
out=${1:-output}
|
|
7 |
|
|
8 |
echo "" > $out
|
|
9 |
|
|
10 |
echo "Below is the feedback and provisional marks for your submission" >> $out
|
|
11 |
echo "for assignment 8 Part 1. 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 |
|
|
17 |
|
|
18 |
# marks for CW8 part 1
|
|
19 |
marks=$(( 0 ))
|
|
20 |
|
|
21 |
|
|
22 |
# compilation tests (used to be 30 secs)
|
|
23 |
|
|
24 |
function scala_compile {
|
250
|
25 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
|
243
|
26 |
}
|
|
27 |
|
|
28 |
# functional tests
|
|
29 |
|
|
30 |
function scala_assert {
|
250
|
31 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
|
243
|
32 |
}
|
|
33 |
|
244
|
34 |
function scala_assert_long {
|
250
|
35 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
|
244
|
36 |
}
|
|
37 |
|
|
38 |
function scala_assert_elong {
|
250
|
39 |
(ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
|
244
|
40 |
}
|
|
41 |
|
|
42 |
|
243
|
43 |
# purity test
|
|
44 |
|
|
45 |
function scala_vars {
|
|
46 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
# knights1: purity test
|
|
51 |
|
|
52 |
echo "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
53 |
|
|
54 |
if (scala_vars knight1.scala)
|
|
55 |
then
|
|
56 |
echo " --> fail" | tee -a $out
|
|
57 |
tsts0=$(( 1 ))
|
|
58 |
else
|
|
59 |
echo " --> success" | tee -a $out
|
|
60 |
tsts0=$(( 0 ))
|
|
61 |
fi
|
|
62 |
|
|
63 |
|
|
64 |
# compilation test
|
|
65 |
|
|
66 |
if [ $tsts0 -eq 0 ]
|
|
67 |
then
|
|
68 |
echo "knight1.scala runs?" | tee -a $out
|
|
69 |
|
|
70 |
if (scala_compile knight1.scala)
|
|
71 |
then
|
|
72 |
echo " --> success " | tee -a $out
|
|
73 |
tsts1=$(( 0 ))
|
|
74 |
else
|
|
75 |
echo " --> scala did not run knight1.scala" | tee -a $out
|
|
76 |
tsts1=$(( 1 ))
|
|
77 |
fi
|
|
78 |
else
|
|
79 |
tsts1=$(( 1 ))
|
|
80 |
fi
|
|
81 |
|
|
82 |
### knight1 test
|
|
83 |
|
|
84 |
if [ $tsts1 -eq 0 ]
|
|
85 |
then
|
|
86 |
echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out
|
|
87 |
echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
|
|
88 |
echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out
|
|
89 |
|
|
90 |
if (scala_assert "knight1.scala" "knight1_test1.scala")
|
|
91 |
then
|
|
92 |
echo " --> success" | tee -a $out
|
|
93 |
marks=$(( marks + 1 ))
|
|
94 |
else
|
|
95 |
echo " --> test failed" | tee -a $out
|
|
96 |
fi
|
|
97 |
fi
|
|
98 |
|
|
99 |
### knight2 test
|
|
100 |
|
|
101 |
if [ $tsts1 -eq 0 ]
|
|
102 |
then
|
|
103 |
echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" | tee -a $out
|
|
104 |
echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
|
|
105 |
echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" | tee -a $out
|
|
106 |
echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
|
|
107 |
echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
|
|
108 |
echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
|
|
109 |
echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
|
|
110 |
|
|
111 |
if (scala_assert "knight1.scala" "knight1_test2.scala")
|
|
112 |
then
|
|
113 |
echo " --> success" | tee -a $out
|
|
114 |
marks=$(( marks + 1 ))
|
|
115 |
else
|
|
116 |
echo " --> test failed" | tee -a $out
|
|
117 |
fi
|
|
118 |
fi
|
|
119 |
|
|
120 |
|
|
121 |
### knight3 test
|
|
122 |
|
|
123 |
if [ $tsts1 -eq 0 ]
|
|
124 |
then
|
|
125 |
echo " all_tours from every position on the board" | tee -a $out
|
|
126 |
echo " dim = 1: 1" | tee -a $out
|
244
|
127 |
echo " 2: 0,0,0,0" | tee -a $out
|
|
128 |
echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out
|
243
|
129 |
echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
|
|
130 |
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
|
|
131 |
|
244
|
132 |
if (time scala_assert_elong "knight1.scala" "knight1_test3a.scala")
|
243
|
133 |
then
|
|
134 |
echo " --> success" | tee -a $out
|
|
135 |
marks=$(( marks + 1 ))
|
|
136 |
else
|
|
137 |
echo " --> test failed" | tee -a $out
|
|
138 |
fi
|
|
139 |
fi
|
|
140 |
|
|
141 |
if [ $tsts1 -eq 0 ]
|
|
142 |
then
|
|
143 |
echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
|
|
144 |
|
244
|
145 |
if (time scala_assert "knight1.scala" "knight1_test3b.scala")
|
243
|
146 |
then
|
|
147 |
echo " --> success" | tee -a $out
|
|
148 |
marks=$(( marks + 1 ))
|
|
149 |
else
|
|
150 |
echo " --> test failed" | tee -a $out
|
|
151 |
fi
|
|
152 |
fi
|
|
153 |
|
|
154 |
|
244
|
155 |
### knight4 test
|
243
|
156 |
|
|
157 |
if [ $tsts1 -eq 0 ]
|
|
158 |
then
|
|
159 |
echo " val f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out
|
|
160 |
echo " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out
|
|
161 |
echo " first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out
|
|
162 |
|
|
163 |
if (scala_assert "knight1.scala" "knight1_test4.scala")
|
|
164 |
then
|
|
165 |
echo " --> success" | tee -a $out
|
|
166 |
marks=$(( marks + 1 ))
|
|
167 |
else
|
|
168 |
echo " --> test failed" | tee -a $out
|
|
169 |
fi
|
|
170 |
fi
|
|
171 |
|
|
172 |
|
244
|
173 |
### knight5 test
|
243
|
174 |
|
|
175 |
if [ $tsts1 -eq 0 ]
|
|
176 |
then
|
|
177 |
echo " is first_tour(8, List((0, 0))) ok? " | tee -a $out
|
|
178 |
echo " is first_tour(4, List((0, 0))) == None " | tee -a $out
|
|
179 |
|
244
|
180 |
if (time scala_assert_long "knight1.scala" "knight1_test5.scala")
|
243
|
181 |
then
|
|
182 |
echo " --> success" | tee -a $out
|
244
|
183 |
marks=$(( marks + 1 ))
|
243
|
184 |
else
|
|
185 |
echo " --> test failed" | tee -a $out
|
|
186 |
fi
|
|
187 |
fi
|
|
188 |
|
|
189 |
|
|
190 |
## final marks
|
|
191 |
echo "Overall mark for Part 1" | tee -a $out
|
|
192 |
echo "$marks" | tee -a $out
|
|
193 |
|
|
194 |
|