main_testing3/re_test.sh
changeset 347 4de31fdc0d67
parent 329 8a34b2ebc8cc
child 352 97bcf8efe4e0
equal deleted inserted replaced
346:663c2a9108d1 347:4de31fdc0d67
       
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 
       
     5 out=${1:-output}
       
     6 
       
     7 echo -e "" > $out
       
     8 
       
     9 echo -e "Below is the feedback for your submission of re.scala." >> $out
       
    10 echo -e "" >> $out
       
    11 
       
    12 
       
    13 # compilation tests
       
    14 
       
    15 function scala_compile {
       
    16   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    17 }
       
    18 
       
    19 # functional tests
       
    20 
       
    21 function scala_assert {
       
    22   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    23 }
       
    24 
       
    25 # purity test
       
    26 
       
    27 function scala_vars {
       
    28    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    29 }
       
    30 
       
    31 
       
    32 
       
    33 # compilation test
       
    34 
       
    35 echo -e "re.scala runs?" >> $out
       
    36 
       
    37 if (scala_compile re.scala)
       
    38 then
       
    39     echo -e "  --> yes" >> $out
       
    40     tsts=$(( 0 ))
       
    41 else
       
    42     echo -e "  --> SCALA DID NOT RUN RE.SCALA\n" >> $out
       
    43     tsts=$(( 1 )) 
       
    44 fi
       
    45 
       
    46 # var, return, ListBuffer test
       
    47 #
       
    48 
       
    49 if [ $tsts -eq 0 ]
       
    50 then
       
    51     echo -e "re.scala does not contain vars, returns etc?" >> $out
       
    52 
       
    53     if (scala_vars re.scala)
       
    54     then
       
    55 	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out 
       
    56 	tsts=$(( 1 ))
       
    57     else
       
    58 	echo -e "  --> success" >> $out
       
    59 	tsts=$(( 0 )) 
       
    60     fi
       
    61 fi
       
    62 
       
    63 
       
    64 
       
    65 ### re tests
       
    66 
       
    67 if [ $tsts -eq 0 ]
       
    68 then
       
    69   echo -e " nullable(ZERO) == false" >> $out
       
    70   echo -e " nullable(ONE) == true" >> $out
       
    71   echo -e " nullable(CHAR('a')) == false" >> $out
       
    72   echo -e " nullable(ZERO | ONE) == true" >> $out
       
    73   echo -e " nullable(ZERO | CHAR('a')) == false" >> $out
       
    74   echo -e " nullable(ONE ~  ONE) == true" >> $out
       
    75   echo -e " nullable(ONE ~ CHAR('a')) == false" >> $out
       
    76   echo -e " nullable(STAR(ZERO)) == true" >> $out
       
    77   
       
    78   if (scala_assert "re.scala" "re_test1.scala")
       
    79   then
       
    80     echo -e "  --> success" >> $out
       
    81   else
       
    82     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    83   fi
       
    84 fi
       
    85 
       
    86 
       
    87 
       
    88 if [ $tsts -eq 0 ]
       
    89 then
       
    90   echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" >> $out
       
    91   echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) ==" >> $out
       
    92   echo -e "                 ALT((ONE | ZERO) ~ CHAR('a'), ONE)" >> $out
       
    93   echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" >> $out
       
    94   echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" >> $out
       
    95   
       
    96   if (scala_assert "re.scala" "re_test2.scala")
       
    97   then
       
    98     echo -e "  --> success" >> $out
       
    99   else
       
   100     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   101   fi
       
   102 fi
       
   103 
       
   104 
       
   105 
       
   106 if [ $tsts -eq 0 ]
       
   107 then
       
   108   echo -e " simp(ZERO | ONE) == ONE" >> $out
       
   109   echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" >> $out
       
   110   echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" >> $out
       
   111   echo -e " simp(((ONE ~ ONE) ~ ONE) ~ CHAR('a')) == CHAR('a'))" >> $out
       
   112   echo -e " simp(((ONE | ONE) ~ ONE) ~ CHAR('a')) == CHAR('a'))" >> $out
       
   113   echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" >> $out
       
   114   echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" >> $out
       
   115   echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" >> $out
       
   116   echo -e " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" >> $out
       
   117   echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" >> $out
       
   118   echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," >> $out
       
   119   echo -e "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" >> $out
       
   120   echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" >> $out
       
   121   echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" >> $out
       
   122   echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" >> $out
       
   123   echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" >> $out
       
   124   if (scala_assert "re.scala" "re_test3.scala")
       
   125   then
       
   126     echo -e "  --> success" >> $out
       
   127   else
       
   128     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   129   fi
       
   130 fi
       
   131 
       
   132 
       
   133 if [ $tsts -eq 0 ]
       
   134 then
       
   135   echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
       
   136   echo -e " ders(\"aaaaa\".toList, EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" >> $out
       
   137   echo -e " ders(List('b'), EVIL) == ONE" >> $out
       
   138   echo -e " ders(\"bb\".toList, EVIL) == ZERO" >> $out
       
   139   echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" >> $out
       
   140   echo -e " matcher(EVIL, \"b\") == true" >> $out
       
   141   echo -e " matcher(EVIL, \"bb\") == false" >> $out
       
   142   echo -e " matcher(\"abc\", \"abc\") == true" >> $out
       
   143   echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" >> $out
       
   144   echo -e " matcher(ONE, \"\") == true" >> $out
       
   145   echo -e " matcher(ZERO, \"\") == false" >> $out
       
   146   echo -e " matcher(ONE | CHAR('a'), \"\") == true" >> $out
       
   147   echo -e " matcher(ONE | CHAR('a'), \"a\") == true" >> $out
       
   148   
       
   149   if (scala_assert "re.scala" "re_test4.scala")
       
   150   then
       
   151     echo -e "  --> success" >> $out
       
   152   else
       
   153     echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   154   fi
       
   155 fi
       
   156 
       
   157 
       
   158 if [ $tsts -eq 0 ]
       
   159 then
       
   160   echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out  
       
   161   echo -e " size(der('a', der('a', EVIL))) == 28" >> $out
       
   162   echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" >> $out
       
   163   echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" >> $out
       
   164   
       
   165   if (scala_assert "re.scala" "re_test5.scala")
       
   166   then
       
   167     echo -e "  --> success" >> $out
       
   168   else
       
   169     echo -e "  --> \n ONE TEST FAILED\n" >> $out   
       
   170   fi
       
   171 fi
       
   172 
       
   173