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