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