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