377
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
#!/bin/bash
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
set -euo pipefail
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
out=${1:-output}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
echo -e "" > $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
echo -e "Below is the feedback for your submission of knight1.scala" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
#echo -e "!! Important: !!" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
#echo -e "Because of limitations with our testing infrastructure, we can only" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
#echo -e "let code run for 10 seconds and then have to kill it. This might" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
#echo -e "mean your code is correct, but still marked as Fail. Remember" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
#echo -e "you can test your code on your own machine and benchmark it" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
#echo -e "against the reference implementation." >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
#echo -e "" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
# compilation tests
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
function scala_compile {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
# functional tests
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
function scala_assert {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
# purity test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
function scala_vars {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
(egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
# compilation test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
echo -e "knight1.scala runs?" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
if (scala_compile knight1.scala)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
echo -e " --> passed" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
tsts=$(( 0 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
echo -e " --> SCALA DID NOT RUN knight1.scala\n" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
tsts=$(( 1 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
# knights1: purity test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
echo -e "knight1.scala does not contain vars, returns etc?" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
if (scala_vars knight1.scala)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
tsts=$(( 1 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
echo -e " --> passed" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
tsts=$(( 0 ))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
### knight1 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
if (scala_assert "knight1.scala" "knight_test1.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
echo -e " --> success" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
84 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
85 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
86 |
### knight2 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
87 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
88 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
89 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
90 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
91 |
echo -e " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
92 |
echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
93 |
echo -e " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
94 |
echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
95 |
echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
96 |
echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
97 |
echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
98 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
99 |
if (scala_assert "knight1.scala" "knight_test2.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
100 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
101 |
echo -e " --> success" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
102 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
103 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
### knight3 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
112 |
#echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
echo -e " count_tours from every position on the board" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
114 |
echo -e " dim = 1: 1" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
115 |
echo -e " 2: 0,0,0,0" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
echo -e " 3: 0,0,0,0,0,0,0,0,0" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
echo -e " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
#echo -e " 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" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
119 |
echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
120 |
echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
121 |
echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
if (scala_assert "knight1.scala" "knight_test3.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
echo -e " --> success" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
126 |
else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
131 |
### knight4 test
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
133 |
#if [ $tsts -eq 0 ]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
#then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
# #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
# echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
# echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
# echo -e " first(List((1,0),(2,0),(3,0)), f) == None" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
#
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
# if (scala_assert "knight1.scala" "knight_test4.scala")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
141 |
# then
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
142 |
# echo -e " --> success" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
143 |
# else
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
144 |
# echo -e " --> \n ONE TEST FAILED\n" >> $out
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
# fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
146 |
#fi
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
147 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
148 |
|