testing5/bf_test2.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 16 Aug 2019 06:51:06 +0100
changeset 276 52faee6d0be2
parent 266 ca48ac1d3c3e
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -e
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo -e "" > $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo -e "Below is the feedback for your submission of CW 10, Part 2." >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo -e "" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
# compilation tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
5a16bcb4105e 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: 263
diff changeset
    15
   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# functional tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_assert {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 263
diff changeset
    21
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "")  #2> /dev/null 1> /dev/null)   
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# purity test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_vars {
5a16bcb4105e 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)
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# var, return, ListBuffer test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
#
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
echo -e "bfc.scala does not contain vars, returns etc?" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
if (scala_vars bfc.scala)
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  echo -e "   --> fail (make triple-sure your program conforms to the required format)" >> $out  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  tsts0=$(( 0 ))
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 )) 
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# compilation test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if  [ $tsts0 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then    
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  echo -e "bfc.scala runs?" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  if (scala_compile bfc.scala)
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    tsts1=$(( 0 ))
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    echo -e "  -->   --> SCALA DID NOT RUN BFC.SCALA\nx" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    tsts1=$(( 1 )) 
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  tsts1=$(( 1 ))     
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
### bfc tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  echo -e "     Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  if (scala_assert "bfc.scala" "bf_test5.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  if (scala_assert "bfc.scala" "bf_test6.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
    echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  if (scala_assert "bfc.scala" "bf_test7.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109