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
|
326
|
11 |
echo "for Preliminary 8. Please note all marks are provisional until" >> $out
|
243
|
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 |
function scala_compile {
|
326
|
23 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
243
|
24 |
}
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
326
|
28 |
function scala_assert_slow {
|
|
29 |
(ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "-- $2" 2> /dev/null 1> /dev/null)
|
|
30 |
}
|
|
31 |
|
|
32 |
function scala_assert_thirty {
|
|
33 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
|
34 |
}
|
|
35 |
|
|
36 |
function scala_assert_quick {
|
|
37 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
|
38 |
}
|
|
39 |
|
243
|
40 |
function scala_assert {
|
326
|
41 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
243
|
42 |
}
|
|
43 |
|
244
|
44 |
function scala_assert_long {
|
326
|
45 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -2> /dev/null 1> /dev/null)
|
244
|
46 |
}
|
|
47 |
|
|
48 |
function scala_assert_elong {
|
326
|
49 |
(ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
244
|
50 |
}
|
|
51 |
|
243
|
52 |
# purity test
|
|
53 |
|
|
54 |
function scala_vars {
|
|
55 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
56 |
}
|
|
57 |
|
|
58 |
|
|
59 |
# knights1: purity test
|
|
60 |
|
|
61 |
echo "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
|
62 |
|
|
63 |
if (scala_vars knight1.scala)
|
|
64 |
then
|
326
|
65 |
echo " --> FAIL" | tee -a $out
|
243
|
66 |
tsts0=$(( 1 ))
|
|
67 |
else
|
|
68 |
echo " --> success" | tee -a $out
|
|
69 |
tsts0=$(( 0 ))
|
|
70 |
fi
|
|
71 |
|
|
72 |
|
|
73 |
# compilation test
|
|
74 |
|
|
75 |
if [ $tsts0 -eq 0 ]
|
|
76 |
then
|
|
77 |
echo "knight1.scala runs?" | tee -a $out
|
|
78 |
|
|
79 |
if (scala_compile knight1.scala)
|
|
80 |
then
|
|
81 |
echo " --> success " | tee -a $out
|
|
82 |
tsts1=$(( 0 ))
|
|
83 |
else
|
326
|
84 |
echo -e " --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out
|
243
|
85 |
tsts1=$(( 1 ))
|
|
86 |
fi
|
|
87 |
else
|
|
88 |
tsts1=$(( 1 ))
|
|
89 |
fi
|
|
90 |
|
|
91 |
### knight1 test
|
|
92 |
|
|
93 |
if [ $tsts1 -eq 0 ]
|
|
94 |
then
|
|
95 |
echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out
|
|
96 |
echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
|
|
97 |
echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out
|
|
98 |
|
|
99 |
if (scala_assert "knight1.scala" "knight1_test1.scala")
|
|
100 |
then
|
326
|
101 |
echo -e " --> success\n" | tee -a $out
|
243
|
102 |
marks=$(( marks + 1 ))
|
|
103 |
else
|
326
|
104 |
echo -e " --> \n ONE TEST FAILED\n"| tee -a $out
|
243
|
105 |
fi
|
|
106 |
fi
|
|
107 |
|
|
108 |
### knight2 test
|
|
109 |
|
|
110 |
if [ $tsts1 -eq 0 ]
|
|
111 |
then
|
|
112 |
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
|
|
113 |
echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
|
|
114 |
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
|
326
|
115 |
echo " legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0))" | tee -a $out
|
243
|
116 |
echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
|
|
117 |
echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
|
|
118 |
echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
|
|
119 |
echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
|
|
120 |
|
|
121 |
if (scala_assert "knight1.scala" "knight1_test2.scala")
|
|
122 |
then
|
326
|
123 |
echo -e " --> success\n" | tee -a $out
|
243
|
124 |
marks=$(( marks + 1 ))
|
|
125 |
else
|
326
|
126 |
echo -e " --> \n ONE TEST FAILED\n" | tee -a $out
|
243
|
127 |
fi
|
|
128 |
fi
|
|
129 |
|
|
130 |
|
|
131 |
### knight3 test
|
|
132 |
|
|
133 |
if [ $tsts1 -eq 0 ]
|
|
134 |
then
|
|
135 |
echo " all_tours from every position on the board" | tee -a $out
|
|
136 |
echo " dim = 1: 1" | tee -a $out
|
244
|
137 |
echo " 2: 0,0,0,0" | tee -a $out
|
|
138 |
echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out
|
243
|
139 |
echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
|
|
140 |
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
|
326
|
141 |
START=$(date +%s)
|
243
|
142 |
|
326
|
143 |
if (scala_assert_elong "knight1.scala" "knight1_test3a.scala")
|
243
|
144 |
then
|
326
|
145 |
END=$(date +%s)
|
|
146 |
DIFF=$(( $END - $START ))
|
|
147 |
echo " It took $DIFF seconds" | tee -a $out
|
|
148 |
echo -e " --> success\n" | tee -a $out
|
243
|
149 |
marks=$(( marks + 1 ))
|
|
150 |
else
|
326
|
151 |
END=$(date +%s)
|
|
152 |
DIFF=$(( $END - $START ))
|
|
153 |
echo " It took $DIFF seconds" | tee -a $out
|
|
154 |
echo -e " --> \n ONE TEST FAILED\n" | tee -a $out
|
243
|
155 |
fi
|
|
156 |
fi
|
|
157 |
|
|
158 |
if [ $tsts1 -eq 0 ]
|
|
159 |
then
|
|
160 |
echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
|
326
|
161 |
echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out
|
|
162 |
START=$(date +%s)
|
243
|
163 |
|
326
|
164 |
if (scala_assert "knight1.scala" "knight1_test3b.scala")
|
243
|
165 |
then
|
326
|
166 |
END=$(date +%s)
|
|
167 |
DIFF=$(( $END - $START ))
|
331
|
168 |
echo " It took $DIFF seconds" | tee -a $out
|
326
|
169 |
echo -e " --> success\n" | tee -a $out
|
243
|
170 |
marks=$(( marks + 1 ))
|
|
171 |
else
|
326
|
172 |
END=$(date +%s)
|
|
173 |
DIFF=$(( $END - $START ))
|
|
174 |
echo " It took $DIFF seconds" | tee -a $out
|
|
175 |
echo -e " --> \n ONE TEST FAILED\n" | tee -a $out
|
243
|
176 |
fi
|
|
177 |
fi
|
|
178 |
|
|
179 |
|
|
180 |
## final marks
|
326
|
181 |
echo "Overall mark for Preliminary 8" | tee -a $out
|
243
|
182 |
echo "$marks" | tee -a $out
|
|
183 |
|
|
184 |
|