testing4/re_test.sh
author Christian Urban <urbanc@in.tum.de>
Tue, 29 Oct 2019 11:10:09 +0000
changeset 279 14bf4e478534
parent 266 ca48ac1d3c3e
child 300 72688efdf17c
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
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
     2
set -euo pipefail
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
     3
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
out=${1:-output}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
     7
echo -e "" > $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
     9
echo -e "Below is the feedback for your submission of CW 9, Part 1." >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    10
echo -e "" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
# compilation tests
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
function scala_compile {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
    16
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)   
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
# functional tests
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
function scala_assert {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
    22
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) 
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
# purity test
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
function scala_vars {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
   (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
    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
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
# var, return, ListBuffer test
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
#
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    34
echo -e "re.scala does not contain vars, returns etc?" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
if (scala_vars re.scala)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    38
  echo -e "   --> fail (make triple-sure your program conforms to the required format)" >> $out 
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    39
  tsts0=$(( 0 ))
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    41
  echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  tsts0=$(( 0 )) 
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
# compilation test
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    47
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
if  [ $tsts0 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
then    
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    50
  echo -e "re.scala runs?" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  if (scala_compile re.scala)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    54
    echo -e "  --> yes" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    tsts1=$(( 0 ))
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    57
    echo -e "  --> SCALA DID NOT RUN RE.SCALA\n" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
    tsts1=$(( 1 )) 
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  tsts1=$(( 1 ))     
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    64
### re tests
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    68
  echo -e " nullable(ZERO) == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    69
  echo -e " nullable(ONE) == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    70
  echo -e " nullable(CHAR('a')) == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    71
  echo -e " nullable(ZERO | ONE) == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    72
  echo -e " nullable(ZERO | CHAR('a')) == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    73
  echo -e " nullable(ONE ~  ONE) == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    74
  echo -e " nullable(ONE ~ CHAR('a')) == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    75
  echo -e " nullable(STAR(ZERO)) == true" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    77
  if (scala_assert "re.scala" "re_test1.scala")
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    79
    echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    81
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    89
  echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    90
  echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) ==" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    91
  echo -e "                 ALT((ONE | ZERO) ~ CHAR('a'), ONE)" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    92
  echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    93
  echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    95
  if (scala_assert "re.scala" "re_test2.scala")
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    97
    echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    99
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   107
  echo -e " simp(ZERO | ONE) == ONE" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   108
  echo -e " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   109
  echo -e " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   110
  echo -e " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   111
  echo -e " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   112
  echo -e " simp(CHAR('a') | CHAR('a')) == CHAR('a')" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   113
  echo -e " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   114
  echo -e " simp(ALT((CHAR('a') | ZERO) ~ ONE," >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   115
  echo -e "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   116
  if (scala_assert "re.scala" "re_test3.scala")
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   118
    echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   120
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   127
  echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   128
  echo -e " ders(\"aaaaa\".toList, EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   129
  echo -e " ders(List('b'), EVIL) == ONE" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   130
  echo -e " ders(\"bb\".toList, EVIL) == ZERO" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   131
  echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   132
  echo -e " matcher(EVIL, \"b\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   133
  echo -e " matcher(EVIL, \"bb\") == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   134
  echo -e " matcher(\"abc\", \"abc\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   135
  echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   136
  echo -e " matcher(ONE, \"\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   137
  echo -e " matcher(ZERO, \"\") == false" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   138
  echo -e " matcher(ONE | CHAR('a'), \"\") == true" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   139
  echo -e " matcher(ONE | CHAR('a'), \"a\") == true" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   141
  if (scala_assert "re.scala" "re_test4.scala")
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   143
    echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   145
    echo -e "  --> \n ONE TEST FAILED\n" >> $out  
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   152
  echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" >> $out  
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   153
  echo -e " size(der('a', der('a', EVIL))) == 28" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   154
  echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" >> $out
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   155
  echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   157
  if (scala_assert "re.scala" "re_test5.scala")
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  then
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   159
    echo -e "  --> success" >> $out
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  else
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   161
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165