10 |
10 |
11 |
11 |
12 # compilation tests |
12 # compilation tests |
13 |
13 |
14 function scala_compile { |
14 function scala_compile { |
15 (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) |
15 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
16 } |
16 } |
17 |
17 |
18 # functional tests |
18 # functional tests |
19 |
19 |
20 function scala_assert { |
20 function scala_assert_slow { |
21 (ulimit -t 300 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
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 10; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
22 } |
30 } |
23 |
31 |
24 # purity test |
32 # purity test |
25 |
33 |
26 function scala_vars { |
34 function scala_vars { |
27 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
35 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
28 } |
36 } |
29 |
37 |
30 |
38 |
31 # knights1: purity test |
39 # knights1: purity test |
32 |
40 |
33 echo "knight1.scala does not contain vars, returns etc?" >> $out |
41 echo "knight1.scala does not contain vars, returns etc?" >> $out |
34 |
42 |
35 if (scala_vars knight1.scala) |
43 if (scala_vars knight1.scala) |
36 then |
44 then |
37 echo " --> fail" >> $out |
45 echo " --> fail: if you do not fix this, you will receive a mark of zero" >> $out |
38 tsts0=$(( 1 )) |
46 tsts0=$(( 1 )) |
39 else |
47 else |
40 echo " --> success" >> $out |
48 echo " --> success" >> $out |
41 tsts0=$(( 0 )) |
49 tsts0=$(( 0 )) |
42 fi |
50 fi |
62 |
70 |
63 ### knight1a test |
71 ### knight1a test |
64 |
72 |
65 if [ $tsts1 -eq 0 ] |
73 if [ $tsts1 -eq 0 ] |
66 then |
74 then |
67 echo " is_legal(8, Nil) (3, 4) == true " >> $out |
75 echo "Takes 10 seconds or less to execute: " >> $out |
68 echo " is_legal(8, List((4, 1), (1, 0))) (4, 1) == false " >> $out |
76 echo " is_legal(8, Nil)(3, 4) == true " >> $out |
69 echo " is_legal(2, Nil) (0, 0) == true" >> $out |
77 echo " is_legal(8, List((4, 1), (1, 0)))(4, 1) == false " >> $out |
|
78 echo " is_legal(2, Nil)(0, 0) == true" >> $out |
70 |
79 |
71 if (scala_assert "knight1.scala" "knight1a_test.scala") |
80 if (scala_assert_quick "knight1.scala" "knight1a_test.scala") |
72 then |
81 then |
73 echo " --> success" >> $out |
82 echo " --> success" >> $out |
74 else |
83 else |
75 echo " --> test failed" >> $out |
84 echo " --> test failed" >> $out |
76 fi |
85 fi |
78 |
87 |
79 ### knight1b test |
88 ### knight1b test |
80 |
89 |
81 if [ $tsts1 -eq 0 ] |
90 if [ $tsts1 -eq 0 ] |
82 then |
91 then |
|
92 echo "Takes 10 seconds or less to execute: " >> $out |
83 echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out |
93 echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out |
84 echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out |
94 echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out |
85 echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out |
95 echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out |
86 echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out |
96 echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out |
87 echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out |
97 echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out |
88 echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out |
98 echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out |
89 echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out |
99 echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out |
90 |
100 |
91 if (scala_assert "knight1.scala" "knight1b_test.scala") |
101 if (scala_assert_quick "knight1.scala" "knight1b_test.scala") |
92 then |
102 then |
93 echo " --> success" >> $out |
103 echo " --> success" >> $out |
94 else |
104 else |
95 echo " --> test failed" >> $out |
105 echo " --> test failed" >> $out |
96 fi |
106 fi |
99 |
109 |
100 ### knight1c test |
110 ### knight1c test |
101 |
111 |
102 if [ $tsts1 -eq 0 ] |
112 if [ $tsts1 -eq 0 ] |
103 then |
113 then |
104 echo " all_tours from every position on the board" >> $out |
114 echo " all_tours from every position on the board, in 2 minutes or less" >> $out |
105 echo " dim = 1: 1" >> $out |
115 echo " dim = 1: 1" >> $out |
106 echo " 2: 0,0,0,0" >> $out |
116 echo " 2: 0,0,0,0" >> $out |
107 echo " 3: 0,0,0,0,0,0,0,0,0" >> $out |
117 echo " 3: 0,0,0,0,0,0,0,0,0" >> $out |
108 echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out |
118 echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out |
109 echo " 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 |
119 echo " 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 |
110 echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out |
120 echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out |
111 |
121 |
112 if (scala_assert "knight1.scala" "knight1c_test.scala") |
122 if (scala_assert_slow "knight1.scala" "knight1c_test.scala") |
113 then |
123 then |
114 echo " --> success" >> $out |
124 echo " --> success" >> $out |
115 else |
125 else |
116 echo " --> test failed" >> $out |
126 echo " --> test failed" >> $out |
117 fi |
127 fi |
151 |
161 |
152 ### knight2a test |
162 ### knight2a test |
153 |
163 |
154 if [ $tsts1 -eq 0 ] |
164 if [ $tsts1 -eq 0 ] |
155 then |
165 then |
|
166 echo "Takes 10 seconds or less to execute: " >> $out |
156 echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out |
167 echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out |
157 echo " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out |
168 echo " first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out |
158 echo " first(List((1,0),(2,0),(3,0)), f) == None" >> $out |
169 echo " first(List((1,0),(2,0),(3,0)), f) == None" >> $out |
159 |
170 |
160 if (scala_assert "knight2.scala" "knight2a_test.scala") |
171 if (scala_assert_quick "knight2.scala" "knight2a_test.scala") |
161 then |
172 then |
162 echo " --> success" >> $out |
173 echo " --> success" >> $out |
163 else |
174 else |
164 echo " --> test failed" >> $out |
175 echo " --> test failed" >> $out |
165 fi |
176 fi |