|
1 #!/bin/bash |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 |
|
7 out=${1:-output} |
|
8 |
|
9 echo "" > $out |
|
10 |
|
11 echo "Below is the feedback and provisional marks for your submission" >> $out |
|
12 echo "for assignment 8 Part 2. Please note all marks are provisional until" >> $out |
|
13 echo "ratified by the assessment board -- this is not an official" >> $out |
|
14 echo "results transcript." >> $out |
|
15 echo "" >> $out |
|
16 |
|
17 # marks for CW8 part 2 |
|
18 marks=$(( 0 )) |
|
19 |
|
20 # compilation tests |
|
21 |
|
22 function scala_compile { |
|
23 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) |
|
24 } |
|
25 |
|
26 # functional tests |
|
27 |
|
28 |
|
29 function scala_assert { |
|
30 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) |
|
31 } |
|
32 |
|
33 function scala_assert_slow { |
|
34 (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
35 } |
|
36 |
|
37 |
|
38 |
|
39 # purity test |
|
40 |
|
41 function scala_vars { |
|
42 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
43 } |
|
44 |
|
45 |
|
46 # knights2: purity test |
|
47 # |
|
48 echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
49 |
|
50 |
|
51 if (scala_vars knight2.scala) |
|
52 then |
|
53 echo -e " --> test failed" | tee -a $out |
|
54 tsts0=$(( 0 )) |
|
55 else |
|
56 echo -e " --> success" | tee -a $out |
|
57 tsts0=$(( 0 )) |
|
58 fi |
|
59 |
|
60 |
|
61 # compilation test |
|
62 if [ $tsts0 -eq 0 ] |
|
63 then |
|
64 echo -e "knight2.scala runs?" | tee -a $out |
|
65 |
|
66 if (scala_compile knight2.scala) |
|
67 then |
|
68 echo -e " --> success" | tee -a $out |
|
69 tsts1=$(( 0 )) |
|
70 else |
|
71 echo -e " --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out |
|
72 tsts1=$(( 1 )) |
|
73 fi |
|
74 else |
|
75 tsts1=$(( 1 )) |
|
76 fi |
|
77 |
|
78 # ordered move test |
|
79 |
|
80 if [ $tsts1 -eq 0 ] |
|
81 then |
|
82 echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out |
|
83 echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out |
|
84 echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out |
|
85 |
|
86 if (scala_assert "knight2.scala" "knight_test6.scala") |
|
87 then |
|
88 echo -e " --> success" | tee -a $out |
|
89 marks=$(( marks + 1 )) |
|
90 else |
|
91 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
92 fi |
|
93 fi |
|
94 |
|
95 |
|
96 # first-closed-tour test |
|
97 |
|
98 if [ $tsts1 -eq 0 ] |
|
99 then |
|
100 echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out |
|
101 |
|
102 if (scala_assert "knight2.scala" "knight_test7.scala") |
|
103 then |
|
104 echo -e " --> success" | tee -a $out |
|
105 marks=$(( marks + 1 )) |
|
106 else |
|
107 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
108 fi |
|
109 fi |
|
110 |
|
111 |
|
112 |
|
113 if [ $tsts1 -eq 0 ] |
|
114 then |
|
115 echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out |
|
116 echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" | tee -a $out |
|
117 |
|
118 if (scala_assert "knight2.scala" "knight_test8.scala") |
|
119 then |
|
120 echo -e " --> success" | tee -a $out |
|
121 marks=$(( marks + 1 )) |
|
122 else |
|
123 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
124 fi |
|
125 fi |
|
126 |
|
127 |
|
128 # knights3: purity test |
|
129 # |
|
130 echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
131 |
|
132 |
|
133 if (scala_vars knight3.scala) |
|
134 then |
|
135 echo " --> test failed" | tee -a $out |
|
136 tsts0=$(( 0 )) |
|
137 else |
|
138 echo " --> success" | tee -a $out |
|
139 tsts0=$(( 0 )) |
|
140 fi |
|
141 |
|
142 |
|
143 # compilation test |
|
144 if [ $tsts0 -eq 0 ] |
|
145 then |
|
146 echo "knight3.scala runs?" | tee -a $out |
|
147 |
|
148 if (scala_compile knight3.scala) |
|
149 then |
|
150 echo " --> success" | tee -a $out |
|
151 tsts1=$(( 0 )) |
|
152 else |
|
153 echo -e " --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out |
|
154 tsts1=$(( 1 )) |
|
155 fi |
|
156 else |
|
157 tsts1=$(( 1 )) |
|
158 fi |
|
159 |
|
160 |
|
161 if [ $tsts1 -eq 0 ] |
|
162 then |
|
163 echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out |
|
164 |
|
165 if (scala_assert "knight3.scala" "knight_test9.scala") |
|
166 then |
|
167 echo -e " --> success" | tee -a $out |
|
168 marks=$(( marks + 1 )) |
|
169 else |
|
170 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
171 fi |
|
172 fi |
|
173 |
|
174 |
|
175 ## final marks |
|
176 echo "Overall mark for CW 8, Part 2" | tee -a $out |
|
177 echo "$marks" | tee -a $out |