main_testing5/bfc_test.sh
changeset 348 b5b6ed38c2f2
parent 286 5c57c407e27b
child 352 97bcf8efe4e0
equal deleted inserted replaced
347:4de31fdc0d67 348:b5b6ed38c2f2
       
     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 {
       
    14   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    15 }
       
    16 
       
    17 # functional tests
       
    18 
       
    19 function scala_assert {
       
    20   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    21 }
       
    22 
       
    23 # purity test
       
    24 
       
    25 function scala_vars {
       
    26    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    27 }
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 # compilation test
       
    33 echo -e "bfc.scala runs?" >> $out
       
    34 
       
    35 if (scala_compile bfc.scala)
       
    36 then
       
    37     echo -e "  --> success" >> $out
       
    38     tsts1=$(( 0 ))
       
    39 else
       
    40     echo -e "  -->   --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
       
    41     tsts1=$(( 1 )) 
       
    42 fi
       
    43 
       
    44 
       
    45 # var, return, ListBuffer test
       
    46 #
       
    47 if [ $tsts1 -eq 0 ]
       
    48 then
       
    49     echo -e "bfc.scala does not contain vars, returns etc?" >> $out
       
    50 
       
    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
       
    56 	echo -e "  --> success" >> $out
       
    57 	tsts1=$(( 0 )) 
       
    58     fi
       
    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
       
    80   echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
       
    81   echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out  
       
    82   
       
    83   if (scala_assert "bfc.scala" "bf_test6.scala")
       
    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
       
    96     echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
       
    97   
       
    98   if (scala_assert "bfc.scala" "bf_test7.scala")
       
    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