testing2/danube_test.sh
author Christian Urban <urbanc@in.tum.de>
Sun, 09 Dec 2018 01:36:49 +0000
changeset 243 9bb36426c781
parent 211 092e0879a5ae
child 261 8997430d9765
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "Below is the feedback for your submission danube.scala" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# compilation tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
function scala_compile {
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# functional tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_assert {
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# purity test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_vars {
092e0879a5ae 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)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# var, .par return, ListBuffer test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
#
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
echo "danube.scala does not contain vars, returns etc?" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
if (scala_vars danube.scala)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 ))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  echo "  --> success" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  tsts0=$(( 0 )) 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
### compilation test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
if  [ $tsts0 -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  echo "danube.scala runs?" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  if (scala_compile danube.scala)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    echo "  --> success" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    tsts=$(( 0 ))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    echo "  --> scala did not run danube.scala" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    tsts=$(( 1 )) 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  tsts=$(( 1 ))     
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
### danube get_cvs_url tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  echo "danube.scala tests:" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  echo "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  echo "  get_csv_url(movies_url).length == 9742" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  if (scala_assert "danube.scala" "danube_test1.scala")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    echo "  --> success" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo "  --> one of the tests failed" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
### danube processing tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  echo "  val good_ratings = process_ratings(ratings)" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  echo "  val movie_names = process_movies(movies)" >> $out  
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  echo "  " >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  echo "  good_ratings.length == 48580 " >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  echo "  movie_names.length == 9742 " >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  if (scala_assert "danube.scala" "danube_test2.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  then
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    echo "  --> success" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    echo "  --> one of the tests failed" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99