marking/mark03a
changeset 281 87b9e3e2c1a7
parent 280 a057dc4457fc
child 282 ec9773fe1dc0
equal deleted inserted replaced
280:a057dc4457fc 281:87b9e3e2c1a7
     1 #!/bin/bash
       
     2 set -e
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo "" > $out
       
     7 
       
     8 echo "Below is the feedback and provisional mark for your submission" >> $out
       
     9 echo "for CW 8, Part 1.  Please note all marks are provisional until" >> $out
       
    10 echo "ratified by the assessment board -- this is not an official" >> $out
       
    11 echo "results transcript." >> $out
       
    12 echo "" >> $out
       
    13 
       
    14 function scala_vars {
       
    15    (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
       
    16 }
       
    17 
       
    18 
       
    19 # compilation tests
       
    20 
       
    21 function scala_compile {
       
    22   (ulimit -t 1 ; scala "$1" 1> $out 2> $out) 
       
    23 }
       
    24 
       
    25 
       
    26 # functional tests
       
    27 
       
    28 function scala_assert {
       
    29   (ulimit - t 1; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 
       
    33 # marks for CW
       
    34 marks=$(( 0 ))
       
    35 
       
    36 
       
    37 # var, return, ListBuffer test
       
    38 #
       
    39 echo "re.scala does not contain vars, returns etc?" | tee -a $out
       
    40 
       
    41 if (scala_vars re.scala)
       
    42 then
       
    43   echo "  --> fail" | tee -a $out
       
    44   tsts0=$(( 1 ))
       
    45 else
       
    46   echo "  --> yes" | tee -a $out
       
    47   tsts0=$(( 0 )) 
       
    48 fi
       
    49 
       
    50 
       
    51 # compilation test
       
    52 if  [ $tsts0 -eq 0 ]
       
    53 then    
       
    54   echo "re.scala runs?" | tee -a $out
       
    55 
       
    56   if (scala_compile re.scala.bak)
       
    57   then
       
    58     echo "  --> yes" | tee -a $out
       
    59     tsts1=$(( 0 ))
       
    60   else
       
    61     echo "  --> scala re.scala did not run successfully" | tee -a $out
       
    62     tsts1=$(( 1 )) 
       
    63   fi
       
    64 else
       
    65   tsts1=$(( 1 ))     
       
    66 fi
       
    67 
       
    68 if [ $tsts1 -eq 0 ]
       
    69 then
       
    70   echo " nullable(ZERO) == false" | tee -a $out
       
    71   echo " nullable(ONE) == true" | tee -a $out
       
    72   echo " nullable(CHAR('a')) == false" | tee -a $out
       
    73   echo " nullable(ZERO | ONE) == true" | tee -a $out
       
    74   echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out
       
    75   echo " nullable(ONE ~  ONE) == true" | tee -a $out
       
    76   echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
       
    77   echo " nullable(STAR(ZERO)) == true" | tee -a $out
       
    78   
       
    79   if (scala_assert "re.scala.bak" "../../../marking/re1a_test.scala")
       
    80   then
       
    81     echo "  --> success" | tee -a $out
       
    82     marks=$(( marks + 1 ))
       
    83   else
       
    84     echo "  --> test failed" | tee -a $out
       
    85   fi
       
    86 fi
       
    87 
       
    88 if [ $tsts1 -eq 0 ]
       
    89 then
       
    90   echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
       
    91   echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
       
    92   echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
       
    93   echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
       
    94   
       
    95   if (scala_assert "re.scala.bak" "../../../marking/re1b_test.scala")
       
    96   then
       
    97     echo "  --> success" | tee -a $out
       
    98     marks=$(( marks + 1 ))
       
    99   else
       
   100     echo "  --> test failed" | tee -a $out
       
   101   fi
       
   102 fi
       
   103 
       
   104 if [ $tsts1 -eq 0 ]
       
   105 then
       
   106   echo " simp(ZERO | ONE) == ONE" | tee -a $out
       
   107   echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
       
   108   echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
       
   109   echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
       
   110   echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
       
   111   echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
       
   112   echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
       
   113   
       
   114   if (scala_assert "re.scala.bak" "../../../marking/re1c_test.scala")
       
   115   then
       
   116     echo "  --> success" | tee -a $out
       
   117     marks=$(( marks + 1 ))
       
   118   else
       
   119     echo "  --> test failed" | tee -a $out
       
   120   fi
       
   121 fi
       
   122 
       
   123 if [ $tsts1 -eq 0 ]
       
   124 then
       
   125   echo " EVIL = (a*)* b" | tee -a $out
       
   126   echo " ders(List.fill(5)('a'),EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
       
   127   echo " ders(List('b'),EVIL) == ONE" | tee -a $out
       
   128   echo " ders(List('b','b'),EVIL) == ZERO" | tee -a $out
       
   129   echo " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out
       
   130   echo " matcher(EVIL, \"b\") == true" | tee -a $out
       
   131   echo " matcher(EVIL, \"bb\") == false" | tee -a $out
       
   132   echo " matcher(\"abc\", \"abc\") == true" | tee -a $out
       
   133   echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
       
   134   echo " matcher(ONE, \"\") == true" | tee -a $out
       
   135   echo " matcher(ZERO, \"\") == false" | tee -a $out
       
   136   echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
       
   137   echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
       
   138   
       
   139   if (scala_assert "re.scala.bak" "../../../marking/re1d_test.scala")
       
   140   then
       
   141     echo "  --> success" | tee -a $out
       
   142     marks=$(( marks + 1 ))
       
   143   else
       
   144     echo "  --> test failed" | tee -a $out
       
   145   fi
       
   146 fi
       
   147 
       
   148 if [ $tsts1 -eq 0 ]
       
   149 then
       
   150   echo " replace(\"aa\".% | \"bb\", \"aabbbaaaaaaabaaaaabbaaaabb\" , \"c\") == \"ccbcabcaccc\"" | tee -a $out
       
   151   echo " replace(\"aa\".% | \"bb\", \"abba\" , \"\") == \"aa\"" | tee -a $out
       
   152   
       
   153   if (scala_assert "re.scala.bak" "../../../marking/re1e_test.scala")
       
   154   then
       
   155     echo "  --> success" | tee -a $out
       
   156     marks=$(( marks + 2 ))
       
   157   else
       
   158     echo "  --> test failed" | tee -a $out
       
   159   fi
       
   160 fi
       
   161 
       
   162 
       
   163 ## final marks
       
   164 echo "Overall mark for CW 8, Part 1" | tee -a $out
       
   165 echo "$marks" | tee -a $out