testing5/bf_test.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 10 Apr 2020 12:12:48 +0100
changeset 333 24bc76d97db2
parent 286 5c57c407e27b
child 340 9eeab89d0671
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 {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    15
   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $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 {
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    21
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 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 {
c989f50da5de 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)
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
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# var, return, ListBuffer test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
#
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    33
echo -e "bf.scala does not contain vars, returns etc?" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
if (scala_vars bf.scala)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
then
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    37
  echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    38
  tsts0=$(( 0 ))
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    40
  echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 )) 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# compilation test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if  [ $tsts0 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then    
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    48
  echo -e "bf.scala runs?" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  if (scala_compile bf.scala)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    52
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    tsts1=$(( 0 ))
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  else
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    55
    echo -e "  --> SCALA DID NOT RUN BF.SCALA\n" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    tsts1=$(( 1 )) 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
else
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  tsts1=$(( 1 ))     
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
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    63
### bf tests
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    67
  echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    68
  echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    70
  if (scala_assert "bf.scala" "bf_test1.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    72
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    74
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    75
  fi
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
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    78
if [ $tsts1 -eq 0 ]
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    79
then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    80
  echo -e " sread(Map(), 2) == 0" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    81
  echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    82
  echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    83
  echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    84
  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    85
  if (scala_assert "bf.scala" "bf_test2.scala")
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    86
  then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    87
    echo -e "  --> success" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    88
  else
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    89
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  fi
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
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
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
then
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
    97
    echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
    98
    echo -e " jumpRight(\"[xx[x]x]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[xxx]xxx\", 1, 0) == 11" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   101
    echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   102
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   103
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   104
    echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   106
  if (scala_assert "bf.scala" "bf_test3.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   108
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   110
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  fi
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
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
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   118
  echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   119
  echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   120
  echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   121
  echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   122
  echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   124
  if (scala_assert "bf.scala" "bf_test4.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   126
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   128
    echo -e "  --> \n ONE TEST FAILED\n" >> $out 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134