main_marking5/bf_test.sh
changeset 392 97ecdc8cb61b
child 393 7a9cc14d0912
equal deleted inserted replaced
391:0930e4555b60 392:97ecdc8cb61b
       
     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 echo -e `date` >> $out
       
    12 echo -e  "" >> $out
       
    13 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    14 echo -e "for Part 5 (Scala).  Please note all marks are provisional until" >> $out
       
    15 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    16 echo -e "results transcript." >> $out
       
    17 echo -e "" >> $out
       
    18 
       
    19 # marks for CW10 part 1
       
    20 marks=$(( 0 ))
       
    21 
       
    22 # compilation tests
       
    23 
       
    24 function scala_compile {
       
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    26 }
       
    27 
       
    28 # functional tests
       
    29 
       
    30 function scala_assert {
       
    31   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    32 }
       
    33 
       
    34 function scala_assert_thirty {
       
    35   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
       
    36 }
       
    37 
       
    38 # purity test
       
    39 
       
    40 function scala_vars {
       
    41    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    42 }
       
    43 
       
    44 
       
    45 
       
    46 echo -e "" >> $out
       
    47 echo -e "Below is the feedback for your submission of bf.scala" >> $out
       
    48 echo -e "" >> $out
       
    49 
       
    50 # compilation test
       
    51 echo -e "bf.scala runs?" | tee -a $out
       
    52 
       
    53 if (scala_compile bf.scala)
       
    54 then
       
    55     echo -e "  --> success" | tee -a $out
       
    56     tsts=$(( 0 ))
       
    57 else
       
    58     echo -e "  --> SCALA DID NOT RUN bf.scala\n" | tee -a $out
       
    59     tsts=$(( 1 )) 
       
    60 fi
       
    61 
       
    62 
       
    63 # var, return, ListBuffer test
       
    64 #
       
    65 if  [ $tsts -eq 0 ]
       
    66 then   
       
    67     echo -e "bf.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    68 
       
    69     if (scala_vars bf.scala)   
       
    70     then
       
    71 	echo -e "  --> TEST FAILED\n" | tee -a $out
       
    72 	tsts=$(( 1 ))
       
    73     else
       
    74 	echo -e "  --> success" | tee -a $out
       
    75 	tsts=$(( 0 )) 
       
    76     fi
       
    77 else
       
    78     tsts=$(( 1 ))  
       
    79 fi    
       
    80 
       
    81 
       
    82 
       
    83 ### bf1 test
       
    84 
       
    85 if [ $tsts -eq 0 ]
       
    86 then
       
    87   echo -e " load_bff(\"benchmark.bf\").length == 188" | tee -a $out
       
    88   echo -e " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
       
    89    
       
    90   if (scala_assert "bf.scala" "bf_test1.scala")
       
    91   then
       
    92       echo -e "  --> success" | tee -a $out
       
    93       marks=$(( marks + 1 ))
       
    94   else
       
    95       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
    96   fi
       
    97 fi
       
    98 
       
    99 
       
   100 ### bf2 test
       
   101 
       
   102 if [ $tsts -eq 0 ]
       
   103 then
       
   104   echo -e " sread(Map(), 2) == 0" | tee -a $out
       
   105   echo -e " sread(Map(2 -> 1), 2) == 1" | tee -a $out  
       
   106   echo -e " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out
       
   107   echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
       
   108   
       
   109   if (scala_assert "bf.scala" "bf_test2.scala")
       
   110   then
       
   111       echo -e "  --> success" | tee -a $out
       
   112       marks=$(( marks + 1 ))
       
   113   else
       
   114       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   115   fi
       
   116 fi
       
   117 
       
   118 ### bf3 test
       
   119 
       
   120 if [ $tsts -eq 0 ]
       
   121 then
       
   122     echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" | tee -a $out
       
   123     echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   124     echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   125     echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" | tee -a $out
       
   126     echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" | tee -a $out
       
   127     echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" | tee -a $out
       
   128     echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" | tee -a $out
       
   129     echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
       
   130   
       
   131   if (scala_assert "bf.scala" "bf_test3.scala")
       
   132   then
       
   133       echo -e "  --> success" | tee -a $out
       
   134       marks=$(( marks + 2 ))
       
   135   else
       
   136       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   137   fi
       
   138 fi
       
   139 
       
   140 
       
   141 
       
   142 if [ $tsts -eq 0 ]
       
   143 then
       
   144   echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   145   echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   146   echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   147   echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000)" | tee -a $out
       
   148   echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" | tee -a $out
       
   149   
       
   150   echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   151   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   152   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   153   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   154   echo -e " run(hello, Map()) == " | tee -a $out
       
   155   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   156   
       
   157   if (scala_assert "bf.scala" "bf_test4.scala")
       
   158   then
       
   159       echo -e "  --> success" | tee -a $out
       
   160       marks=$(( marks + 1 ))
       
   161   else
       
   162       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   163   fi
       
   164 fi
       
   165 
       
   166 sleep 10
       
   167 
       
   168 if [ $tsts -eq 0 ]
       
   169 then
       
   170   echo -e " val bench_small = \"\"\">+[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++" | tee -a $out
       
   171   echo -e "  [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++" | tee -a $out
       
   172   echo -e "  ++++++++[>++++++++++[>++++++++++[>++++++++++[>+" | tee -a $out
       
   173   echo -e "  +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.\"\"\"" | tee -a $out
       
   174   echo -e " run(bench_small, Map()) == " | tee -a $out
       
   175   echo -e "       Map(0 -> 10, 5 -> 0, 1 -> 0, 6 -> 0, 2 -> 0, 7 -> 0, 3 -> 0, 4 -> 0)" | tee -a $out
       
   176   START=$(date +%s)
       
   177   
       
   178   if (scala_assert_thirty "bf.scala" "bf_test4b.scala")
       
   179   then
       
   180       END=$(date +%s)
       
   181       DIFF=$(( $END - $START ))
       
   182       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
       
   183       echo -e "  --> success" | tee -a $out
       
   184       marks=$(( marks + 1 ))
       
   185   else
       
   186       END=$(date +%s)
       
   187       DIFF=$(( $END - $START ))
       
   188       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
       
   189       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   190   fi
       
   191 fi
       
   192 
       
   193 sleep 10
       
   194 
       
   195 echo -e "" >> $out
       
   196 echo -e "Below is the feedback for your submission of bfc.scala" >> $out
       
   197 echo -e "" >> $out
       
   198 
       
   199 
       
   200 # compilation test
       
   201 echo "bfc.scala runs?" | tee -a $out
       
   202 
       
   203 if (scala_compile bfc.scala)
       
   204 then
       
   205     echo -e "  --> success" | tee -a $out
       
   206     tsts=$(( 0 ))
       
   207 else
       
   208     echo -e "  --> SCALA DID NOT RUN bfc.scala\n" | tee -a $out
       
   209     tsts=$(( 1 )) 
       
   210 fi
       
   211 
       
   212 # var, return, ListBuffer test
       
   213 #
       
   214 
       
   215 if [ $tsts -eq 0 ]
       
   216 then 
       
   217     echo "bfc.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
   218 
       
   219     if (scala_vars bfc.scala)
       
   220     then
       
   221 	echo -e "  --> TEST FAILED\n" | tee -a $out
       
   222 	tsts=$(( 1 ))
       
   223     else
       
   224 	echo -e "  --> success" | tee -a $out
       
   225 	tsts=$(( 0 )) 
       
   226     fi
       
   227 else
       
   228   tsts=$(( 1 ))     
       
   229 fi
       
   230 
       
   231 
       
   232 ### bfc5 test
       
   233 
       
   234 if [ $tsts -eq 0 ]
       
   235 then
       
   236   echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out
       
   237   echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out  
       
   238   echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   239   echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out
       
   240   echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   241   echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   242   echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   243   echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   244   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   245   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   246   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   247   echo -e " run2(hello, Map()) == " | tee -a $out
       
   248   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   249   
       
   250   if (scala_assert "bfc.scala" "bf_test5.scala")
       
   251   then
       
   252       echo -e "  --> success" | tee -a $out
       
   253       marks=$(( marks + 1 ))
       
   254   else
       
   255       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   256   fi
       
   257 fi
       
   258 
       
   259 
       
   260 ### bfc6 test
       
   261 
       
   262 if [ $tsts -eq 0 ]
       
   263 then
       
   264   echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out
       
   265   echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out  
       
   266   echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   267   echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   268   echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   269   echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   270   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   271   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   272   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   273   echo -e " run3(hello, Map()) == " | tee -a $out
       
   274   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   275   
       
   276   if (scala_assert "bfc.scala" "bf_test6.scala")
       
   277   then
       
   278       echo -e "  --> success" | tee -a $out
       
   279       marks=$(( marks + 1 ))
       
   280   else
       
   281       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   282   fi
       
   283 fi
       
   284 
       
   285 ### bfc7 test
       
   286 
       
   287 if [ $tsts -eq 0 ]
       
   288 then
       
   289   echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out
       
   290   echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out
       
   291   echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
       
   292   echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
       
   293   echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
       
   294   echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
       
   295   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
       
   296   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
       
   297   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
       
   298   echo -e " run4(hello, Map()) == " | tee -a $out
       
   299   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
       
   300   
       
   301   if (scala_assert "bfc.scala" "bf_test7.scala")
       
   302   then
       
   303       echo -e "  --> success (+ 2%)" | tee -a $out
       
   304       marks=$(( marks + 2 ))
       
   305   else
       
   306       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   307   fi
       
   308 fi
       
   309 
       
   310 
       
   311 ## final marks
       
   312 echo -e "Overall mark for Part 5 (Scala)" | tee -a $out
       
   313 echo -e "$marks" | tee -a $out
       
   314 
       
   315 sleep 10