testing1/alcohol_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 06 Dec 2018 13:15:28 +0000
changeset 229 5549016ab10f
parent 147 72f7dd1a3754
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 for alcohol.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 {
147
72f7dd1a3754 updated
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
    24
  (ulimit -t 30 -m 1024000 ; 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 {
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
#
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    36
echo "alcohol.scala does not contain vars, returns etc?" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    38
if (scala_vars alcohol.scala)
125
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 
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    52
  echo "alcohol.scala runs?" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    54
  if (scala_compile alcohol.scala)
125
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
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    59
    echo "  --> scala did not run alcohol.scala" >> $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
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    66
### alcohol tests
125
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
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    70
  echo "get_csv tests:" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    71
  echo "  get_csv_page(url_alcohol).size == 194" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    72
  echo "  get_csv_file(file_population).size == 216" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    74
  if (scala_assert "alcohol.scala" "alcohol_test1.scala")
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    echo "  --> success" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo "  --> one of the tests failed" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  fi
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
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    82
### alcohol processing tests
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts -eq 0 ]
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    86
  echo "processing tests:" >> $out  
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    87
  echo "  process_alcs(alcs_list.drop(1))(0) == (\"Afghanistan\", 0.0)" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    88
  echo "  process_pops(pops_list.drop(1))(\"Micronesia\") == 104015" >> $out
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    90
  if (scala_assert "alcohol.scala" "alcohol_test2.scala") 
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  then
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    echo "  --> success" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  else
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    echo "  --> one of the tests failed" >> $out
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
fi
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    98
### alcohol percentage tests
125
dcaab8068baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
128
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   100
if [ $tsts -eq 0 ]
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   101
then
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   102
  echo "calculation tests:" >> $out  
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   103
  echo "  sorted_country_consumption().size == 177" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   104
  echo "  sorted_country_consumption()(9) == (\"United Kingdom\", 671976864)" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   105
  echo "  percentage(164) == (28771558364L, 28771558364L, 100.0)" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   106
  
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   107
  if (scala_assert "alcohol.scala" "alcohol_test3.scala") 
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   108
  then
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   109
    echo "  --> success" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   110
  else
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   111
    echo "  --> one of the tests failed" >> $out
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   112
  fi
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   113
fi
166bb9b6b20a updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   114