marking1/alcohol_test.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 28 Nov 2018 17:13:40 +0000
changeset 219 44161f2c3226
parent 158 94b11ac19b41
permissions -rwxr-xr-x
updated
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
# read marks for CW6 part 1
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
marks=$(( `tail -1 $out` ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo $marks
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "Below is the feedback for your submission for alcohol.scala" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
echo "" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
# compilation tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
function scala_compile {
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  (ulimit -t 30 -m 1024000 ; scala "$1" 2> /dev/null 1> /dev/null)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
# functional tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
function scala_assert {
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# purity test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
function scala_vars {
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
   (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
    35
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
# var, .par return, ListBuffer test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
#
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
echo "alcohol.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
if (scala_vars alcohol.scala)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  echo "  --> fail" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  tsts0=$(( 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  tsts0=$(( 0 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
### compilation test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
if  [ $tsts0 -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
then 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  echo "alcohol.scala runs?" | tee -a $out
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 (scala_compile alcohol.scala)
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 "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    tsts=$(( 0 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    echo "  --> scala did not run alcohol.scala" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts=$(( 1 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  tsts=$(( 1 ))     
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
### alcohol tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  echo "get_csv tests:" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  echo "  get_csv_page(url_alcohol).size == 194" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  echo "  get_csv_file(file_population).size == 216" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  if (scala_assert "alcohol.scala" "alcohol_test1.scala")
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
      echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
      marks=$(( marks + 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
    echo "  --> one of the tests failed" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
### alcohol processing tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  echo "processing tests:" | tee -a $out  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  echo "  process_alcs(alcs_list.drop(1))(0) == (\"Afghanistan\", 0.0)" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  echo "  process_alcs(alcs_list.drop(1))(1) == (\"Albania\", 4.9)" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  echo "  process_pops(pops_list.drop(1))(\"Micronesia\") == 104015" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  echo "  process_pops(pops_list.drop(1))(\"Albania\") == 2889104" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  if (scala_assert "alcohol.scala" "alcohol_test2.scala") 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
      echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
      marks=$(( marks + 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo "  --> one of the tests failed" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
### alcohol percentage tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  echo "calculation tests:" | tee -a $out  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  echo "  sorted_country_consumption().size == 177" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  echo "  sorted_country_consumption()(9) == (\"United Kingdom\", 671976864)" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  echo "  percentage(164) == (28771558364L, 28771558364L, 100.0)" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  if (scala_assert "alcohol.scala" "alcohol_test3.scala") 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  then
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
      echo "  --> success" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
      marks=$(( marks + 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
    echo "  --> one of the tests failed" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
## final marks
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
echo "Overall mark for Part 1 and 2" | tee -a $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
echo "$marks" | tee -a $out