main_testing5/bf_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 06 Nov 2020 01:07:26 +0000
changeset 352 97bcf8efe4e0
parent 348 b5b6ed38c2f2
child 376 6cc36d0ef79e
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     2
set -euo pipefail
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
     6
echo -e "" > $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     8
echo -e "Below is the feedback for your submission of CW 10." >> $out
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
     9
echo -e "" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
# compilation tests
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
function scala_compile {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    15
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# functional tests
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_assert {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    21
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# purity test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_vars {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    27
   (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    31
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    32
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    33
echo -e "bf.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    34
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    35
if (scala_compile bf.scala)
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    36
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    37
    echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    38
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    39
else
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    40
    echo -e "  --> SCALA DID NOT RUN BF.SCALA\n" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    41
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    42
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    43
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    44
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# var, return, ListBuffer test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
#
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    48
if [ $tsts1 -eq 0 ]
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    50
    echo -e "bf.scala does not contain vars, returns etc?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    51
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    52
    if (scala_vars bf.scala)
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    53
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    54
	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    55
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    56
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    57
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    58
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    59
    fi
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    64
### bf tests
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    68
  echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    69
  echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    71
  if (scala_assert "bf.scala" "bf_test1.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    73
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    75
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    76
  fi
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    77
fi
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    78
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    79
if [ $tsts1 -eq 0 ]
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    80
then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    81
  echo -e " sread(Map(), 2) == 0" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    82
  echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    83
  echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    84
  echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    85
  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    86
  if (scala_assert "bf.scala" "bf_test2.scala")
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    87
  then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    88
    echo -e "  --> success" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    89
  else
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    90
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
then
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
    98
    echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
    99
    echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   100
    echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   101
    echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   102
    echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   103
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   104
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   105
    echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   107
  if (scala_assert "bf.scala" "bf_test3.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   109
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   111
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   119
  echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   120
  echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   121
  echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
340
9eeab89d0671 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
   122
  echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000))" >> $out
9eeab89d0671 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
   123
  echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" >> $out
9eeab89d0671 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
   124
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   125
  echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   126
  echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   128
  if (scala_assert "bf.scala" "bf_test4.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   130
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   132
    echo -e "  --> \n ONE TEST FAILED\n" >> $out 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138