testing2/danube_test.sh
changeset 211 092e0879a5ae
child 261 8997430d9765
equal deleted inserted replaced
210:63a1376cbebd 211:092e0879a5ae
       
     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 danube.scala" >> $out
       
    12 echo "" >> $out
       
    13 
       
    14 
       
    15 # compilation tests
       
    16 
       
    17 function scala_compile {
       
    18   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
       
    19 }
       
    20 
       
    21 # functional tests
       
    22 
       
    23 function scala_assert {
       
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" 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 "danube.scala does not contain vars, returns etc?" >> $out
       
    37 
       
    38 if (scala_vars danube.scala)
       
    39 then
       
    40   echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
       
    41   tsts0=$(( 0 ))
       
    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 "danube.scala runs?" >> $out
       
    53 
       
    54   if (scala_compile danube.scala)
       
    55   then
       
    56     echo "  --> success" >> $out
       
    57     tsts=$(( 0 ))
       
    58   else
       
    59     echo "  --> scala did not run danube.scala" >> $out
       
    60     tsts=$(( 1 )) 
       
    61   fi
       
    62 else
       
    63   tsts=$(( 1 ))     
       
    64 fi
       
    65 
       
    66 ### danube get_cvs_url tests
       
    67 
       
    68 if [ $tsts -eq 0 ]
       
    69 then
       
    70   echo "danube.scala tests:" >> $out
       
    71   echo "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out
       
    72   echo "  get_csv_url(movies_url).length == 9742" >> $out
       
    73 
       
    74   if (scala_assert "danube.scala" "danube_test1.scala")
       
    75   then
       
    76     echo "  --> success" >> $out
       
    77   else
       
    78     echo "  --> one of the tests failed" >> $out
       
    79   fi
       
    80 fi
       
    81 
       
    82 ### danube processing tests
       
    83 
       
    84 if [ $tsts -eq 0 ]
       
    85 then
       
    86   echo "  val good_ratings = process_ratings(ratings)" >> $out
       
    87   echo "  val movie_names = process_movies(movies)" >> $out  
       
    88   echo "  " >> $out
       
    89   echo "  good_ratings.length == 48580 " >> $out
       
    90   echo "  movie_names.length == 9742 " >> $out
       
    91 
       
    92   if (scala_assert "danube.scala" "danube_test2.scala") 
       
    93   then
       
    94     echo "  --> success" >> $out
       
    95   else
       
    96     echo "  --> one of the tests failed" >> $out
       
    97   fi
       
    98 fi
       
    99