|      1 #!/bin/bash |         | 
|      2  |         | 
|      3 # to make the script fail safely |         | 
|      4 set -euo pipefail |         | 
|      5  |         | 
|      6  |         | 
|      7 out=${1:-output} |         | 
|      8  |         | 
|      9 echo "" > $out |         | 
|     10  |         | 
|     11 echo "Below is the feedback for your submission for alcohol.scala" >> $out |         | 
|     12 echo "" >> $out |         | 
|     13  |         | 
|     14  |         | 
|     15 # compilation tests |         | 
|     16  |         | 
|     17 function scala_compile { |         | 
|     18   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out)  |         | 
|     19 } |         | 
|     20  |         | 
|     21 # functional tests |         | 
|     22  |         | 
|     23 function scala_assert { |         | 
|     24   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |         | 
|     25 } |         | 
|     26  |         | 
|     27 # purity test |         | 
|     28  |         | 
|     29 function scala_vars { |         | 
|     30    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |         | 
|     31 } |         | 
|     32  |         | 
|     33  |         | 
|     34 # var, .par return, ListBuffer test |         | 
|     35 # |         | 
|     36 echo "alcohol.scala does not contain vars, returns etc?" >> $out |         | 
|     37  |         | 
|     38 if (scala_vars alcohol.scala) |         | 
|     39 then |         | 
|     40   echo "  --> fail" >> $out |         | 
|     41   tsts0=$(( 1 )) |         | 
|     42 else |         | 
|     43   echo "  --> success" >> $out |         | 
|     44   tsts0=$(( 0 ))  |         | 
|     45 fi |         | 
|     46  |         | 
|     47 ### compilation test |         | 
|     48  |         | 
|     49  |         | 
|     50 if  [ $tsts0 -eq 0 ] |         | 
|     51 then  |         | 
|     52   echo "alcohol.scala runs?" >> $out |         | 
|     53  |         | 
|     54   if (scala_compile alcohol.scala) |         | 
|     55   then |         | 
|     56     echo "  --> success" >> $out |         | 
|     57     tsts=$(( 0 )) |         | 
|     58   else |         | 
|     59     echo "  --> scala did not run alcohol.scala" >> $out |         | 
|     60     tsts=$(( 1 ))  |         | 
|     61   fi |         | 
|     62 else |         | 
|     63   tsts=$(( 1 ))      |         | 
|     64 fi |         | 
|     65  |         | 
|     66 ### alcohol tests |         | 
|     67  |         | 
|     68 if [ $tsts -eq 0 ] |         | 
|     69 then |         | 
|     70   echo "get_csv tests:" >> $out |         | 
|     71   echo "  get_csv_page(url_alcohol).size == 194" >> $out |         | 
|     72   echo "  get_csv_file(file_population).size == 216" >> $out |         | 
|     73  |         | 
|     74   if (scala_assert "alcohol.scala" "alcohol_test1.scala") |         | 
|     75   then |         | 
|     76     echo "  --> success" >> $out |         | 
|     77   else |         | 
|     78     echo "  --> one of the tests failed" >> $out |         | 
|     79   fi |         | 
|     80 fi |         | 
|     81  |         | 
|     82 ### alcohol processing tests |         | 
|     83  |         | 
|     84 if [ $tsts -eq 0 ] |         | 
|     85 then |         | 
|     86   echo "processing tests:" >> $out   |         | 
|     87   echo "  process_alcs(alcs_list.drop(1))(0) == (\"Afghanistan\", 0.0)" >> $out |         | 
|     88   echo "  process_pops(pops_list.drop(1))(\"Micronesia\") == 104015" >> $out |         | 
|     89  |         | 
|     90   if (scala_assert "alcohol.scala" "alcohol_test2.scala")  |         | 
|     91   then |         | 
|     92     echo "  --> success" >> $out |         | 
|     93   else |         | 
|     94     echo "  --> one of the tests failed" >> $out |         | 
|     95   fi |         | 
|     96 fi |         | 
|     97  |         | 
|     98 ### alcohol percentage tests |         | 
|     99  |         | 
|    100 if [ $tsts -eq 0 ] |         | 
|    101 then |         | 
|    102   echo "calculation tests:" >> $out   |         | 
|    103   echo "  sorted_country_consumption().size == 177" >> $out |         | 
|    104   echo "  sorted_country_consumption()(9) == (\"United Kingdom\", 671976864)" >> $out |         | 
|    105   echo "  percentage(164) == (28771558364L, 28771558364L, 100.0)" >> $out |         | 
|    106    |         | 
|    107   if (scala_assert "alcohol.scala" "alcohol_test3.scala")  |         | 
|    108   then |         | 
|    109     echo "  --> success" >> $out |         | 
|    110   else |         | 
|    111     echo "  --> one of the tests failed" >> $out |         | 
|    112   fi |         | 
|    113 fi |         | 
|    114  |         |