220
|
1 |
#!/bin/bash
|
|
2 |
set -euo pipefail
|
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
|
6 |
echo -e "" > $out
|
|
7 |
|
476
|
8 |
echo -e "Below is the feedback for your submission of shogun.scala" >> $out
|
220
|
9 |
echo -e "" >> $out
|
347
|
10 |
#echo -e "!! Important: !!" >> $out
|
|
11 |
#echo -e "Because of limitations with our testing infrastructure, we can only" >> $out
|
|
12 |
#echo -e "let code run for 10 seconds and then have to kill it. This might" >> $out
|
|
13 |
#echo -e "mean your code is correct, but still marked as Fail. Remember" >> $out
|
|
14 |
#echo -e "you can test your code on your own machine and benchmark it" >> $out
|
|
15 |
#echo -e "against the reference implementation." >> $out
|
|
16 |
#echo -e "" >> $out
|
|
17 |
|
220
|
18 |
# compilation tests
|
|
19 |
|
|
20 |
function scala_compile {
|
493
|
21 |
(scala-cli compile -color never -Xprint:parser "$1" 2> c$out 1> c$out)
|
220
|
22 |
}
|
|
23 |
|
|
24 |
# functional tests
|
|
25 |
|
347
|
26 |
function scala_assert {
|
493
|
27 |
(scala-cli --server=false --java-opt -Xmx1g -i project.scala "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null)
|
220
|
28 |
}
|
|
29 |
|
|
30 |
# purity test
|
|
31 |
function scala_vars {
|
476
|
32 |
(sed 's/immutable/ok/g' c$out > cb$out;
|
|
33 |
egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
|
220
|
34 |
}
|
|
35 |
|
|
36 |
|
|
37 |
# compilation test
|
|
38 |
|
347
|
39 |
|
476
|
40 |
echo -e "shogun.scala runs?" >> $out
|
220
|
41 |
|
476
|
42 |
if (scala_compile shogun.scala)
|
347
|
43 |
then
|
352
|
44 |
echo -e " --> passed" >> $out
|
220
|
45 |
tsts1=$(( 0 ))
|
|
46 |
else
|
476
|
47 |
echo -e " --> SCALA DID NOT RUN SHOGUN.SCALA\n" >> $out
|
220
|
48 |
tsts1=$(( 1 ))
|
|
49 |
fi
|
|
50 |
|
347
|
51 |
|
476
|
52 |
# shogun: purity test
|
347
|
53 |
|
|
54 |
if [ $tsts1 -eq 0 ]
|
|
55 |
then
|
476
|
56 |
echo -e "shogun.scala does not contain vars, returns etc?" >> $out
|
347
|
57 |
|
476
|
58 |
if (scala_vars shogun.scala)
|
347
|
59 |
then
|
|
60 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
|
61 |
tsts1=$(( 1 ))
|
|
62 |
else
|
352
|
63 |
echo -e " --> passed" >> $out
|
347
|
64 |
tsts1=$(( 0 ))
|
|
65 |
fi
|
|
66 |
fi
|
|
67 |
|
|
68 |
|
476
|
69 |
### shogun eval test
|
220
|
70 |
|
433
|
71 |
if [ $tsts1 -eq 0 ]
|
|
72 |
then
|
476
|
73 |
echo -e " val pw_a = Pawn(4, Wht, (4,4)) " >> $out
|
|
74 |
echo -e " eval(pw_a, U, 4, b_init) == Set(Pawn(4,Wht,(4,8)))" >> $out
|
|
75 |
echo -e " eval(pw_a, U, 3, b_init) == Set(Pawn(4,Wht,(4,7)))" >> $out
|
|
76 |
echo -e " eval(pw_a, RU, 4, b_init) == Set(Pawn(4,Wht,(6,6)), Pawn(4,Wht,(4,8)), " >> $out
|
|
77 |
echo -e " Pawn(4,Wht,(5,7)), Pawn(4,Wht,(7,5)), " >> $out
|
|
78 |
echo -e " Pawn(4,Wht,(8,4)))" >> $out
|
|
79 |
echo -e " " >> $out
|
|
80 |
echo -e " val pw_b = Pawn(4, Red, (4,4))" >> $out
|
|
81 |
echo -e " eval(pw_b, RU, 4, b_init) == Set(Pawn(4,Red,(8,4)), Pawn(4,Red,(7,5)), " >> $out
|
|
82 |
echo -e " Pawn(4,Red,(6,6)), Pawn(4,Red,(5,7)))" >> $out
|
|
83 |
echo -e " " >> $out
|
433
|
84 |
|
476
|
85 |
if (scala_assert "shogun.scala" "shogun_test1.scala")
|
433
|
86 |
then
|
|
87 |
echo -e " --> success" >> $out
|
|
88 |
else
|
|
89 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
90 |
fi
|
|
91 |
fi
|
220
|
92 |
|
476
|
93 |
### shogun all_moves test
|
220
|
94 |
|
433
|
95 |
if [ $tsts1 -eq 0 ]
|
|
96 |
then
|
476
|
97 |
echo -e " val pw_c = Pawn(2, Wht, (4,4))" >> $out
|
|
98 |
echo -e " val pw_d = Pawn(3, Red, (4,4))" >> $out
|
|
99 |
echo -e " all_moves(pw_c, b_init) == " >> $out
|
|
100 |
echo -e " Set(Pawn(2,Wht,(3,5)), Pawn(2,Wht,(2,4)), Pawn(2,Wht,(3,3)), Pawn(2,Wht,(5,5))," >> $out
|
|
101 |
echo -e " Pawn(2,Wht,(6,4)), Pawn(2,Wht,(4,6)), Pawn(2,Wht,(4,2)), Pawn(2,Wht,(5,3)))" >> $out
|
|
102 |
echo -e " all_moves(pw_d, b_init) == " >> $out
|
|
103 |
echo -e " Set(Pawn(3,Red,(4,7)), Pawn(3,Red,(5,2)), Pawn(3,Red,(3,2)), Pawn(3,Red,(1,4))," >> $out
|
|
104 |
echo -e " Pawn(3,Red,(6,3)), Pawn(3,Red,(3,6)), Pawn(3,Red,(2,5)), Pawn(3,Red,(2,3)), " >> $out
|
|
105 |
echo -e " Pawn(3,Red,(4,1)), Pawn(3,Red,(5,6)), Pawn(3,Red,(7,4)), Pawn(3,Red,(6,5))))" >> $out
|
|
106 |
|
433
|
107 |
|
476
|
108 |
if (scala_assert "shogun.scala" "shogun_test2.scala")
|
433
|
109 |
then
|
|
110 |
echo -e " --> success" >> $out
|
|
111 |
else
|
|
112 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
113 |
fi
|
|
114 |
fi
|
220
|
115 |
|
|
116 |
|
476
|
117 |
### attacked test
|
220
|
118 |
|
433
|
119 |
if [ $tsts1 -eq 0 ]
|
|
120 |
then
|
476
|
121 |
echo -e " val b2 = Board(Set(King(2, Red, (4,2)), King(2, Wht, (7,1))," >> $out
|
|
122 |
echo -e " Pawn(3, Red, (6,1)), Pawn(2, Wht, (8,4))," >> $out
|
|
123 |
echo -e " Pawn(4, Red, (4,4)), Pawn(2, Wht, (4,1))," >> $out
|
|
124 |
echo -e " Pawn(4, Red, (5,3)), Pawn(3, Wht, (8,7))," >> $out
|
|
125 |
echo -e " Pawn(3, Red, (6,5))))" >> $out
|
|
126 |
echo -e " attacked(Red, b2) == Set(Pawn(2,Wht,(8,4)), King(2,Wht,(7,1)))" >> $out
|
|
127 |
echo -e " attacked(Wht, b2) == Set(Pawn(3,Red,(6,1)))" >> $out
|
|
128 |
echo -e " attacked(Wht, b_init) == Set()" >> $out
|
|
129 |
echo -e " attacked(Red, b_init) == Set()" >> $out
|
433
|
130 |
|
476
|
131 |
if (scala_assert "shogun.scala" "shogun_test3.scala")
|
433
|
132 |
then
|
|
133 |
echo -e " --> success" >> $out
|
|
134 |
else
|
|
135 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
136 |
fi
|
|
137 |
fi
|
220
|
138 |
|
476
|
139 |
### attackedN test
|
220
|
140 |
|
|
141 |
if [ $tsts1 -eq 0 ]
|
|
142 |
then
|
476
|
143 |
echo -e " attackedN(Pawn(2, Wht, (8,4)), b2) == 3" >> $out
|
|
144 |
echo -e " attackedN(King(2, Wht, (7,1)), b2) == 1" >> $out
|
|
145 |
echo -e " attackedN(Pawn(3, Red, (6,1)), b2) == 1" >> $out
|
220
|
146 |
|
476
|
147 |
if (scala_assert "shogun.scala" "shogun_test4.scala")
|
220
|
148 |
then
|
|
149 |
echo -e " --> success" >> $out
|
|
150 |
else
|
|
151 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
152 |
fi
|
|
153 |
fi
|
|
154 |
|
|
155 |
|
476
|
156 |
### protectedN test
|
220
|
157 |
|
|
158 |
if [ $tsts1 -eq 0 ]
|
|
159 |
then
|
476
|
160 |
echo -e " protectedN(Pawn(2, Wht, (8,4)), b2) == 1" >> $out
|
|
161 |
echo -e " protectedN(Pawn(4, Red, (5,3)), b2) == 3" >> $out
|
220
|
162 |
|
476
|
163 |
if (scala_assert "shogun.scala" "shogun_test5.scala")
|
220
|
164 |
then
|
|
165 |
echo -e " --> success" >> $out
|
|
166 |
else
|
|
167 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
168 |
fi
|
|
169 |
fi
|
|
170 |
|
296
|
171 |
|
477
|
172 |
# legal moves
|
|
173 |
if [ $tsts1 -eq 0 ]
|
|
174 |
then
|
|
175 |
echo -e " Task 6: automated test cases not yet done" >> $out
|
|
176 |
fi
|
|
177 |
|
296
|
178 |
echo -e "" >> $out
|
|
179 |
echo -e "" >> $out
|
|
180 |
|