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