|
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 10." >> $out |
|
9 echo -e "" >> $out |
|
10 |
|
11 |
|
12 # compilation tests |
|
13 |
|
14 function scala_compile { |
|
15 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
|
16 } |
|
17 |
|
18 # functional tests |
|
19 |
|
20 function scala_assert { |
|
21 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
22 } |
|
23 |
|
24 # purity test |
|
25 |
|
26 function scala_vars { |
|
27 (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) |
|
28 } |
|
29 |
|
30 |
|
31 |
|
32 # compilation test |
|
33 echo -e "bf.scala runs?" >> $out |
|
34 |
|
35 if (scala_compile bf.scala) |
|
36 then |
|
37 echo -e " --> success" >> $out |
|
38 tsts1=$(( 0 )) |
|
39 else |
|
40 echo -e " --> SCALA DID NOT RUN BF.SCALA\n" >> $out |
|
41 tsts1=$(( 1 )) |
|
42 fi |
|
43 |
|
44 |
|
45 # var, return, ListBuffer test |
|
46 # |
|
47 |
|
48 if [ $tsts1 -eq 0 ] |
|
49 then |
|
50 echo -e "bf.scala does not contain vars, returns etc?" >> $out |
|
51 |
|
52 if (scala_vars bf.scala) |
|
53 then |
|
54 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
55 tsts1=$(( 1 )) |
|
56 else |
|
57 echo -e " --> success" >> $out |
|
58 tsts1=$(( 0 )) |
|
59 fi |
|
60 fi |
|
61 |
|
62 |
|
63 |
|
64 ### bf tests |
|
65 |
|
66 if [ $tsts1 -eq 0 ] |
|
67 then |
|
68 echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out |
|
69 echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out |
|
70 |
|
71 if (scala_assert "bf.scala" "bf_test1.scala") |
|
72 then |
|
73 echo -e " --> success" >> $out |
|
74 else |
|
75 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
76 fi |
|
77 fi |
|
78 |
|
79 if [ $tsts1 -eq 0 ] |
|
80 then |
|
81 echo -e " sread(Map(), 2) == 0" >> $out |
|
82 echo -e " sread(Map(2 -> 1), 2) == 1" >> $out |
|
83 echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out |
|
84 echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out |
|
85 |
|
86 if (scala_assert "bf.scala" "bf_test2.scala") |
|
87 then |
|
88 echo -e " --> success" >> $out |
|
89 else |
|
90 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
91 fi |
|
92 fi |
|
93 |
|
94 |
|
95 |
|
96 if [ $tsts1 -eq 0 ] |
|
97 then |
|
98 echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out |
|
99 echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out |
|
100 echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out |
|
101 echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out |
|
102 echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out |
|
103 echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out |
|
104 echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out |
|
105 echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out |
|
106 |
|
107 if (scala_assert "bf.scala" "bf_test3.scala") |
|
108 then |
|
109 echo -e " --> success" >> $out |
|
110 else |
|
111 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
112 fi |
|
113 fi |
|
114 |
|
115 |
|
116 |
|
117 if [ $tsts1 -eq 0 ] |
|
118 then |
|
119 echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out |
|
120 echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out |
|
121 echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out |
|
122 echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000))" >> $out |
|
123 echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" >> $out |
|
124 |
|
125 echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out |
|
126 echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out |
|
127 |
|
128 if (scala_assert "bf.scala" "bf_test4.scala") |
|
129 then |
|
130 echo -e " --> success" >> $out |
|
131 else |
|
132 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
133 fi |
|
134 fi |
|
135 |
|
136 |
|
137 |
|
138 |