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