testing1/collatz_test.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 10 Apr 2020 12:12:48 +0100
changeset 333 24bc76d97db2
parent 329 8a34b2ebc8cc
child 343 c8fcc0e0a57f
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
     9
echo -e "" > $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    11
echo -e "Below is the feedback for your submission collatz.scala" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    12
echo -e "" >> $out
125
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 {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    18
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" 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 {
281
87b9e3e2c1a7 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    24
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
125
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 {
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    30
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|collection.mutable|util.control|new Array' "$1" 2> /dev/null 1> /dev/null)
125
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
#
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    36
echo -e "collatz.scala does not contain vars, returns etc?" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    40
  echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" >> $out
199
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
    41
  tsts0=$(( 0 ))
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    43
  echo -e "  --> 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 
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    52
  echo -e "collatz.scala runs?" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    56
    echo -e "  --> success" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    59
    echo -e "  --> SCALA DID NOT RUN COLLATZ.SCALA\n" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    70
  echo -e "collatz.scala tests:" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    71
  echo -e "  collatz(1) == 0" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    72
  echo -e "  collatz(6) == 8" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    73
  echo -e "  collatz(9) == 19" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    77
    echo -e "  --> success" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  else
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    79
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
125
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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    87
  echo -e "  collatz_max(10) == (19, 9)" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    88
  echo -e "  collatz_max(100) == (118, 97)" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    89
  echo -e "  collatz_max(1000) == (178, 871)" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    90
  echo -e "  collatz_max(10000) == (261, 6171)" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    91
  echo -e "  collatz_max(100000) == (350, 77031)" >> $out
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    92
  echo -e "  collatz_max(1000000) == (524, 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
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    96
    echo -e "  --> success" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  else
302
067afe8af35b updated
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    98
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
125
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