marking5/bf_test.sh
changeset 486 9c03b5e89a2a
parent 485 19b75e899d37
child 487 efad9725dfd8
equal deleted inserted replaced
485:19b75e899d37 486:9c03b5e89a2a
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo -e "" > $out
       
    10 
       
    11 
       
    12 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo -e "for assignment 10.  Please note all marks are provisional until" >> $out
       
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    15 echo -e "results transcript." >> $out
       
    16 echo -e "" >> $out
       
    17 
       
    18 # marks for CW10 part 1
       
    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 -e "bf.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    45 
       
    46 if (scala_vars bf.scala)
       
    47 then
       
    48   echo -e "  --> TEST FAILED\n" | tee -a $out
       
    49   tsts0=$(( 1 ))
       
    50 else
       
    51   echo -e "  --> success" | tee -a $out
       
    52   tsts0=$(( 0 )) 
       
    53 fi
       
    54 
       
    55 
       
    56 # compilation test
       
    57 if  [ $tsts0 -eq 0 ]
       
    58 then    
       
    59   echo -e "bf.scala runs?" | tee -a $out
       
    60 
       
    61   if (scala_compile bf.scala)
       
    62   then
       
    63     echo -e "  --> success" | tee -a $out
       
    64     tsts1=$(( 0 ))
       
    65   else
       
    66     echo -e "  --> SCALA DID NOT RUN bf.scala\n" | tee -a $out
       
    67     tsts1=$(( 1 )) 
       
    68   fi
       
    69 else
       
    70   tsts1=$(( 1 ))     
       
    71 fi
       
    72 
       
    73 
       
    74 ### bf1 test
       
    75 
       
    76 if [ $tsts1 -eq 0 ]
       
    77 then
       
    78   echo -e " load_bff(\"benchmark.bf\").length == 188" | tee -a $out
       
    79   echo -e " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
       
    80    
       
    81   if (scala_assert "bf.scala" "bf_test1.scala")
       
    82   then
       
    83       echo -e "  --> success" | tee -a $out
       
    84       marks=$(( marks + 1 ))
       
    85   else
       
    86       echo -e "  --> TEST FAILED\n" | tee -a $out
       
    87   fi
       
    88 fi
       
    89 
       
    90 
       
    91 ### bf2 test
       
    92 
       
    93 if [ $tsts1 -eq 0 ]
       
    94 then
       
    95   echo -e " sread(Map(), 2) == 0" | tee -a $out
       
    96   echo -e " sread(Map(2 -> 1), 2) == 1" | tee -a $out  
       
    97   echo -e " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out
       
    98   echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
       
    99   
       
   100   if (scala_assert "bf.scala" "bf_test2.scala")
       
   101   then
       
   102       echo -e "  --> success" | tee -a $out
       
   103       marks=$(( marks + 1 ))
       
   104   else
       
   105       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   106   fi
       
   107 fi
       
   108 
       
   109 ### bf3 test
       
   110 
       
   111 if [ $tsts1 -eq 0 ]
       
   112 then
       
   113     echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" | tee -a $out
       
   114     echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   115     echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   116     echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" | tee -a $out
       
   117     echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" | tee -a $out
       
   118     echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" | tee -a $out
       
   119     echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" | tee -a $out
       
   120     echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
       
   121   
       
   122   if (scala_assert "bf.scala" "bf_test3.scala")
       
   123   then
       
   124       echo -e "  --> success" | tee -a $out
       
   125       marks=$(( marks + 2 ))
       
   126   else
       
   127       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   128   fi
       
   129 fi
       
   130 
       
   131 
       
   132 
       
   133 if [ $tsts1 -eq 0 ]
       
   134 then
       
   135   echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   136   echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   137   echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   138   echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   139   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   140   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   141   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   142   echo -e " run(hello, Map()) == " | tee -a $out
       
   143   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   144   
       
   145   if (scala_assert "bf.scala" "bf_test4.scala")
       
   146   then
       
   147       echo -e "  --> success" | tee -a $out
       
   148       marks=$(( marks + 2 ))
       
   149   else
       
   150       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   151   fi
       
   152 fi
       
   153 
       
   154 
       
   155 # var, return, ListBuffer test
       
   156 #
       
   157 echo "bfc.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
   158 
       
   159 if (scala_vars bfc.scala)
       
   160 then
       
   161   echo -e "  --> TEST FAILED\n" | tee -a $out
       
   162   tsts0=$(( 1 ))
       
   163 else
       
   164   echo -e "  --> success" | tee -a $out
       
   165   tsts0=$(( 0 )) 
       
   166 fi
       
   167 
       
   168 
       
   169 # compilation test
       
   170 if  [ $tsts0 -eq 0 ]
       
   171 then    
       
   172   echo "bfc.scala runs?" | tee -a $out
       
   173 
       
   174   if (scala_compile bfc.scala)
       
   175   then
       
   176     echo -e "  --> success" | tee -a $out
       
   177     tsts1=$(( 0 ))
       
   178   else
       
   179     echo -e "  --> SCALA DID NOT RUN bfc.scala\n" | tee -a $out
       
   180     tsts1=$(( 1 )) 
       
   181   fi
       
   182 else
       
   183   tsts1=$(( 1 ))     
       
   184 fi
       
   185 
       
   186 
       
   187 ### bfc5 test
       
   188 
       
   189 if [ $tsts1 -eq 0 ]
       
   190 then
       
   191   echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out
       
   192   echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out  
       
   193   echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   194   echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out
       
   195   echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   196   echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   197   echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   198   echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   199   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   200   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   201   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   202   echo -e " run2(hello, Map()) == " | tee -a $out
       
   203   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   204   
       
   205   if (scala_assert "bfc.scala" "bf_test5.scala")
       
   206   then
       
   207       echo -e "  --> success" | tee -a $out
       
   208       marks=$(( marks + 1 ))
       
   209   else
       
   210       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   211   fi
       
   212 fi
       
   213 
       
   214 
       
   215 ### bfc6 test
       
   216 
       
   217 if [ $tsts1 -eq 0 ]
       
   218 then
       
   219   echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out
       
   220   echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out  
       
   221   echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   222   echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   223   echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   224   echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   225   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   226   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   227   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   228   echo -e " run3(hello, Map()) == " | tee -a $out
       
   229   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   230   
       
   231   if (scala_assert "bfc.scala" "bf_test6.scala")
       
   232   then
       
   233       echo -e "  --> success" | tee -a $out
       
   234       marks=$(( marks + 1 ))
       
   235   else
       
   236       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   237   fi
       
   238 fi
       
   239 
       
   240 ### bfc7 test
       
   241 
       
   242 if [ $tsts1 -eq 0 ]
       
   243 then
       
   244   echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out
       
   245   echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out
       
   246   echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   247   echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   248   echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   249   echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   250   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   251   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   252   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   253   echo -e " run4(hello, Map()) == " | tee -a $out
       
   254   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   255   
       
   256   if (scala_assert "bfc.scala" "bf_test7.scala")
       
   257   then
       
   258       echo -e "  --> success" | tee -a $out
       
   259       marks=$(( marks + 2 ))
       
   260   else
       
   261       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   262   fi
       
   263 fi
       
   264 
       
   265 
       
   266 ## final marks
       
   267 echo -e "Overall mark for CW 10" | tee -a $out
       
   268 echo -e "$marks" | tee -a $out
       
   269