testing3/bf_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 23 Nov 2017 10:56:47 +0000
changeset 153 4383809c176a
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
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -e
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo "" > $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo "Below is the feedback for your submission of CW 8, Part 2." >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
# compilation tests
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
function scala_compile {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# functional tests
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_assert {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# purity test
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_vars {
4383809c176a 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)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}
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
# var, return, ListBuffer test
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
#
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
echo "bf.scala does not contain vars, returns etc?" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
if (scala_vars bf.scala)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  echo "  --> fail" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  tsts0=$(( 1 ))
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> success" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 )) 
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# compilation test
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if  [ $tsts0 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then    
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  echo "bf.scala runs?" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  if (scala_compile bf.scala)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
    echo "  --> success" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    tsts1=$(( 0 ))
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    echo "  --> scala bf.scala did not run successfully" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    tsts1=$(( 1 )) 
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  tsts1=$(( 1 ))     
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  echo " sread(Map(), 2) == 0" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  echo " sread(Map(2 -> 1), 2) == 1" >> $out  
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  echo " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  if (scala_assert "bf.scala" "bf1a_test.scala")
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    echo "  --> success" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo "  --> test failed" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
    echo " jumpRight(\"[******]***\", 1, 0) == 8" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
    echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
    echo " jumpRight(\"[**[***]***\", 1, 0) == 11" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo " jumpRight(\"[*[][]*]***\", 1, 0) == 8" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
    echo " jumpLeft(\"[******]***\", 6, 0) == 1" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    echo " jumpLeft(\"[******]***\", 7, 0) == -1" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    echo " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  if (scala_assert "bf.scala" "bf1b_test.scala")
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    echo "  --> success" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    echo "  --> test failed" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
if [ $tsts1 -eq 0 ]
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  echo " start(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  echo " start(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  echo " start(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  echo " start({{hello world prg 1}}, Map()) == " >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  echo "        Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  if (scala_assert "bf.scala" "bf1c_test.scala")
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  then
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    echo "  --> success" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  else
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    echo "  --> test failed" >> $out
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
fi
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120