testing1/alcohol_test.sh
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 06 Aug 2019 00:12:34 +0100
changeset 270 38e13601cb1b
parent 147 3e5d8657302f
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
128
fd03a2f06286 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
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# compilation tests
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
function scala_compile {
127
01d522ba48d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    18
  (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
}
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# functional tests
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_assert {
147
3e5d8657302f 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
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# purity test
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_vars {
b91ad3761732 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)
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# var, .par return, ListBuffer test
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
#
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    36
echo "alcohol.scala does not contain vars, returns etc?" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    38
if (scala_vars alcohol.scala)
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
then
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> fail" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 1 ))
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
127
01d522ba48d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    43
  echo "  --> success" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  tsts0=$(( 0 )) 
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
### compilation test
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
if  [ $tsts0 -eq 0 ]
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then 
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    52
  echo "alcohol.scala runs?" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    54
  if (scala_compile alcohol.scala)
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  then
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    echo "  --> success" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    tsts=$(( 0 ))
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  else
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    59
    echo "  --> scala did not run alcohol.scala" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    tsts=$(( 1 )) 
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
else
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  tsts=$(( 1 ))     
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    66
### alcohol tests
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
if [ $tsts -eq 0 ]
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
then
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    70
  echo "get_csv tests:" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    71
  echo "  get_csv_page(url_alcohol).size == 194" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    72
  echo "  get_csv_file(file_population).size == 216" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    74
  if (scala_assert "alcohol.scala" "alcohol_test1.scala")
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    echo "  --> success" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo "  --> one of the tests failed" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    82
### alcohol processing tests
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts -eq 0 ]
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    86
  echo "processing tests:" >> $out  
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    87
  echo "  process_alcs(alcs_list.drop(1))(0) == (\"Afghanistan\", 0.0)" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    88
  echo "  process_pops(pops_list.drop(1))(\"Micronesia\") == 104015" >> $out
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    90
  if (scala_assert "alcohol.scala" "alcohol_test2.scala") 
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  then
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    echo "  --> success" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  else
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    echo "  --> one of the tests failed" >> $out
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
fi
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    98
### alcohol percentage tests
125
b91ad3761732 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
128
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   100
if [ $tsts -eq 0 ]
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   101
then
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   102
  echo "calculation tests:" >> $out  
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   103
  echo "  sorted_country_consumption().size == 177" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   104
  echo "  sorted_country_consumption()(9) == (\"United Kingdom\", 671976864)" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   105
  echo "  percentage(164) == (28771558364L, 28771558364L, 100.0)" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   106
  
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   107
  if (scala_assert "alcohol.scala" "alcohol_test3.scala") 
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   108
  then
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   109
    echo "  --> success" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   110
  else
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   111
    echo "  --> one of the tests failed" >> $out
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   112
  fi
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   113
fi
fd03a2f06286 updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   114