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