|
1 #!/bin/bash |
|
2 set -e |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo "" > $out |
|
7 |
|
8 echo "Below is the feedback for your submission of CW 7, Part 3." >> $out |
|
9 echo "" >> $out |
|
10 |
|
11 function scala_vars { |
|
12 (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
|
13 } |
|
14 |
|
15 # compilation tests |
|
16 |
|
17 function scala_compile { |
|
18 (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) |
|
19 } |
|
20 |
|
21 # functional tests |
|
22 |
|
23 function scala_assert { |
|
24 (ulimit -t 300 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
25 } |
|
26 |
|
27 # purity test |
|
28 |
|
29 function scala_vars { |
|
30 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
|
31 } |
|
32 |
|
33 |
|
34 # knights3: purity test |
|
35 # |
|
36 echo "knight3.scala does not contain vars, returns etc?" >> $out |
|
37 |
|
38 if (scala_vars knight3.scala) |
|
39 then |
|
40 echo " --> fail" >> $out |
|
41 tsts0=$(( 1 )) |
|
42 else |
|
43 echo " --> success" >> $out |
|
44 tsts0=$(( 0 )) |
|
45 fi |
|
46 |
|
47 |
|
48 # compilation test |
|
49 if [ $tsts0 -eq 0 ] |
|
50 then |
|
51 echo "knight3.scala runs?" >> $out |
|
52 |
|
53 if (scala_compile knight3.scala) |
|
54 then |
|
55 echo " --> success" >> $out |
|
56 tsts1=$(( 0 )) |
|
57 else |
|
58 echo " --> scala knight3.scala did not run successfully" >> $out |
|
59 tsts1=$(( 1 )) |
|
60 fi |
|
61 else |
|
62 tsts1=$(( 1 )) |
|
63 fi |
|
64 |
|
65 # ordered move test |
|
66 |
|
67 if [ $tsts1 -eq 0 ] |
|
68 then |
|
69 echo " ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out |
|
70 echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out |
|
71 echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out |
|
72 |
|
73 if (scala_assert "knight3.scala" "knight3a_test.scala") |
|
74 then |
|
75 echo " --> success" >> $out |
|
76 else |
|
77 echo " --> test failed" >> $out |
|
78 fi |
|
79 fi |
|
80 |
|
81 |
|
82 # first-closed-tour test |
|
83 |
|
84 if [ $tsts1 -eq 0 ] |
|
85 then |
|
86 echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" >> $out |
|
87 |
|
88 if (scala_assert "knight3.scala" "knight3b_test.scala") |
|
89 then |
|
90 echo " --> success" >> $out |
|
91 else |
|
92 echo " --> test failed" >> $out |
|
93 fi |
|
94 fi |
|
95 |
|
96 |
|
97 |
|
98 if [ $tsts1 -eq 0 ] |
|
99 then |
|
100 echo " first_tour_heuristic(8, List((0,0))) found and ok?" >> $out |
|
101 echo " first_tour_heuristic(40, List((0,0))) found and ok?" >> $out |
|
102 |
|
103 if (scala_assert "knight3.scala" "knight3c_test.scala") |
|
104 then |
|
105 echo " --> success" >> $out |
|
106 else |
|
107 echo " --> test failed" >> $out |
|
108 fi |
|
109 fi |
|
110 |
|
111 |
|
112 ## final marks |
|
113 ##echo "Overall mark for CW 7, Part 2" | tee -a $out |
|
114 ##echo "$marks" | tee -a $out |