1 #!/bin/bash |
|
2 set -e |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo -e "" > $out |
|
7 |
|
8 echo -e "Below is the feedback for your submission of CW 10, Part 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 { |
|
21 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null) |
|
22 } |
|
23 |
|
24 # purity test |
|
25 |
|
26 function scala_vars { |
|
27 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
28 } |
|
29 |
|
30 |
|
31 # var, return, ListBuffer test |
|
32 # |
|
33 echo -e "bfc.scala does not contain vars, returns etc?" >> $out |
|
34 |
|
35 if (scala_vars bfc.scala) |
|
36 then |
|
37 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
38 tsts0=$(( 0 )) |
|
39 else |
|
40 echo -e " --> success" >> $out |
|
41 tsts0=$(( 0 )) |
|
42 fi |
|
43 |
|
44 |
|
45 # compilation test |
|
46 if [ $tsts0 -eq 0 ] |
|
47 then |
|
48 echo -e "bfc.scala runs?" >> $out |
|
49 |
|
50 if (scala_compile bfc.scala) |
|
51 then |
|
52 echo -e " --> success" >> $out |
|
53 tsts1=$(( 0 )) |
|
54 else |
|
55 echo -e " --> --> SCALA DID NOT RUN BFC.SCALA\n" >> $out |
|
56 tsts1=$(( 1 )) |
|
57 fi |
|
58 else |
|
59 tsts1=$(( 1 )) |
|
60 fi |
|
61 |
|
62 |
|
63 ### bfc tests |
|
64 |
|
65 if [ $tsts1 -eq 0 ] |
|
66 then |
|
67 echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out |
|
68 echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out |
|
69 |
|
70 if (scala_assert "bfc.scala" "bf_test5.scala") |
|
71 then |
|
72 echo -e " --> success" >> $out |
|
73 else |
|
74 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
75 fi |
|
76 fi |
|
77 |
|
78 |
|
79 |
|
80 if [ $tsts1 -eq 0 ] |
|
81 then |
|
82 echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out |
|
83 echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out |
|
84 |
|
85 if (scala_assert "bfc.scala" "bf_test6.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 |
|
94 |
|
95 if [ $tsts1 -eq 0 ] |
|
96 then |
|
97 echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out |
|
98 echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out |
|
99 |
|
100 if (scala_assert "bfc.scala" "bf_test7.scala") |
|
101 then |
|
102 echo -e " --> success" >> $out |
|
103 else |
|
104 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
105 fi |
|
106 fi |
|
107 |
|
108 |
|
109 |
|