162
|
1 |
#!/bin/bash
|
168
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
162
|
6 |
|
|
7 |
out=${1:-output}
|
|
8 |
|
|
9 |
echo "" > $out
|
|
10 |
|
168
|
11 |
echo "Below is the feedback and provisional marks for your submission" >> $out
|
|
12 |
echo "for assignment 7 Part 2. Please note all marks are provisional until" >> $out
|
|
13 |
echo "ratified by the assessment board -- this is not an official" >> $out
|
|
14 |
echo "results transcript." >> $out
|
162
|
15 |
echo "" >> $out
|
|
16 |
|
168
|
17 |
# marks for CW7 part 2
|
|
18 |
marks=$(( 0 ))
|
162
|
19 |
|
|
20 |
# compilation tests
|
|
21 |
|
|
22 |
function scala_compile {
|
168
|
23 |
(ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
|
162
|
24 |
}
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
|
28 |
function scala_assert {
|
168
|
29 |
(ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
162
|
30 |
}
|
|
31 |
|
168
|
32 |
|
162
|
33 |
# purity test
|
|
34 |
|
|
35 |
function scala_vars {
|
|
36 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
# knights3: purity test
|
|
41 |
#
|
168
|
42 |
echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
43 |
|
162
|
44 |
|
|
45 |
if (scala_vars knight3.scala)
|
|
46 |
then
|
168
|
47 |
echo " --> test failed" | tee -a $out
|
162
|
48 |
tsts0=$(( 1 ))
|
|
49 |
else
|
168
|
50 |
echo " --> success" | tee -a $out
|
162
|
51 |
tsts0=$(( 0 ))
|
|
52 |
fi
|
|
53 |
|
|
54 |
|
|
55 |
# compilation test
|
|
56 |
if [ $tsts0 -eq 0 ]
|
|
57 |
then
|
168
|
58 |
echo "knight3.scala runs?" | tee -a $out
|
162
|
59 |
|
|
60 |
if (scala_compile knight3.scala)
|
|
61 |
then
|
168
|
62 |
echo " --> success" | tee -a $out
|
162
|
63 |
tsts1=$(( 0 ))
|
|
64 |
else
|
168
|
65 |
echo " --> scala knight3.scala did not run successfully" | tee -a $out
|
162
|
66 |
tsts1=$(( 1 ))
|
|
67 |
fi
|
|
68 |
else
|
|
69 |
tsts1=$(( 1 ))
|
|
70 |
fi
|
|
71 |
|
|
72 |
# ordered move test
|
|
73 |
|
|
74 |
if [ $tsts1 -eq 0 ]
|
|
75 |
then
|
168
|
76 |
echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
|
|
77 |
echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
|
|
78 |
echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
|
162
|
79 |
|
|
80 |
if (scala_assert "knight3.scala" "knight3a_test.scala")
|
|
81 |
then
|
168
|
82 |
echo " --> success" | tee -a $out
|
|
83 |
marks=$(( marks + 1 ))
|
162
|
84 |
else
|
168
|
85 |
echo " --> test failed" | tee -a $out
|
162
|
86 |
fi
|
|
87 |
fi
|
|
88 |
|
|
89 |
|
|
90 |
# first-closed-tour test
|
|
91 |
|
|
92 |
if [ $tsts1 -eq 0 ]
|
|
93 |
then
|
168
|
94 |
echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
|
162
|
95 |
|
|
96 |
if (scala_assert "knight3.scala" "knight3b_test.scala")
|
|
97 |
then
|
168
|
98 |
echo " --> success" | tee -a $out
|
|
99 |
marks=$(( marks + 1 ))
|
162
|
100 |
else
|
168
|
101 |
echo " --> test failed" | tee -a $out
|
162
|
102 |
fi
|
|
103 |
fi
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
if [ $tsts1 -eq 0 ]
|
|
108 |
then
|
168
|
109 |
echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
|
|
110 |
echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
|
162
|
111 |
|
|
112 |
if (scala_assert "knight3.scala" "knight3c_test.scala")
|
|
113 |
then
|
168
|
114 |
echo " --> success" | tee -a $out
|
|
115 |
marks=$(( marks + 1 ))
|
162
|
116 |
else
|
168
|
117 |
echo " --> test failed" | tee -a $out
|
162
|
118 |
fi
|
|
119 |
fi
|
|
120 |
|
|
121 |
|
|
122 |
## final marks
|
168
|
123 |
echo "Overall mark for CW 7, Part 2" | tee -a $out
|
|
124 |
echo "$marks" | tee -a $out
|