marking2/danube_test.sh
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 05 Aug 2019 20:14:06 +0100
changeset 269 86a85865e772
parent 264 ecd989eee8bd
child 283 ef5f62bf5987
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
     9
# read marks for CW7 part 1
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    10
marks=$(( `tail -1 $out` ))
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    11
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    12
echo $marks
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    13
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    14
echo "" >> $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
echo "Below is the feedback for your submission danube.scala" >> $out
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
echo "" >> $out
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# compilation tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
function scala_compile {
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    23
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out)
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
# functional tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
function scala_assert {
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    29
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
# purity test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
function scala_vars {
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    35
   (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
# var, .par return, ListBuffer test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
#
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    41
echo "danube.scala does not contain vars, returns etc?" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
if (scala_vars danube.scala)
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    45
  echo "  --> test failed" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    46
  tsts0=$(( 1 ))  
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
else
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    48
  echo "  --> success" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 0 )) 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
### compilation test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
if  [ $tsts0 -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
then 
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    57
  echo "danube.scala runs?" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  if (scala_compile danube.scala)
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    61
    echo "  --> success" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    tsts=$(( 0 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  else
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    64
    echo "  --> scala did not run danube.scala" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    tsts=$(( 1 )) 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
else
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  tsts=$(( 1 ))     
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
### danube get_cvs_url tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    75
  echo "danube.scala tests:" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    76
  echo "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    77
  echo "  get_csv_url(movies_url).length == 9742" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  if (scala_assert "danube.scala" "danube_test1.scala")
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    81
      echo "  --> success" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    82
      marks=$(( marks + 1 ))
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  else
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    84
    echo "  --> one of the tests failed" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
### danube processing tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    92
  echo "  val good_ratings = process_ratings(ratings)" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    93
  echo "  val movie_names = process_movies(movies)" | tee -a $out  
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    94
  echo "  " | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    95
  echo "  good_ratings.length == 48580 " | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    96
  echo "  movie_names.length == 9742 " | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  if (scala_assert "danube.scala" "danube_test2.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   100
      echo "  --> success" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   101
      marks=$(( marks + 1 ))
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  else
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   103
    echo "  --> one of the tests failed" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   107
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   108
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   109
## final marks
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   110
echo "Overall mark for CW 7, Part 1 + 2" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   111
echo "$marks" | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   112
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   113