marking4/re_test.sh
changeset 245 975d34506e88
parent 227 b5f3e814a710
child 246 178438912e5f
equal deleted inserted replaced
244:a359976a6f3e 245:975d34506e88
     7 
     7 
     8 echo "" > $out
     8 echo "" > $out
     9 
     9 
    10 
    10 
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
    12 echo "for assignment 8 Part 1.  Please note all marks are provisional until" >> $out
    12 echo "for assignment 9 Part 1.  Please note all marks are provisional until" >> $out
    13 echo "ratified by the assessment board -- this is not an official" >> $out
    13 echo "ratified by the assessment board -- this is not an official" >> $out
    14 echo "results transcript." >> $out
    14 echo "results transcript." >> $out
    15 echo "" >> $out
    15 echo "" >> $out
    16 
    16 
    17 # marks for CW8 part 1
    17 # marks for CW9 part 1
    18 marks=$(( 0 ))
    18 marks=$(( 0 ))
    19 
    19 
    20 # compilation tests
    20 # compilation tests
    21 
    21 
    22 function scala_compile {
    22 function scala_compile {
    23     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
    23     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
    24 }
    24 }
    25 
    25 
    26 # functional tests
    26 # functional tests
    27 
    27 
    28 function scala_assert {
    28 function scala_assert {
    29     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    29     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") # 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 function scala_assert_long {
       
    33     (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    30 }
    34 }
    31 
    35 
    32 # purity test
    36 # purity test
    33 
    37 
    34 function scala_vars {
    38 function scala_vars {
    65   fi
    69   fi
    66 else
    70 else
    67   tsts1=$(( 1 ))     
    71   tsts1=$(( 1 ))     
    68 fi
    72 fi
    69 
    73 
    70 
    74 ### re1 test
    71 
    75 
    72 if [ $tsts1 -eq 0 ]
    76 if [ $tsts1 -eq 0 ]
    73 then
    77 then
    74   echo " nullable(ZERO) == false" | tee -a $out
    78   echo " nullable(ZERO) == false" | tee -a $out
    75   echo " nullable(ONE) == true" | tee -a $out
    79   echo " nullable(ONE) == true" | tee -a $out
    78   echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out
    82   echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out
    79   echo " nullable(ONE ~  ONE) == true" | tee -a $out
    83   echo " nullable(ONE ~  ONE) == true" | tee -a $out
    80   echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
    84   echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
    81   echo " nullable(STAR(ZERO)) == true" | tee -a $out
    85   echo " nullable(STAR(ZERO)) == true" | tee -a $out
    82   
    86   
    83   if (scala_assert "re.scala" "re1a_test.scala")
    87   if (scala_assert "re.scala" "re_test1.scala")
    84   then
    88   then
    85       echo "  --> success" | tee -a $out
    89       echo "  --> success" | tee -a $out
    86       marks=$(( marks + 1 ))
    90       marks=$(( marks + 1 ))
    87   else
    91   else
    88       echo "  --> test failed" | tee -a $out
    92       echo "  --> test failed" | tee -a $out
    89   fi
    93   fi
    90 fi
    94 fi
    91 
    95 
    92 
    96 ### re2 test
    93 
    97 
    94 if [ $tsts1 -eq 0 ]
    98 if [ $tsts1 -eq 0 ]
    95 then
    99 then
    96   echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
   100   echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
    97   echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
   101   echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
    98   echo " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
   102   echo " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
    99   echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
   103   echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
   100   echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
   104   echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
   101   
   105   echo "" | tee -a $out
   102   if (scala_assert "re.scala" "re1b_test.scala")
   106   echo " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out
   103   then
   107   echo " assert(der('a', r0) == (ONE ~ \"b\") ~ \"c\")" | tee -a $out
   104       echo "  --> success" | tee -a $out
   108   echo " assert(der('b', r0) == (ZERO ~ \"b\") ~ \"c\")" | tee -a $out
   105       marks=$(( marks + 1 ))
   109   echo " assert(der('c', r0) == (ZERO ~ \"b\") ~ \"c\")" | tee -a $out
   106   else
   110   echo "" | tee -a $out
   107       echo "  --> test failed" | tee -a $out
   111   echo " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out
   108   fi
   112   echo " assert(der('a', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\")" | tee -a $out
   109 fi
   113   echo " assert(der('b', r1) == ((ZERO ~ \"b\") | ONE) ~ \"c\")" | tee -a $out
   110 
   114   echo " assert(der('c', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\")" | tee -a $out
   111 
   115   echo "" | tee -a $out
       
   116   echo " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out
       
   117   echo " assert(der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO))" | tee -a $out
       
   118   echo " assert(der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO))" | tee -a $out
       
   119   echo " assert(der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE))" | tee -a $out
       
   120 
       
   121   if (scala_assert "re.scala" "re_test2.scala")
       
   122   then
       
   123       echo "  --> success" | tee -a $out
       
   124       marks=$(( marks + 1 ))
       
   125   else
       
   126       echo "  --> test failed" | tee -a $out
       
   127   fi
       
   128 fi
       
   129 
       
   130 ### re3 test
   112 
   131 
   113 if [ $tsts1 -eq 0 ]
   132 if [ $tsts1 -eq 0 ]
   114 then
   133 then
   115   echo " simp(ZERO | ONE) == ONE" | tee -a $out
   134   echo " simp(ZERO | ONE) == ONE" | tee -a $out
   116   echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
   135   echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
   117   echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
   136   echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
       
   137   echo " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
       
   138   echo " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
   118   echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
   139   echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
   119   echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
   140   echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
   120   echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
   141   echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
   121   echo " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
   142   echo " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
   122   echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
   143   echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
   123   echo " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
   144   echo " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
   124   echo "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
   145   echo "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
   125   echo " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
   146   echo " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
   126   echo " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
   147   echo " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
   127   echo " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
   148   echo " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
   128   echo " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
   149   echo " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" tee -a $out
   129   echo "    the Iterator produces the rexp" | tee -a $out
   150   
   130   echo "" | tee -a $out
   151   if (scala_assert "re.scala" "re_test3.scala")
   131   echo "      SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
   152   then
   132   echo "" | tee -a $out
   153       echo "  --> success" | tee -a $out
   133   echo "    where SEQ is nested 50 times." | tee -a $out
   154       marks=$(( marks + 1 ))
   134   if (scala_assert "re.scala" "re1c_test.scala")
   155   else
   135   then
   156       echo "  --> test failed" | tee -a $out
   136       echo "  --> success" | tee -a $out
   157   fi
   137       marks=$(( marks + 2 ))
   158 fi
   138   else
   159 
   139       echo "  --> test failed" | tee -a $out
   160 ### re4 test
   140   fi
       
   141 fi
       
   142 
       
   143 
   161 
   144 if [ $tsts1 -eq 0 ]
   162 if [ $tsts1 -eq 0 ]
   145 then
   163 then
   146   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
   164   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
   147   echo " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
   165   echo " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
   151   echo " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
   169   echo " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
   152   echo " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
   170   echo " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
   153   echo " matcher(EVIL, \"b\") == true" | tee -a $out
   171   echo " matcher(EVIL, \"b\") == true" | tee -a $out
   154   echo " matcher(EVIL, \"bb\") == false" | tee -a $out
   172   echo " matcher(EVIL, \"bb\") == false" | tee -a $out
   155   echo " matcher(\"abc\", \"abc\") == true" | tee -a $out
   173   echo " matcher(\"abc\", \"abc\") == true" | tee -a $out
       
   174   echo " matcher(\"abc\", \"ab\") == true" | tee -a $out
   156   echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
   175   echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
   157   echo " matcher(ONE, \"\") == true" | tee -a $out
   176   echo " matcher(ONE, \"\") == true" | tee -a $out
   158   echo " matcher(ZERO, \"\") == false" | tee -a $out
   177   echo " matcher(ZERO, \"\") == false" | tee -a $out
   159   echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
   178   echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
   160   echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
   179   echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
   161   
   180   
   162   if (scala_assert "re.scala" "re1d_test.scala")
   181   if (scala_assert "re.scala" "re_test4.scala")
   163   then
   182   then
   164       echo "  --> success" | tee -a $out
   183       echo "  --> success" | tee -a $out
   165       marks=$(( marks + 1 ))
   184       marks=$(( marks + 1 ))
   166   else
   185   else
   167       echo "  --> test failed" | tee -a $out
   186       echo "  --> test failed" | tee -a $out
   168   fi
   187   fi
   169 fi
   188 fi
       
   189 
       
   190 ### re5 test
   170 
   191 
   171 
   192 
   172 if [ $tsts1 -eq 0 ]
   193 if [ $tsts1 -eq 0 ]
   173 then
   194 then
   174   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out  
   195   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out  
   175   echo " size(der('a', der('a', EVIL))) == 28" | tee -a $out
   196   echo " size(der('a', der('a', EVIL))) == 28" | tee -a $out
   176   echo " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out
   197   echo " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out
   177   echo " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out
   198   echo " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out
   178   echo " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
   199   echo " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
   179   
   200   
   180   if (scala_assert "re.scala" "re1e_test.scala")
   201   if (scala_assert "re.scala" "re_test5.scala")
       
   202   then
       
   203       echo "  --> success" | tee -a $out
       
   204       marks=$(( marks + 1 ))
       
   205   else
       
   206       echo "  --> test failed" | tee -a $out
       
   207   fi
       
   208 fi
       
   209 
       
   210 ### re6 'power' test
       
   211 
       
   212 
       
   213 
       
   214 if [ $tsts1 -eq 0 ]
       
   215 then
       
   216   echo " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
       
   217   echo "    ...the Iterator produces the rexp" | tee -a $out
       
   218   echo "" | tee -a $out
       
   219   echo "      SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
       
   220   echo "" | tee -a $out
       
   221   echo "    where SEQ is nested 50 times." | tee -a $out  
       
   222   echo "" | tee -a $out
       
   223   echo " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out
       
   224   echo "    ... the Iterator produces a rexp of size 2097151" | tee -a $out
       
   225   echo "" | tee -a $out
       
   226   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
       
   227   echo " matcher(EVIL, \"a\" * 1000000 ++ \"b\") == true" | tee -a $out
       
   228   echo " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out
       
   229 
       
   230   
       
   231   if (time scala_assert_long "re.scala" "re_test6.scala")
   181   then
   232   then
   182       echo "  --> success" | tee -a $out
   233       echo "  --> success" | tee -a $out
   183       marks=$(( marks + 1 ))
   234       marks=$(( marks + 1 ))
   184   else
   235   else
   185       echo "  --> test failed" | tee -a $out
   236       echo "  --> test failed" | tee -a $out
   186   fi
   237   fi
   187 fi
   238 fi
   188 
   239 
   189 
   240 
   190 ## final marks
   241 ## final marks
   191 echo "Overall mark for CW 8, Part 1" | tee -a $out
   242 echo "Overall mark for CW 9, Part 1" | tee -a $out
   192 echo "$marks" | tee -a $out
   243 echo "$marks" | tee -a $out
   193 
   244 
   194 
   245