testing1/collatz_test.sh
author Christian Urban <urbanc@in.tum.de>
Tue, 10 Jul 2018 15:09:28 +0100
changeset 189 ff815ca0bbcf
parent 144 716042628398
child 199 54befaf23648
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    11
echo "Below is the feedback for your submission collatz.scala" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# compilation tests
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
function scala_compile {
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    18
  (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
}
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# functional tests
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_assert {
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# purity test
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_vars {
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# var, .par return, ListBuffer test
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
#
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
echo "collatz.scala does not contain vars, returns etc?" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
if (scala_vars collatz.scala)
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> fail" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 1 ))
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    43
  echo "  --> success" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  tsts0=$(( 0 )) 
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
### compilation test
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
if  [ $tsts0 -eq 0 ]
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then 
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  echo "collatz.scala runs?" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  if (scala_compile collatz.scala)
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    echo "  --> success" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    tsts=$(( 0 ))
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    echo "  --> scala did not run collatz.scala" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    tsts=$(( 1 )) 
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  tsts=$(( 1 ))     
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
### collatz tests
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
if [ $tsts -eq 0 ]
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
then
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    70
  echo "collatz.scala tests:" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  echo "  collatz(1) == 0,1 or 4" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  echo "  collatz(6) == 9" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  echo "  collatz(9) == 20" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  if (scala_assert "collatz.scala" "collatz_test1.scala")
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    echo "  --> success" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
    echo "  --> one of the tests failed" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
### collatz-max tests
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
if [ $tsts -eq 0 ]
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
then
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    87
  echo "  collatz_max(10) == (20, 9)" >> $out
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    88
  echo "  collatz_max(100) == (119, 97)" >> $out
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    89
  echo "  collatz_max(1000) == (179, 871)" >> $out
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    90
  echo "  collatz_max(10000) == (262, 6171)" >> $out
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    91
  echo "  collatz_max(100000) == (351, 77031)" >> $out
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    92
  echo "  collatz_max(1000000) == (525, 837799)" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  if (scala_assert "collatz.scala" "collatz_test2.scala") 
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    echo "  --> success" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
    echo "  --> one of the tests failed" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102