| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Thu, 13 Jan 2022 12:55:03 +0000 | |
| changeset 420 | a6db2b70abdd | 
| parent 416 | ef6ad5276c02 | 
| child 423 | 554278cd4b70 | 
| 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 {
 | |
| 376 | 28 | (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) | 
| 263 | 29 | } | 
| 30 | ||
| 31 | ||
| 348 | 32 | |
| 33 | ||
| 34 | # compilation test | |
| 35 | echo -e "bfc.scala runs?" >> $out | |
| 36 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 37 | if (scala_compile $scalafile) | 
| 348 | 38 | then | 
| 352 | 39 | echo -e " --> passed" >> $out | 
| 348 | 40 | tsts1=$(( 0 )) | 
| 41 | else | |
| 352 | 42 | echo -e " --> SCALA DID NOT RUN BFC.SCALA\n" >> $out | 
| 348 | 43 | tsts1=$(( 1 )) | 
| 44 | fi | |
| 45 | ||
| 46 | ||
| 263 | 47 | # var, return, ListBuffer test | 
| 48 | # | |
| 348 | 49 | if [ $tsts1 -eq 0 ] | 
| 263 | 50 | then | 
| 348 | 51 | echo -e "bfc.scala does not contain vars, returns etc?" >> $out | 
| 263 | 52 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 53 | if (scala_vars $scalafile) | 
| 348 | 54 | then | 
| 55 | echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out | |
| 56 | tsts1=$(( 1 )) | |
| 57 | else | |
| 352 | 58 | echo -e " --> passed" >> $out | 
| 348 | 59 | tsts1=$(( 0 )) | 
| 60 | fi | |
| 263 | 61 | fi | 
| 62 | ||
| 63 | ### bfc tests | |
| 64 | ||
| 65 | if [ $tsts1 -eq 0 ] | |
| 66 | then | |
| 67 | echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out | |
| 68 | echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out | |
| 69 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 70 | if (scala_assert $scalafile "bf_test5.scala") | 
| 263 | 71 | then | 
| 72 | echo -e " --> success" >> $out | |
| 73 | else | |
| 74 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 75 | fi | |
| 76 | fi | |
| 77 | ||
| 78 | ||
| 79 | ||
| 80 | if [ $tsts1 -eq 0 ] | |
| 81 | then | |
| 384 | 82 | echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out | 
| 83 | 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 | 84 | if (scala_assert $scalafile "bf_test6.scala") | 
| 263 | 85 | then | 
| 86 | echo -e " --> success" >> $out | |
| 87 | else | |
| 88 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 89 | fi | |
| 90 | fi | |
| 91 | ||
| 92 | ||
| 93 | ||
| 94 | if [ $tsts1 -eq 0 ] | |
| 95 | then | |
| 96 | echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out | |
| 348 | 97 | echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out | 
| 263 | 98 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 99 | if (scala_assert $scalafile "bf_test7.scala") | 
| 263 | 100 | then | 
| 101 | echo -e " --> success" >> $out | |
| 102 | else | |
| 103 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 104 | fi | |
| 105 | fi | |
| 106 | ||
| 107 | ||
| 108 |