|
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 CW 8, Part 1 and 2." >> $out |
|
9 echo -e "" >> $out |
|
10 |
|
11 |
|
12 # compilation tests |
|
13 |
|
14 function scala_compile { |
|
15 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
|
16 } |
|
17 |
|
18 # functional tests |
|
19 |
|
20 function scala_assert_slow { |
|
21 (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
22 } |
|
23 |
|
24 function scala_assert_thirty { |
|
25 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
26 } |
|
27 |
|
28 function scala_assert_quick { |
|
29 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
30 } |
|
31 |
|
32 # purity test |
|
33 |
|
34 function scala_vars { |
|
35 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
36 } |
|
37 |
|
38 |
|
39 # knights1: purity test |
|
40 |
|
41 echo -e "knight1.scala does not contain vars, returns etc?" >> $out |
|
42 |
|
43 if (scala_vars knight1.scala) |
|
44 then |
|
45 echo -e " --> fail (make triple-sure your program conforms to the required format)" >> $out |
|
46 tsts0=$(( 0 )) |
|
47 else |
|
48 echo -e " --> success" >> $out |
|
49 tsts0=$(( 0 )) |
|
50 fi |
|
51 |
|
52 |
|
53 # compilation test |
|
54 |
|
55 if [ $tsts0 -eq 0 ] |
|
56 then |
|
57 echo -e "knight1.scala runs?" >> $out |
|
58 |
|
59 if (scala_compile knight1.scala) |
|
60 then |
|
61 echo -e " --> success " >> $out |
|
62 tsts1=$(( 0 )) |
|
63 else |
|
64 echo -e " --> SCALA DID NOT RUN KNIGHT1.SCALA\n" >> $out |
|
65 tsts1=$(( 1 )) |
|
66 fi |
|
67 else |
|
68 tsts1=$(( 1 )) |
|
69 fi |
|
70 |
|
71 ### knight1 test |
|
72 |
|
73 if [ $tsts1 -eq 0 ] |
|
74 then |
|
75 echo -e "Takes 10 seconds or less to execute: " >> $out |
|
76 echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out |
|
77 echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out |
|
78 echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out |
|
79 |
|
80 if (scala_assert_quick "knight1.scala" "knight_test1.scala") |
|
81 then |
|
82 echo -e " --> success" >> $out |
|
83 else |
|
84 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
85 fi |
|
86 fi |
|
87 |
|
88 ### knight2 test |
|
89 |
|
90 if [ $tsts1 -eq 0 ] |
|
91 then |
|
92 echo -e "Takes 10 seconds or less to execute: " >> $out |
|
93 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 |
|
94 echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out |
|
95 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 |
|
96 echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out |
|
97 echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out |
|
98 echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out |
|
99 echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out |
|
100 |
|
101 if (scala_assert_quick "knight1.scala" "knight_test2.scala") |
|
102 then |
|
103 echo -e " --> success" >> $out |
|
104 else |
|
105 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
106 fi |
|
107 fi |
|
108 |
|
109 |
|
110 ### knight3 test |
|
111 |
|
112 if [ $tsts1 -eq 0 ] |
|
113 then |
|
114 echo -e "Takes 10 seconds or less to execute: " >> $out |
|
115 echo -e " count_tours from every position on the board" >> $out |
|
116 echo -e " dim = 1: 1" >> $out |
|
117 echo -e " 2: 0,0,0,0" >> $out |
|
118 echo -e " 3: 0,0,0,0,0,0,0,0,0" >> $out |
|
119 echo -e " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out |
|
120 #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 |
|
121 echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out |
|
122 echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out |
|
123 echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out |
|
124 |
|
125 if (scala_assert_quick "knight1.scala" "knight_test3.scala") |
|
126 then |
|
127 echo -e " --> success" >> $out |
|
128 else |
|
129 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
130 fi |
|
131 fi |
|
132 |
|
133 ### knight4 test |
|
134 |
|
135 if [ $tsts1 -eq 0 ] |
|
136 then |
|
137 echo -e "Takes 10 seconds or less to execute: " >> $out |
|
138 echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out |
|
139 echo -e " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out |
|
140 echo -e " first(List((1,0),(2,0),(3,0)), f) == None" >> $out |
|
141 |
|
142 if (scala_assert_quick "knight1.scala" "knight_test4.scala") |
|
143 then |
|
144 echo -e " --> success" >> $out |
|
145 else |
|
146 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
147 fi |
|
148 fi |
|
149 |
|
150 |
|
151 ### knight5 test |
|
152 |
|
153 if [ $tsts1 -eq 0 ] |
|
154 then |
|
155 echo -e "Takes 10 seconds or less to execute: " >> $out |
|
156 echo -e " is first_tour(6, List((0, 0))) ok? " >> $out |
|
157 echo -e " is first_tour(4, List((0, 0))) == None " >> $out |
|
158 |
|
159 if (scala_assert_quick "knight1.scala" "knight_test5.scala") |
|
160 then |
|
161 echo -e " --> success" >> $out |
|
162 else |
|
163 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
164 fi |
|
165 fi |
|
166 |