| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Wed, 06 Mar 2024 18:20:25 +0000 | |
| changeset 481 | cae100aab278 | 
| parent 479 | 78cb5cdda3c3 | 
| 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 {
 | |
| 474 | 16 | (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile -Xprint:parser "$1" 2> c$out 1> c$out) | 
| 263 | 17 | } | 
| 18 | ||
| 19 | # functional tests | |
| 20 | ||
| 21 | function scala_assert {
 | |
| 479 | 22 | (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()")# 2> /dev/null 1> /dev/null) | 
| 263 | 23 | } | 
| 24 | ||
| 25 | # purity test | |
| 26 | function scala_vars {
 | |
| 472 | 27 | (sed 's/immutable/ok/g' c$out > cb$out; | 
| 28 | egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null) | |
| 263 | 29 | } | 
| 30 | ||
| 31 | ||
| 348 | 32 | |
| 33 | # compilation test | |
| 34 | echo -e "bfc.scala runs?" >> $out | |
| 35 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 36 | if (scala_compile $scalafile) | 
| 348 | 37 | then | 
| 352 | 38 | echo -e " --> passed" >> $out | 
| 348 | 39 | tsts1=$(( 0 )) | 
| 40 | else | |
| 352 | 41 | echo -e " --> SCALA DID NOT RUN BFC.SCALA\n" >> $out | 
| 348 | 42 | tsts1=$(( 1 )) | 
| 43 | fi | |
| 44 | ||
| 45 | ||
| 263 | 46 | # var, return, ListBuffer test | 
| 47 | # | |
| 348 | 48 | if [ $tsts1 -eq 0 ] | 
| 263 | 49 | then | 
| 348 | 50 | echo -e "bfc.scala does not contain vars, returns etc?" >> $out | 
| 263 | 51 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 52 | if (scala_vars $scalafile) | 
| 348 | 53 | then | 
| 54 | echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out | |
| 55 | tsts1=$(( 1 )) | |
| 56 | else | |
| 352 | 57 | echo -e " --> passed" >> $out | 
| 348 | 58 | tsts1=$(( 0 )) | 
| 59 | fi | |
| 263 | 60 | fi | 
| 61 | ||
| 62 | ### bfc tests | |
| 63 | ||
| 64 | if [ $tsts1 -eq 0 ] | |
| 65 | then | |
| 66 | echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out | |
| 67 | echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out | |
| 68 | ||
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 69 | if (scala_assert $scalafile "bf_test5.scala") | 
| 263 | 70 | then | 
| 71 | echo -e " --> success" >> $out | |
| 72 | else | |
| 73 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 74 | fi | |
| 75 | fi | |
| 76 | ||
| 77 | ||
| 78 | ||
| 79 | if [ $tsts1 -eq 0 ] | |
| 80 | then | |
| 384 | 81 | echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out | 
| 457 | 82 | echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out | 
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 83 | if (scala_assert $scalafile "bf_test6.scala") | 
| 263 | 84 | then | 
| 85 | echo -e " --> success" >> $out | |
| 86 | else | |
| 87 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 88 | fi | |
| 89 | fi | |
| 90 | ||
| 91 | ||
| 92 | ||
| 93 | if [ $tsts1 -eq 0 ] | |
| 94 | then | |
| 95 | echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out | |
| 459 | 96 | echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out | 
| 263 | 97 | |
| 416 
ef6ad5276c02
updated test with second arguments
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
404diff
changeset | 98 | if (scala_assert $scalafile "bf_test7.scala") | 
| 263 | 99 | then | 
| 100 | echo -e " --> success" >> $out | |
| 101 | else | |
| 102 | echo -e " --> \n ONE TEST FAILED\n" >> $out | |
| 103 | fi | |
| 104 | fi | |
| 105 | ||
| 106 | ||
| 107 |