235
|
1 |
#!/bin/bash
|
286
|
2 |
set -euo pipefail
|
235
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
236
|
6 |
echo -e "" > $out
|
235
|
7 |
|
286
|
8 |
echo -e "Below is the feedback for your submission of CW 10." >> $out
|
236
|
9 |
echo -e "" >> $out
|
235
|
10 |
|
|
11 |
|
|
12 |
# compilation tests
|
|
13 |
|
|
14 |
function scala_compile {
|
348
|
15 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
|
235
|
16 |
}
|
|
17 |
|
|
18 |
# functional tests
|
|
19 |
|
|
20 |
function scala_assert {
|
348
|
21 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
|
235
|
22 |
}
|
|
23 |
|
|
24 |
# purity test
|
|
25 |
|
|
26 |
function scala_vars {
|
348
|
27 |
(egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
|
235
|
28 |
}
|
|
29 |
|
|
30 |
|
348
|
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 |
|
235
|
45 |
# var, return, ListBuffer test
|
|
46 |
#
|
|
47 |
|
348
|
48 |
if [ $tsts1 -eq 0 ]
|
235
|
49 |
then
|
348
|
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
|
235
|
60 |
fi
|
|
61 |
|
|
62 |
|
|
63 |
|
236
|
64 |
### bf tests
|
235
|
65 |
|
|
66 |
if [ $tsts1 -eq 0 ]
|
|
67 |
then
|
236
|
68 |
echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
|
|
69 |
echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out
|
235
|
70 |
|
236
|
71 |
if (scala_assert "bf.scala" "bf_test1.scala")
|
235
|
72 |
then
|
236
|
73 |
echo -e " --> success" >> $out
|
235
|
74 |
else
|
236
|
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
|
235
|
91 |
fi
|
|
92 |
fi
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
if [ $tsts1 -eq 0 ]
|
|
97 |
then
|
243
|
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
|
235
|
106 |
|
236
|
107 |
if (scala_assert "bf.scala" "bf_test3.scala")
|
235
|
108 |
then
|
236
|
109 |
echo -e " --> success" >> $out
|
235
|
110 |
else
|
236
|
111 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
235
|
112 |
fi
|
|
113 |
fi
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
if [ $tsts1 -eq 0 ]
|
|
118 |
then
|
236
|
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
|
340
|
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 |
|
236
|
125 |
echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
|
|
126 |
echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
|
235
|
127 |
|
236
|
128 |
if (scala_assert "bf.scala" "bf_test4.scala")
|
235
|
129 |
then
|
236
|
130 |
echo -e " --> success" >> $out
|
235
|
131 |
else
|
236
|
132 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
235
|
133 |
fi
|
|
134 |
fi
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|