main_marking3/re_test.sh
changeset 390 175a950470a9
child 424 daf561a83ba6
equal deleted inserted replaced
389:4113d4d8cf62 390:175a950470a9
       
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 out=${1:-output}
       
     7 
       
     8 echo -e "" > $out
       
     9 
       
    10 echo -e `date` >> $out
       
    11 echo -e  "" >> $out
       
    12 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo -e "for the Main Part 3 (Scala). 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 CW8
       
    19 marks=$(( 0 ))
       
    20 
       
    21 # compilation tests
       
    22 
       
    23 function scala_compile {
       
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    25 }
       
    26 
       
    27 # functional tests
       
    28 
       
    29 function scala_assert {
       
    30   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    31 }
       
    32 
       
    33 function scala_assert_thirty {
       
    34   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
       
    35 }
       
    36 
       
    37 # purity test
       
    38 
       
    39 function scala_vars {
       
    40    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    41 }
       
    42 
       
    43 echo -e "" >> $out
       
    44 echo -e  "Below is the feedback for your submission re.scala" >> $out
       
    45 echo -e  "" >> $out
       
    46 
       
    47 
       
    48 
       
    49 ### compilation test
       
    50 
       
    51 echo -e "re.scala runs?" | tee -a $out
       
    52 
       
    53 if (scala_compile re.scala)
       
    54 then
       
    55     echo -e "  --> success" | tee -a $out
       
    56     tsts=$(( 0 ))
       
    57 else
       
    58     echo -e "  --> SCALA DID NOT RUN re.scala" | tee -a $out
       
    59     tsts=$(( 1 )) 
       
    60 fi
       
    61 
       
    62 
       
    63 # var, return, ListBuffer test
       
    64 #
       
    65 
       
    66 if [ $tsts -eq 0 ]
       
    67 then 
       
    68     echo -e "re.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    69 
       
    70     if (scala_vars re.scala)
       
    71     then
       
    72 	echo -e  "  --> TEST FAILED\n" | tee -a $out
       
    73 	tsts=$(( 1 ))  
       
    74     else
       
    75 	echo -e "  --> success" | tee -a $out
       
    76 	tsts=$(( 0 )) 
       
    77     fi
       
    78 else
       
    79     tsts=$(( 1 ))  
       
    80 fi
       
    81 
       
    82 
       
    83 
       
    84 ### re1 test
       
    85 
       
    86 if [ $tsts -eq 0 ]
       
    87 then
       
    88   echo -e " nullable(ZERO) == false" | tee -a $out
       
    89   echo -e " nullable(ONE) == true" | tee -a $out
       
    90   echo -e " nullable(CHAR('a')) == false" | tee -a $out
       
    91   echo -e " nullable(ZERO | ONE) == true" | tee -a $out
       
    92   echo -e " nullable(ZERO | CHAR('a')) == false" | tee -a $out
       
    93   echo -e " nullable(ONE ~  ONE) == true" | tee -a $out
       
    94   echo -e " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
       
    95   echo -e " nullable(STAR(ZERO)) == true" | tee -a $out
       
    96   
       
    97   if (scala_assert "re.scala" "re_test1.scala")
       
    98   then
       
    99       echo -e "  --> success" | tee -a $out
       
   100       marks=$(( marks + 1 ))
       
   101   else
       
   102       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   103   fi
       
   104 fi
       
   105 
       
   106 ### re2 test
       
   107 
       
   108 if [ $tsts -eq 0 ]
       
   109 then
       
   110   echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
       
   111   echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
       
   112   echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
       
   113   echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
       
   114   echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
       
   115   echo -e "" | tee -a $out
       
   116   echo -e " val r0 = \"a\" ~ \"b\" ~ \"c\"" | tee -a $out
       
   117   echo -e " der('a', r0) == (ONE ~ \"b\") ~ \"c\"" | tee -a $out
       
   118   echo -e " der('b', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out
       
   119   echo -e " der('c', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out
       
   120   echo -e "" | tee -a $out
       
   121   echo -e " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out
       
   122   echo -e " der('a', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out
       
   123   echo -e " der('b', r1) == ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out
       
   124   echo -e " der('c', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out
       
   125   echo -e "" | tee -a $out
       
   126   echo -e " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out
       
   127   echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out
       
   128   echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out
       
   129   echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE)" | tee -a $out
       
   130 
       
   131   if (scala_assert "re.scala" "re_test2.scala")
       
   132   then
       
   133       echo -e "  --> success" | tee -a $out
       
   134       marks=$(( marks + 1 ))
       
   135   else
       
   136       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   137   fi
       
   138 fi
       
   139 
       
   140 ### re3 test
       
   141 
       
   142 if [ $tsts -eq 0 ]
       
   143 then
       
   144   echo -e " simp(ZERO | ONE) == ONE" | tee -a $out
       
   145   echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
       
   146   echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
       
   147   echo -e " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
       
   148   echo -e " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a')" | tee -a $out
       
   149   echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
       
   150   echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
       
   151   echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
       
   152   echo -e " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
       
   153   echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
       
   154   echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
       
   155   echo -e "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
       
   156   echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
       
   157   echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
       
   158   echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
       
   159   echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" | tee -a $out
       
   160   
       
   161   if (scala_assert "re.scala" "re_test3.scala")
       
   162   then
       
   163       echo -e "  --> success" | tee -a $out
       
   164       marks=$(( marks + 1 ))
       
   165   else
       
   166       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   167   fi
       
   168 fi
       
   169 
       
   170 ### re4 test
       
   171 
       
   172 if [ $tsts -eq 0 ]
       
   173 then
       
   174   echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
       
   175   echo -e " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
       
   176   echo -e " ders(List('b'),EVIL) == ONE" | tee -a $out
       
   177   echo -e " ders(List('b','b'),EVIL) == ZERO" | tee -a $out
       
   178   echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out
       
   179   echo -e " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
       
   180   echo -e " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
       
   181   echo -e " matcher(EVIL, \"b\") == true" | tee -a $out
       
   182   echo -e " matcher(EVIL, \"bb\") == false" | tee -a $out
       
   183   echo -e " matcher(\"abc\", \"abc\") == true" | tee -a $out
       
   184   echo -e " matcher(\"abc\", \"ab\") == false" | tee -a $out
       
   185   echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
       
   186   echo -e " matcher(ONE, \"\") == true" | tee -a $out
       
   187   echo -e " matcher(ZERO, \"\") == false" | tee -a $out
       
   188   echo -e " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
       
   189   echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
       
   190   
       
   191   if (scala_assert "re.scala" "re_test4.scala")
       
   192   then
       
   193       echo -e "  --> success" | tee -a $out
       
   194       marks=$(( marks + 1 ))
       
   195   else
       
   196       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   197   fi
       
   198 fi
       
   199 
       
   200 ### re5 test
       
   201 
       
   202 
       
   203 if [ $tsts -eq 0 ]
       
   204 then
       
   205   echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out  
       
   206   echo -e " size(der('a', der('a', EVIL))) == 28" | tee -a $out
       
   207   echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out
       
   208   echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out
       
   209   echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
       
   210   
       
   211   if (scala_assert "re.scala" "re_test5.scala")
       
   212   then
       
   213       echo -e "  --> success" | tee -a $out
       
   214       marks=$(( marks + 1 ))
       
   215   else
       
   216       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   217   fi
       
   218 fi
       
   219 
       
   220 ### re6 'power' test 1
       
   221 
       
   222 sleep 5
       
   223 
       
   224 if [ $tsts -eq 0 ]
       
   225 then
       
   226   echo -e " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
       
   227   echo -e "    ...the Iterator produces the rexp" | tee -a $out
       
   228   echo -e "" | tee -a $out
       
   229   echo -e "      SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
       
   230   echo -e "" | tee -a $out
       
   231   echo -e "    where SEQ is nested 50 times." | tee -a $out  
       
   232   echo -e "" | tee -a $out
       
   233   echo -e " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out
       
   234   echo -e "    ... the Iterator produces a rexp of size 2097151" | tee -a $out
       
   235   START=$(date +%s)
       
   236   
       
   237   if (scala_assert_thirty "re.scala" "re_test6.scala")
       
   238   then
       
   239       END=$(date +%s)
       
   240       DIFF=$(( $END - $START ))
       
   241       echo "   This test ran for $DIFF seconds" | tee -a $out
       
   242       echo -e "  --> success" | tee -a $out
       
   243       marks=$(( marks + 1 ))
       
   244   else
       
   245       END=$(date +%s)
       
   246       DIFF=$(( $END - $START ))
       
   247       echo "  This test ran for $DIFF seconds" | tee -a $out
       
   248       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   249   fi
       
   250 fi
       
   251 
       
   252 sleep 10
       
   253 
       
   254 ### re7 'power' test 2
       
   255 
       
   256 if [ $tsts -eq 0 ]
       
   257 then
       
   258   echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
       
   259   echo -e " matcher(EVIL, \"a\" * 1000000 ++ \"b\") == true" | tee -a $out
       
   260   echo -e " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out
       
   261   START=$(date +%s)
       
   262   
       
   263   if (scala_assert_thirty "re.scala" "re_test7.scala")
       
   264   then
       
   265       END=$(date +%s)
       
   266       DIFF=$(( $END - $START ))
       
   267       echo "   This test ran for $DIFF seconds" | tee -a $out
       
   268       echo -e "  --> success" | tee -a $out
       
   269       marks=$(( marks + 1 ))
       
   270   else
       
   271       END=$(date +%s)
       
   272       DIFF=$(( $END - $START ))
       
   273       echo "  This test ran for $DIFF seconds" | tee -a $out
       
   274       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   275   fi
       
   276 fi
       
   277 
       
   278 sleep 10
       
   279 
       
   280 ## final marks
       
   281 echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out
       
   282 echo -e "$marks" | tee -a $out
       
   283 
       
   284