Attic/bfc_test.sh
changeset 333 24bc76d97db2
parent 286 5c57c407e27b
equal deleted inserted replaced
332:703c7e42bf46 333:24bc76d97db2
       
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo "" > $out
       
    10 
       
    11 
       
    12 echo "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo "for assignment 10 Part 2.  Please note all marks are provisional until" >> $out
       
    14 echo "ratified by the assessment board -- this is not an official" >> $out
       
    15 echo "results transcript." >> $out
       
    16 echo "" >> $out
       
    17 
       
    18 # marks for CW10 part 2
       
    19 marks=$(( 0 ))
       
    20 
       
    21 # compilation tests
       
    22 
       
    23 function scala_compile {
       
    24     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
       
    25 }
       
    26 
       
    27 # functional tests
       
    28 
       
    29 function scala_assert {
       
    30     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    31 }
       
    32 
       
    33 
       
    34 # purity test
       
    35 
       
    36 function scala_vars {
       
    37    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    38 }
       
    39 
       
    40 
       
    41 
       
    42 # var, return, ListBuffer test
       
    43 #
       
    44 echo "bfc.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    45 
       
    46 if (scala_vars bfc.scala)
       
    47 then
       
    48   echo "  --> FAIL (make triple-sure your program conforms to the required format)" | tee -a $out
       
    49   tsts0=$(( 1 ))
       
    50 else
       
    51   echo "  --> success" | tee -a $out
       
    52   tsts0=$(( 0 )) 
       
    53 fi
       
    54 
       
    55 
       
    56 # compilation test
       
    57 if  [ $tsts0 -eq 0 ]
       
    58 then    
       
    59   echo "bfc.scala runs?" | tee -a $out
       
    60 
       
    61   if (scala_compile bfc.scala)
       
    62   then
       
    63     echo "  --> success" | tee -a $out
       
    64     tsts1=$(( 0 ))
       
    65   else
       
    66     echo "  --> SCALA DID NOT RUN BFC.SCALA\n" | tee -a $out
       
    67     tsts1=$(( 1 )) 
       
    68   fi
       
    69 else
       
    70   tsts1=$(( 1 ))     
       
    71 fi
       
    72 
       
    73 
       
    74 ### bfc5 test
       
    75 
       
    76 if [ $tsts1 -eq 0 ]
       
    77 then
       
    78   echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out
       
    79   echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out  
       
    80   echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
    81   echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out
       
    82   echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
    83   echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
    84   echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
    85   echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
    86   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
    87   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
    88   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
    89   echo -e " run2(hello, Map()) == " | tee -a $out
       
    90   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
    91   
       
    92   if (scala_assert "bfc.scala" "bf_test5.scala")
       
    93   then
       
    94       echo "  --> success" | tee -a $out
       
    95       marks=$(( marks + 1 ))
       
    96   else
       
    97     echo "  --> \n ONE TEST FAILED\n" | tee -a $out
       
    98   fi
       
    99 fi
       
   100 
       
   101 
       
   102 ### bfc6 test
       
   103 
       
   104 if [ $tsts1 -eq 0 ]
       
   105 then
       
   106   echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out
       
   107   echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out  
       
   108   echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   109   echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   110   echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   111   echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   112   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   113   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   114   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   115   echo -e " run3(hello, Map()) == " | tee -a $out
       
   116   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   117   
       
   118   if (scala_assert "bfc.scala" "bf_test6.scala")
       
   119   then
       
   120       echo "  --> success" | tee -a $out
       
   121       marks=$(( marks + 1 ))
       
   122   else
       
   123       echo "  --> \n ONE TEST FAILED\n" | tee -a $out
       
   124   fi
       
   125 fi
       
   126 
       
   127 ### bfc7 test
       
   128 
       
   129 if [ $tsts1 -eq 0 ]
       
   130 then
       
   131   echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out
       
   132   echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out
       
   133   echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   134   echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   135   echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   136   echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   137   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   138   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   139   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   140   echo -e " run4(hello, Map()) == " | tee -a $out
       
   141   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   142   
       
   143   if (scala_assert "bfc.scala" "bf_test7.scala")
       
   144   then
       
   145       echo "  --> success" | tee -a $out
       
   146       marks=$(( marks + 2 ))
       
   147   else
       
   148       echo "  --> \n ONE TEST FAILED\n" | tee -a $out
       
   149   fi
       
   150 fi
       
   151 
       
   152 
       
   153 ## final marks
       
   154 echo "Overall mark for CW 10, Part 2" | tee -a $out
       
   155 echo "$marks" | tee -a $out
       
   156