marking1/collatz_test.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 30 Nov 2018 08:56:22 +0000
changeset 225 56732dbefcff
parent 212 4bda49ec24da
child 261 8997430d9765
permissions -rwxr-xr-x
added pdfs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "Below is the feedback and provisional marks for your submission" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "for assignment 6 Part 1 + 2.  Please note all marks are provisional until" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "ratified by the assessment board -- this is not an official" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "results transcript." >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
echo "Below is the feedback for your submission for collatz.scala" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
echo "" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# marks for CW6 parts 1 + 2
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
marks=$(( 0 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
# compilation tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_compile {
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    26
  (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
# functional tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
function scala_assert {
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    32
  (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
# purity test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
function scala_vars {
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
# var, .par return, ListBuffer test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
#
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    44
echo "collatz.scala does not contain vars, return etc?" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if (scala_vars collatz.scala)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    48
  echo "  --> test failed" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  tsts0=$(( 0 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
### compilation test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
if  [ $tsts0 -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
then 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  echo "collatz.scala runs?" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  if (scala_compile collatz.scala)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    tsts=$(( 0 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  else
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    67
    echo "  --> scala collatz.scala did not run successfully" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
    tsts=$(( 1 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  tsts=$(( 1 ))     
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
### collatz tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  echo "collatz.scala tests:" | tee -a $out
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    79
  echo "  collatz(1) == 0" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    80
  echo "  collatz(6) == 8" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    81
  echo "  collatz(9) == 19" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    82
  echo "  collatz(9000) == 47" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  if (scala_assert "collatz.scala" "collatz_test1.scala")
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
      echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
      marks=$(( marks + 2 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    echo "  --> one of the tests failed" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
### collatz-max tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
then
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    97
  echo "  collatz_max(10) == (19, 9)" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    98
  echo "  collatz_max(100) == (118, 97)" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    99
  echo "  collatz_max(1000) == (178, 871)" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   100
  echo "  collatz_max(10000) == (261, 6171)" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   101
  echo "  collatz_max(100000) == (350, 77031)" | tee -a $out
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   102
  echo "  collatz_max(1000000) == (524, 837799)" | tee -a $out
212
4bda49ec24da updated
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   103
  #  echo "  collatz_max(2) == (1, 2) || collatz_max(2) == (0, 1)" | tee -a $out
4bda49ec24da updated
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   104
  echo "  collatz_max(2) == (1, 2)" | tee -a $out
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   105
  echo "  collatz_max(77000) == (339, 52527)" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  if (scala_assert "collatz.scala" "collatz_test2.scala") 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
      echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
      marks=$(( marks + 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    echo "  --> one of the tests failed" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
## final marks
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
echo "Overall mark for Part 1" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
echo " $marks" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122