|
1 #!/bin/bash |
|
2 set -euo pipefail |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo -e "" > $out |
|
7 |
|
8 echo -e "Below is the feedback for your submission of shogun.scala" >> $out |
|
9 echo -e "" >> $out |
|
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 |
|
18 # compilation tests |
|
19 |
|
20 function scala_compile { |
|
21 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" 2> c$out 1> c$out) |
|
22 } |
|
23 |
|
24 # functional tests |
|
25 |
|
26 function scala_assert { |
|
27 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null) |
|
28 } |
|
29 |
|
30 # purity test |
|
31 function scala_vars { |
|
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) |
|
34 } |
|
35 |
|
36 |
|
37 # compilation test |
|
38 |
|
39 |
|
40 echo -e "shogun.scala runs?" >> $out |
|
41 |
|
42 if (scala_compile shogun.scala) |
|
43 then |
|
44 echo -e " --> passed" >> $out |
|
45 tsts1=$(( 0 )) |
|
46 else |
|
47 echo -e " --> SCALA DID NOT RUN SHOGUN.SCALA\n" >> $out |
|
48 tsts1=$(( 1 )) |
|
49 fi |
|
50 |
|
51 |
|
52 # shogun: purity test |
|
53 |
|
54 if [ $tsts1 -eq 0 ] |
|
55 then |
|
56 echo -e "shogun.scala does not contain vars, returns etc?" >> $out |
|
57 |
|
58 if (scala_vars shogun.scala) |
|
59 then |
|
60 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
61 tsts1=$(( 1 )) |
|
62 else |
|
63 echo -e " --> passed" >> $out |
|
64 tsts1=$(( 0 )) |
|
65 fi |
|
66 fi |
|
67 |
|
68 |
|
69 ### shogun eval test |
|
70 |
|
71 if [ $tsts1 -eq 0 ] |
|
72 then |
|
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 |
|
84 |
|
85 if (scala_assert "shogun.scala" "shogun_test1.scala") |
|
86 then |
|
87 echo -e " --> success" >> $out |
|
88 else |
|
89 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
90 fi |
|
91 fi |
|
92 |
|
93 ### shogun all_moves test |
|
94 |
|
95 if [ $tsts1 -eq 0 ] |
|
96 then |
|
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 |
|
107 |
|
108 if (scala_assert "shogun.scala" "shogun_test2.scala") |
|
109 then |
|
110 echo -e " --> success" >> $out |
|
111 else |
|
112 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
113 fi |
|
114 fi |
|
115 |
|
116 |
|
117 ### attacked test |
|
118 |
|
119 if [ $tsts1 -eq 0 ] |
|
120 then |
|
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 |
|
130 |
|
131 if (scala_assert "shogun.scala" "shogun_test3.scala") |
|
132 then |
|
133 echo -e " --> success" >> $out |
|
134 else |
|
135 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
136 fi |
|
137 fi |
|
138 |
|
139 ### attackedN test |
|
140 |
|
141 if [ $tsts1 -eq 0 ] |
|
142 then |
|
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 |
|
146 |
|
147 if (scala_assert "shogun.scala" "shogun_test4.scala") |
|
148 then |
|
149 echo -e " --> success" >> $out |
|
150 else |
|
151 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
152 fi |
|
153 fi |
|
154 |
|
155 |
|
156 ### protectedN test |
|
157 |
|
158 if [ $tsts1 -eq 0 ] |
|
159 then |
|
160 echo -e " protectedN(Pawn(2, Wht, (8,4)), b2) == 1" >> $out |
|
161 echo -e " protectedN(Pawn(4, Red, (5,3)), b2) == 3" >> $out |
|
162 |
|
163 if (scala_assert "shogun.scala" "shogun_test5.scala") |
|
164 then |
|
165 echo -e " --> success" >> $out |
|
166 else |
|
167 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
168 fi |
|
169 fi |
|
170 |
|
171 |
|
172 echo -e "" >> $out |
|
173 echo -e "" >> $out |
|
174 |