| 227 |      1 | #!/bin/bash
 | 
|  |      2 | 
 | 
|  |      3 | # to make the script fail safely
 | 
|  |      4 | set -euo pipefail
 | 
|  |      5 | 
 | 
|  |      6 | 
 | 
|  |      7 | out=${1:-output}
 | 
|  |      8 | 
 | 
| 259 |      9 | echo "" > $out
 | 
| 227 |     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 {
 | 
| 261 |     18 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) 
 | 
| 227 |     19 | }
 | 
|  |     20 | 
 | 
|  |     21 | # functional tests
 | 
|  |     22 | 
 | 
|  |     23 | function scala_assert {
 | 
| 261 |     24 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 227 |     25 | }
 | 
|  |     26 | 
 | 
|  |     27 | # purity test
 | 
|  |     28 | 
 | 
|  |     29 | function scala_vars {
 | 
| 259 |     30 |    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
 | 
| 227 |     31 | }
 | 
|  |     32 | 
 | 
|  |     33 | 
 | 
|  |     34 | # var, .par return, ListBuffer test
 | 
|  |     35 | #
 | 
| 259 |     36 | echo "danube.scala does not contain vars, returns etc?" >> $out
 | 
| 227 |     37 | 
 | 
|  |     38 | if (scala_vars danube.scala)
 | 
|  |     39 | then
 | 
| 259 |     40 |   echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
 | 
|  |     41 |   tsts0=$(( 0 ))
 | 
| 227 |     42 | else
 | 
| 259 |     43 |   echo "  --> success" >> $out
 | 
| 227 |     44 |   tsts0=$(( 0 )) 
 | 
|  |     45 | fi
 | 
|  |     46 | 
 | 
|  |     47 | ### compilation test
 | 
|  |     48 | 
 | 
|  |     49 | 
 | 
|  |     50 | if  [ $tsts0 -eq 0 ]
 | 
|  |     51 | then 
 | 
| 259 |     52 |   echo "danube.scala runs?" >> $out
 | 
| 227 |     53 | 
 | 
|  |     54 |   if (scala_compile danube.scala)
 | 
|  |     55 |   then
 | 
| 259 |     56 |     echo "  --> success" >> $out
 | 
| 227 |     57 |     tsts=$(( 0 ))
 | 
|  |     58 |   else
 | 
| 259 |     59 |     echo "  --> scala did not run danube.scala" >> $out
 | 
| 227 |     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
 | 
| 259 |     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
 | 
| 227 |     73 | 
 | 
|  |     74 |   if (scala_assert "danube.scala" "danube_test1.scala")
 | 
|  |     75 |   then
 | 
| 259 |     76 |     echo "  --> success" >> $out
 | 
| 227 |     77 |   else
 | 
| 259 |     78 |     echo "  --> one of the tests failed" >> $out
 | 
| 227 |     79 |   fi
 | 
|  |     80 | fi
 | 
|  |     81 | 
 | 
|  |     82 | ### danube processing tests
 | 
|  |     83 | 
 | 
|  |     84 | if [ $tsts -eq 0 ]
 | 
|  |     85 | then
 | 
| 259 |     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
 | 
| 227 |     91 | 
 | 
|  |     92 |   if (scala_assert "danube.scala" "danube_test2.scala") 
 | 
|  |     93 |   then
 | 
| 259 |     94 |     echo "  --> success" >> $out
 | 
| 227 |     95 |   else
 | 
| 259 |     96 |     echo "  --> one of the tests failed" >> $out
 | 
| 227 |     97 |   fi
 | 
|  |     98 | fi
 | 
|  |     99 | 
 |