|      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 -e "Below is the feedback for your submission for the advanced part of danube.scala" >> $out |         | 
|     12 echo -e "" >> $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|new Array' "$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 -e "  --> fail (make triple-sure your program conforms to the required format)" >> $out |         | 
|     41   tsts0=$(( 0 )) |         | 
|     42 else |         | 
|     43   echo -e "  --> 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 -e "  --> success" >> $out |         | 
|     57     tsts=$(( 0 )) |         | 
|     58   else |         | 
|     59     echo -e "  --> SCALA DID NOT RUN DANUBE.SCALA\n" >> $out   |         | 
|     60     tsts=$(( 1 ))  |         | 
|     61   fi |         | 
|     62 else |         | 
|     63   tsts=$(( 1 ))      |         | 
|     64 fi |         | 
|     65  |         | 
|     66 ### danube groupById test |         | 
|     67  |         | 
|     68 if [ $tsts -eq 0 ] |         | 
|     69 then |         | 
|     70   echo "  val ls = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" >> $out |         | 
|     71   echo "  groupById(ls, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" >> $out |         | 
|     72   echo "      where the order in the lists is unimportant" >> $out |         | 
|     73  |         | 
|     74   if (scala_assert "danube.scala" "danube_test3.scala") |         | 
|     75   then |         | 
|     76       echo -e "  --> success" >> $out |         | 
|     77   else |         | 
|     78       echo -e "  --> \n ONE TEST FAILED\n" >> $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  |         | 
|    100 echo -e "\nFor other testcases please look at the template file." >> $out |         |