| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Sat, 11 Mar 2023 23:12:49 +0000 | |
| changeset 464 | 1b1330cde075 | 
| parent 423 | 554278cd4b70 | 
| child 472 | fbff6f601370 | 
| permissions | -rwxr-xr-x | 
| 235 | 1  | 
#!/bin/bash  | 
| 286 | 2  | 
set -euo pipefail  | 
| 235 | 3  | 
|
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
4  | 
|
| 
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
5  | 
scalafile=${1:-bf.scala}
 | 
| 
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
6  | 
out=${2:-output}
 | 
| 235 | 7  | 
|
| 236 | 8  | 
echo -e "" > $out  | 
| 235 | 9  | 
|
| 404 | 10  | 
echo -e "Below is the feedback for your submission of bf.scala." >> $out  | 
| 236 | 11  | 
echo -e "" >> $out  | 
| 235 | 12  | 
|
13  | 
||
14  | 
# compilation tests  | 
|
15  | 
||
16  | 
function scala_compile {
 | 
|
| 348 | 17  | 
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)  | 
| 235 | 18  | 
}  | 
19  | 
||
20  | 
# functional tests  | 
|
21  | 
||
22  | 
function scala_assert {
 | 
|
| 348 | 23  | 
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  | 
| 235 | 24  | 
}  | 
25  | 
||
26  | 
# purity test  | 
|
27  | 
||
28  | 
function scala_vars {
 | 
|
| 423 | 29  | 
(sed 's/immutable/ok/g' c$out > cb$out;  | 
30  | 
egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)  | 
|
| 235 | 31  | 
}  | 
32  | 
||
33  | 
||
| 348 | 34  | 
|
35  | 
# compilation test  | 
|
36  | 
echo -e "bf.scala runs?" >> $out  | 
|
37  | 
||
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
38  | 
if (scala_compile $scalafile)  | 
| 348 | 39  | 
then  | 
| 352 | 40  | 
echo -e " --> passed" >> $out  | 
| 348 | 41  | 
tsts1=$(( 0 ))  | 
42  | 
else  | 
|
43  | 
echo -e " --> SCALA DID NOT RUN BF.SCALA\n" >> $out  | 
|
44  | 
tsts1=$(( 1 ))  | 
|
45  | 
fi  | 
|
46  | 
||
47  | 
||
| 235 | 48  | 
# var, return, ListBuffer test  | 
49  | 
#  | 
|
50  | 
||
| 348 | 51  | 
if [ $tsts1 -eq 0 ]  | 
| 235 | 52  | 
then  | 
| 348 | 53  | 
echo -e "bf.scala does not contain vars, returns etc?" >> $out  | 
54  | 
||
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
55  | 
if (scala_vars $scalafile)  | 
| 348 | 56  | 
then  | 
57  | 
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out  | 
|
58  | 
tsts1=$(( 1 ))  | 
|
59  | 
else  | 
|
| 352 | 60  | 
echo -e " --> passed" >> $out  | 
| 348 | 61  | 
tsts1=$(( 0 ))  | 
62  | 
fi  | 
|
| 235 | 63  | 
fi  | 
64  | 
||
65  | 
||
66  | 
||
| 236 | 67  | 
### bf tests  | 
| 235 | 68  | 
|
69  | 
if [ $tsts1 -eq 0 ]  | 
|
70  | 
then  | 
|
| 236 | 71  | 
echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out  | 
72  | 
echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  | 
|
| 235 | 73  | 
|
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
74  | 
if (scala_assert $scalafile "bf_test1.scala")  | 
| 235 | 75  | 
then  | 
| 236 | 76  | 
echo -e " --> success" >> $out  | 
| 235 | 77  | 
else  | 
| 236 | 78  | 
echo -e " --> \n ONE TEST FAILED\n" >> $out  | 
79  | 
fi  | 
|
80  | 
fi  | 
|
81  | 
||
82  | 
if [ $tsts1 -eq 0 ]  | 
|
83  | 
then  | 
|
84  | 
echo -e " sread(Map(), 2) == 0" >> $out  | 
|
85  | 
echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  | 
|
86  | 
echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out  | 
|
87  | 
echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out  | 
|
88  | 
||
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
89  | 
if (scala_assert $scalafile "bf_test2.scala")  | 
| 236 | 90  | 
then  | 
91  | 
echo -e " --> success" >> $out  | 
|
92  | 
else  | 
|
93  | 
echo -e " --> \n ONE TEST FAILED\n" >> $out  | 
|
| 235 | 94  | 
fi  | 
95  | 
fi  | 
|
96  | 
||
97  | 
||
98  | 
||
99  | 
if [ $tsts1 -eq 0 ]  | 
|
100  | 
then  | 
|
| 243 | 101  | 
echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out  | 
102  | 
echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out  | 
|
103  | 
echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out  | 
|
104  | 
echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out  | 
|
105  | 
echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out  | 
|
106  | 
echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out  | 
|
107  | 
echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out  | 
|
108  | 
echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out  | 
|
| 235 | 109  | 
|
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
110  | 
if (scala_assert $scalafile "bf_test3.scala")  | 
| 235 | 111  | 
then  | 
| 236 | 112  | 
echo -e " --> success" >> $out  | 
| 235 | 113  | 
else  | 
| 236 | 114  | 
echo -e " --> \n ONE TEST FAILED\n" >> $out  | 
| 235 | 115  | 
fi  | 
116  | 
fi  | 
|
117  | 
||
118  | 
||
119  | 
||
120  | 
if [ $tsts1 -eq 0 ]  | 
|
121  | 
then  | 
|
| 236 | 122  | 
echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out  | 
123  | 
echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out  | 
|
124  | 
echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out  | 
|
| 340 | 125  | 
|
| 236 | 126  | 
echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out  | 
127  | 
echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out  | 
|
| 235 | 128  | 
|
| 
416
 
ef6ad5276c02
updated test with second arguments
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents: 
404 
diff
changeset
 | 
129  | 
if (scala_assert $scalafile "bf_test4.scala")  | 
| 235 | 130  | 
then  | 
| 236 | 131  | 
echo -e " --> success" >> $out  | 
| 235 | 132  | 
else  | 
| 236 | 133  | 
echo -e " --> \n ONE TEST FAILED\n" >> $out  | 
| 235 | 134  | 
fi  | 
135  | 
fi  | 
|
136  | 
||
137  | 
||
138  | 
||
139  |