marking5/bf_test.sh
changeset 253 ec7a12806c3f
child 286 5c57c407e27b
equal deleted inserted replaced
252:a9d84442fb65 253:ec7a12806c3f
       
     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 1.  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 1
       
    19 marks=$(( 0 ))
       
    20 
       
    21 # compilation tests
       
    22 
       
    23 function scala_compile {
       
    24     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$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 -nc -i "$1" "$2" -e "" 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 "bf.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    45 
       
    46 if (scala_vars bf.scala)
       
    47 then
       
    48   echo "  --> test failed" | 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 "bf.scala runs?" | tee -a $out
       
    60 
       
    61   if (scala_compile bf.scala)
       
    62   then
       
    63     echo "  --> success" | tee -a $out
       
    64     tsts1=$(( 0 ))
       
    65   else
       
    66     echo "  --> scala bf.scala did not run successfully" | 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 " load_bff(\"benchmark.bf\").length == 188" | tee -a $out
       
    79   echo " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
       
    80    
       
    81   if (scala_assert "bf.scala" "bf_test1.scala")
       
    82   then
       
    83       echo "  --> success" | tee -a $out
       
    84       marks=$(( marks + 1 ))
       
    85   else
       
    86     echo "  --> test failed" | tee -a $out
       
    87   fi
       
    88 fi
       
    89 
       
    90 
       
    91 ### bf2 test
       
    92 
       
    93 if [ $tsts1 -eq 0 ]
       
    94 then
       
    95   echo " sread(Map(), 2) == 0" | tee -a $out
       
    96   echo " sread(Map(2 -> 1), 2) == 1" | tee -a $out  
       
    97   echo " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out
       
    98   echo " 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 "  --> success" | tee -a $out
       
   103       marks=$(( marks + 1 ))
       
   104   else
       
   105     echo "  --> test failed" | tee -a $out
       
   106   fi
       
   107 fi
       
   108 
       
   109 ### bf3 test
       
   110 
       
   111 if [ $tsts1 -eq 0 ]
       
   112 then
       
   113     echo " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" | tee -a $out
       
   114     echo " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   115     echo " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
       
   116     echo " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" | tee -a $out
       
   117     echo " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" | tee -a $out
       
   118     echo " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" | tee -a $out
       
   119     echo " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" | tee -a $out
       
   120     echo " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
       
   121   
       
   122   if (scala_assert "bf.scala" "bf_test3.scala")
       
   123   then
       
   124       echo "  --> success" | tee -a $out
       
   125       marks=$(( marks + 2 ))
       
   126   else
       
   127       echo "  --> test failed" | 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 "  --> success" | tee -a $out
       
   148       marks=$(( marks + 2 ))
       
   149   else
       
   150       echo "  --> test failed" | tee -a $out
       
   151   fi
       
   152 fi
       
   153 
       
   154 
       
   155 ## final marks
       
   156 echo "Overall mark for CW 10, Part 1" | tee -a $out
       
   157 echo "$marks" | tee -a $out
       
   158