| 263 |      1 | #!/bin/bash
 | 
|  |      2 | set -e
 | 
|  |      3 | 
 | 
|  |      4 | out=${1:-output}
 | 
|  |      5 | 
 | 
|  |      6 | echo -e "" > $out
 | 
|  |      7 | 
 | 
|  |      8 | echo -e "Below is the feedback for your submission of CW 10, Part 2." >> $out
 | 
|  |      9 | echo -e "" >> $out
 | 
|  |     10 | 
 | 
|  |     11 | # compilation tests
 | 
|  |     12 | 
 | 
|  |     13 | function scala_compile {
 | 
| 348 |     14 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
 | 
| 263 |     15 | }
 | 
|  |     16 | 
 | 
|  |     17 | # functional tests
 | 
|  |     18 | 
 | 
|  |     19 | function scala_assert {
 | 
| 348 |     20 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 263 |     21 | }
 | 
|  |     22 | 
 | 
|  |     23 | # purity test
 | 
|  |     24 | 
 | 
|  |     25 | function scala_vars {
 | 
| 376 |     26 |    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
 | 
| 263 |     27 | }
 | 
|  |     28 | 
 | 
|  |     29 | 
 | 
| 348 |     30 | 
 | 
|  |     31 | 
 | 
|  |     32 | # compilation test
 | 
|  |     33 | echo -e "bfc.scala runs?" >> $out
 | 
|  |     34 | 
 | 
|  |     35 | if (scala_compile bfc.scala)
 | 
|  |     36 | then
 | 
| 352 |     37 |     echo -e "  --> passed" >> $out
 | 
| 348 |     38 |     tsts1=$(( 0 ))
 | 
|  |     39 | else
 | 
| 352 |     40 |     echo -e "  --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
 | 
| 348 |     41 |     tsts1=$(( 1 )) 
 | 
|  |     42 | fi
 | 
|  |     43 | 
 | 
|  |     44 | 
 | 
| 263 |     45 | # var, return, ListBuffer test
 | 
|  |     46 | #
 | 
| 348 |     47 | if [ $tsts1 -eq 0 ]
 | 
| 263 |     48 | then
 | 
| 348 |     49 |     echo -e "bfc.scala does not contain vars, returns etc?" >> $out
 | 
| 263 |     50 | 
 | 
| 348 |     51 |     if (scala_vars bfc.scala)
 | 
|  |     52 |     then
 | 
|  |     53 | 	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
 | 
|  |     54 | 	tsts1=$(( 1 ))
 | 
|  |     55 |     else
 | 
| 352 |     56 | 	echo -e "  --> passed" >> $out
 | 
| 348 |     57 | 	tsts1=$(( 0 )) 
 | 
|  |     58 |     fi
 | 
| 263 |     59 | fi
 | 
|  |     60 | 
 | 
|  |     61 | ### bfc tests
 | 
|  |     62 | 
 | 
|  |     63 | if [ $tsts1 -eq 0 ]
 | 
|  |     64 | then
 | 
|  |     65 |   echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
 | 
|  |     66 |   echo -e "     Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out  
 | 
|  |     67 |   
 | 
|  |     68 |   if (scala_assert "bfc.scala" "bf_test5.scala")
 | 
|  |     69 |   then
 | 
|  |     70 |     echo -e "  --> success" >> $out
 | 
|  |     71 |   else
 | 
|  |     72 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out
 | 
|  |     73 |   fi
 | 
|  |     74 | fi
 | 
|  |     75 | 
 | 
|  |     76 | 
 | 
|  |     77 | 
 | 
|  |     78 | if [ $tsts1 -eq 0 ]
 | 
|  |     79 | then
 | 
| 384 |     80 |     echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
 | 
|  |     81 |     echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out  
 | 
| 263 |     82 |   if (scala_assert "bfc.scala" "bf_test6.scala")
 | 
|  |     83 |   then
 | 
|  |     84 |     echo -e "  --> success" >> $out
 | 
|  |     85 |   else
 | 
|  |     86 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out
 | 
|  |     87 |   fi
 | 
|  |     88 | fi
 | 
|  |     89 | 
 | 
|  |     90 | 
 | 
|  |     91 | 
 | 
|  |     92 | if [ $tsts1 -eq 0 ]
 | 
|  |     93 | then
 | 
|  |     94 |     echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
 | 
| 348 |     95 |     echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
 | 
| 263 |     96 |   
 | 
|  |     97 |   if (scala_assert "bfc.scala" "bf_test7.scala")
 | 
|  |     98 |   then
 | 
|  |     99 |     echo -e "  --> success" >> $out
 | 
|  |    100 |   else
 | 
|  |    101 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out   
 | 
|  |    102 |   fi
 | 
|  |    103 | fi
 | 
|  |    104 | 
 | 
|  |    105 | 
 | 
|  |    106 | 
 |