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