247
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
|
|
7 |
out=${1:-output}
|
|
8 |
|
|
9 |
echo "" > $out
|
|
10 |
|
248
|
11 |
echo -e "Below is the feedback for your submission of CW 8, Advanced Part 2." >> $out
|
|
12 |
echo -e "" >> $out
|
247
|
13 |
|
248
|
14 |
|
247
|
15 |
|
|
16 |
# compilation tests
|
|
17 |
|
|
18 |
function scala_compile {
|
266
|
19 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
247
|
20 |
}
|
|
21 |
|
|
22 |
# functional tests
|
|
23 |
|
|
24 |
|
|
25 |
function scala_assert {
|
266
|
26 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
247
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
# purity test
|
|
32 |
|
|
33 |
function scala_vars {
|
|
34 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
# knights2: purity test
|
|
39 |
#
|
248
|
40 |
echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
|
247
|
41 |
|
|
42 |
|
|
43 |
if (scala_vars knight2.scala)
|
|
44 |
then
|
248
|
45 |
echo -e " --> fail (make triple-sure your program conforms to the required format)" >> $out
|
247
|
46 |
tsts0=$(( 0 ))
|
|
47 |
else
|
248
|
48 |
echo -e " --> success" >> $out
|
247
|
49 |
tsts0=$(( 0 ))
|
|
50 |
fi
|
|
51 |
|
|
52 |
|
|
53 |
# compilation test
|
|
54 |
if [ $tsts0 -eq 0 ]
|
|
55 |
then
|
248
|
56 |
echo -e "knight2.scala runs?" >> $out
|
247
|
57 |
|
|
58 |
if (scala_compile knight2.scala)
|
|
59 |
then
|
248
|
60 |
echo -e " --> success" >> $out
|
247
|
61 |
tsts1=$(( 0 ))
|
|
62 |
else
|
|
63 |
echo -e " --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out
|
|
64 |
tsts1=$(( 1 ))
|
|
65 |
fi
|
|
66 |
else
|
|
67 |
tsts1=$(( 1 ))
|
|
68 |
fi
|
|
69 |
|
|
70 |
# ordered move test
|
|
71 |
|
|
72 |
if [ $tsts1 -eq 0 ]
|
|
73 |
then
|
248
|
74 |
echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
|
|
75 |
echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
|
|
76 |
echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
|
247
|
77 |
|
|
78 |
if (scala_assert "knight2.scala" "knight_test6.scala")
|
|
79 |
then
|
248
|
80 |
echo -e " --> success" >> $out
|
247
|
81 |
else
|
|
82 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
83 |
fi
|
|
84 |
fi
|
|
85 |
|
|
86 |
|
|
87 |
# first-closed-tour test
|
|
88 |
|
|
89 |
if [ $tsts1 -eq 0 ]
|
|
90 |
then
|
248
|
91 |
echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" >> $out
|
247
|
92 |
|
|
93 |
if (scala_assert "knight2.scala" "knight_test7.scala")
|
|
94 |
then
|
248
|
95 |
echo -e " --> success" >> $out
|
247
|
96 |
else
|
|
97 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
98 |
fi
|
|
99 |
fi
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
if [ $tsts1 -eq 0 ]
|
|
104 |
then
|
248
|
105 |
echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" >> $out
|
|
106 |
echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" >> $out
|
247
|
107 |
|
|
108 |
if (scala_assert "knight2.scala" "knight_test8.scala")
|
|
109 |
then
|
248
|
110 |
echo -e " --> success" >> $out
|
247
|
111 |
else
|
|
112 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
113 |
fi
|
|
114 |
fi
|
|
115 |
|
|
116 |
|
|
117 |
# knights3: purity test
|
|
118 |
#
|
248
|
119 |
echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
|
247
|
120 |
|
|
121 |
|
|
122 |
if (scala_vars knight3.scala)
|
|
123 |
then
|
248
|
124 |
echo " --> test failed" >> $out
|
247
|
125 |
tsts0=$(( 0 ))
|
|
126 |
else
|
248
|
127 |
echo " --> success" >> $out
|
247
|
128 |
tsts0=$(( 0 ))
|
|
129 |
fi
|
|
130 |
|
|
131 |
|
|
132 |
# compilation test
|
|
133 |
if [ $tsts0 -eq 0 ]
|
|
134 |
then
|
248
|
135 |
echo "knight3.scala runs?" >> $out
|
247
|
136 |
|
|
137 |
if (scala_compile knight3.scala)
|
|
138 |
then
|
248
|
139 |
echo " --> success" >> $out
|
247
|
140 |
tsts1=$(( 0 ))
|
|
141 |
else
|
|
142 |
echo -e " --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out
|
|
143 |
tsts1=$(( 1 ))
|
|
144 |
fi
|
|
145 |
else
|
|
146 |
tsts1=$(( 1 ))
|
|
147 |
fi
|
|
148 |
|
|
149 |
|
|
150 |
if [ $tsts1 -eq 0 ]
|
|
151 |
then
|
248
|
152 |
echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out
|
247
|
153 |
|
|
154 |
if (scala_assert "knight3.scala" "knight_test9.scala")
|
|
155 |
then
|
248
|
156 |
echo -e " --> success" >> $out
|
247
|
157 |
else
|
|
158 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
159 |
fi
|
|
160 |
fi
|
|
161 |
|