author | Christian Urban <christian.urban@kcl.ac.uk> |
Sun, 15 Jan 2023 10:58:13 +0000 | |
changeset 462 | 34feeb53c0ba |
parent 460 | 39ec5c112312 |
child 475 | 59e005dcf163 |
permissions | -rwxr-xr-x |
263 | 1 |
#!/bin/bash |
419
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
2 |
set -euo pipefail |
263 | 3 |
|
419
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
4 |
scalafile=${1:-bfc.scala} |
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
5 |
out=${2:-output} |
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
6 |
|
263 | 7 |
|
8 |
echo -e "" > $out |
|
9 |
||
404 | 10 |
echo -e "Below is the feedback for your submission of bfc.scala" >> $out |
263 | 11 |
echo -e "" >> $out |
12 |
||
13 |
# compilation tests |
|
14 |
||
15 |
function scala_compile { |
|
348 | 16 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
263 | 17 |
} |
18 |
||
19 |
# functional tests |
|
20 |
||
21 |
function scala_assert { |
|
348 | 22 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
263 | 23 |
} |
24 |
||
25 |
# purity test |
|
26 |
||
27 |
function scala_vars { |
|
426 | 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) |
|
263 | 30 |
} |
31 |
||
32 |
||
348 | 33 |
|
34 |
||
35 |
# compilation test |
|
36 |
echo -e "bfc.scala runs?" >> $out |
|
37 |
||
419
d8dbf91c149b
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 |
|
352 | 43 |
echo -e " --> SCALA DID NOT RUN BFC.SCALA\n" >> $out |
348 | 44 |
tsts1=$(( 1 )) |
45 |
fi |
|
46 |
||
47 |
||
263 | 48 |
# var, return, ListBuffer test |
49 |
# |
|
348 | 50 |
if [ $tsts1 -eq 0 ] |
263 | 51 |
then |
348 | 52 |
echo -e "bfc.scala does not contain vars, returns etc?" >> $out |
263 | 53 |
|
419
d8dbf91c149b
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 |
|
263 | 62 |
fi |
63 |
||
64 |
### bfc tests |
|
65 |
||
66 |
if [ $tsts1 -eq 0 ] |
|
67 |
then |
|
68 |
echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out |
|
69 |
echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out |
|
70 |
||
419
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
71 |
if (scala_assert $scalafile "bf_test5.scala") |
263 | 72 |
then |
73 |
echo -e " --> success" >> $out |
|
74 |
else |
|
75 |
echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
76 |
fi |
|
77 |
fi |
|
78 |
||
79 |
||
80 |
||
81 |
if [ $tsts1 -eq 0 ] |
|
82 |
then |
|
384 | 83 |
echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out |
460 | 84 |
echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out |
419
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
85 |
if (scala_assert $scalafile "bf_test6.scala") |
263 | 86 |
then |
87 |
echo -e " --> success" >> $out |
|
88 |
else |
|
89 |
echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
90 |
fi |
|
91 |
fi |
|
92 |
||
93 |
||
94 |
||
95 |
if [ $tsts1 -eq 0 ] |
|
96 |
then |
|
97 |
echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out |
|
462 | 98 |
echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out |
263 | 99 |
|
419
d8dbf91c149b
updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents:
404
diff
changeset
|
100 |
if (scala_assert $scalafile "bf_test7.scala") |
263 | 101 |
then |
102 |
echo -e " --> success" >> $out |
|
103 |
else |
|
104 |
echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
105 |
fi |
|
106 |
fi |
|
107 |
||
108 |
||
109 |