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