| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Sat, 14 Jan 2023 14:13:16 +0000 | |
| changeset 456 | 873d0b16aaa9 | 
| parent 423 | 554278cd4b70 | 
| child 457 | 85942c3b387a | 
| permissions | -rwxr-xr-x | 
| 263 | 1 | #!/bin/bash | 
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 2 | set -euo pipefail | 
| 263 | 3 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 4 | scalafile=${1:-bfc.scala}
 | 
| 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 5 | out=${2:-output}
 | 
| 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 {
 | |
| 423 | 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 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 | 
| 84 | echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 | |
| 348 | 98 | echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out | 
| 263 | 99 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
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 |