| 227 |      1 | #!/bin/bash
 | 
|  |      2 | 
 | 
|  |      3 | # to make the script fail safely
 | 
|  |      4 | set -euo pipefail
 | 
|  |      5 | 
 | 
|  |      6 | 
 | 
|  |      7 | out=${1:-output}
 | 
|  |      8 | 
 | 
| 284 |      9 | 
 | 
| 331 |     10 | echo -e `date` >> $out
 | 
| 284 |     11 | echo -e  "" > $out
 | 
|  |     12 | echo -e  "Below is the feedback and provisional marks for your submission" >> $out
 | 
|  |     13 | echo -e  "for core assignment 7.  Please note all marks are provisional until" >> $out
 | 
|  |     14 | echo -e  "ratified by the assessment board -- this is not an official" >> $out
 | 
|  |     15 | echo -e  "results transcript." >> $out
 | 
|  |     16 | echo -e  "" >> $out
 | 
| 227 |     17 | 
 | 
| 331 |     18 | # marks for core CW7
 | 
|  |     19 | marks=$(( 0 ))
 | 
|  |     20 | 
 | 
|  |     21 | echo -e "" >> $out
 | 
| 284 |     22 | echo -e  "Below is the feedback for your submission danube.scala" >> $out
 | 
|  |     23 | echo -e  "" >> $out
 | 
|  |     24 | 
 | 
| 331 |     25 | 
 | 
| 227 |     26 | 
 | 
|  |     27 | 
 | 
|  |     28 | # compilation tests
 | 
|  |     29 | 
 | 
|  |     30 | function scala_compile {
 | 
| 283 |     31 |     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
 | 
| 227 |     32 | }
 | 
|  |     33 | 
 | 
|  |     34 | # functional tests
 | 
|  |     35 | 
 | 
|  |     36 | function scala_assert {
 | 
| 284 |     37 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
 | 
| 227 |     38 | }
 | 
|  |     39 | 
 | 
|  |     40 | # purity test
 | 
|  |     41 | 
 | 
|  |     42 | function scala_vars {
 | 
| 332 |     43 |    (egrep '\bvar\b|\breturn\b|ListBuffer|new Array' "$1" 2> /dev/null 1> /dev/null)
 | 
| 227 |     44 | }
 | 
| 332 |     45 | #function scala_vars {
 | 
|  |     46 | #   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
 | 
|  |     47 | #}
 | 
| 227 |     48 | 
 | 
|  |     49 | 
 | 
|  |     50 | # var, .par return, ListBuffer test
 | 
|  |     51 | #
 | 
| 331 |     52 | echo -e  "danube.scala does not contain vars, returns,  Arrays, ListBuffers etc?" | tee -a $out
 | 
| 227 |     53 | 
 | 
|  |     54 | if (scala_vars danube.scala)
 | 
|  |     55 | then
 | 
| 331 |     56 |   echo -e  "  --> TEST FAILED\n" | tee -a $out
 | 
| 264 |     57 |   tsts0=$(( 1 ))  
 | 
| 227 |     58 | else
 | 
| 284 |     59 |   echo -e  "  --> success" | tee -a $out
 | 
| 227 |     60 |   tsts0=$(( 0 )) 
 | 
|  |     61 | fi
 | 
|  |     62 | 
 | 
|  |     63 | ### compilation test
 | 
|  |     64 | 
 | 
|  |     65 | 
 | 
|  |     66 | if  [ $tsts0 -eq 0 ]
 | 
|  |     67 | then 
 | 
| 284 |     68 |   echo -e  "danube.scala runs?" | tee -a $out
 | 
| 227 |     69 | 
 | 
|  |     70 |   if (scala_compile danube.scala)
 | 
|  |     71 |   then
 | 
| 284 |     72 |     echo -e  "  --> success" | tee -a $out
 | 
| 227 |     73 |     tsts=$(( 0 ))
 | 
|  |     74 |   else
 | 
| 284 |     75 |     echo -e  "  --> SCALA DID NOT RUN danube.scala" | tee -a $out
 | 
| 227 |     76 |     tsts=$(( 1 )) 
 | 
|  |     77 |   fi
 | 
|  |     78 | else
 | 
|  |     79 |   tsts=$(( 1 ))     
 | 
|  |     80 | fi
 | 
|  |     81 | 
 | 
|  |     82 | ### danube get_cvs_url tests
 | 
|  |     83 | 
 | 
|  |     84 | if [ $tsts -eq 0 ]
 | 
|  |     85 | then
 | 
| 284 |     86 |   echo -e  "danube.scala tests:" | tee -a $out
 | 
|  |     87 |   echo -e  "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
 | 
|  |     88 |   echo -e  "  get_csv_url(movies_url).length == 9742" | tee -a $out
 | 
| 227 |     89 | 
 | 
|  |     90 |   if (scala_assert "danube.scala" "danube_test1.scala")
 | 
|  |     91 |   then
 | 
| 284 |     92 |       echo -e  "  --> success" | tee -a $out
 | 
| 264 |     93 |       marks=$(( marks + 1 ))
 | 
| 227 |     94 |   else
 | 
| 331 |     95 |       echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
| 227 |     96 |   fi
 | 
|  |     97 | fi
 | 
|  |     98 | 
 | 
|  |     99 | ### danube processing tests
 | 
|  |    100 | 
 | 
|  |    101 | if [ $tsts -eq 0 ]
 | 
|  |    102 | then
 | 
| 284 |    103 |   echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
 | 
|  |    104 |   echo -e  "  val movie_names = process_movies(movies)" | tee -a $out  
 | 
|  |    105 |   echo -e  "  " | tee -a $out
 | 
|  |    106 |   echo -e  "  good_ratings.length == 48580 " | tee -a $out
 | 
|  |    107 |   echo -e  "  movie_names.length == 9742 " | tee -a $out
 | 
| 227 |    108 | 
 | 
|  |    109 |   if (scala_assert "danube.scala" "danube_test2.scala") 
 | 
|  |    110 |   then
 | 
| 284 |    111 |       echo -e  "  --> success" | tee -a $out
 | 
|  |    112 |       marks=$(( marks + 1 ))
 | 
|  |    113 |   else
 | 
| 331 |    114 |       echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
| 284 |    115 |   fi
 | 
|  |    116 | fi
 | 
|  |    117 | 
 | 
|  |    118 | ### danube groupById test
 | 
|  |    119 | 
 | 
|  |    120 | if [ $tsts -eq 0 ]
 | 
|  |    121 | then
 | 
|  |    122 |   echo -e  "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
 | 
|  |    123 |   echo -e  "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
 | 
|  |    124 |   echo -e  "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
 | 
|  |    125 |   echo -e  "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
 | 
|  |    126 |   echo -e  "      where the order in the lists is unimportant" | tee -a $out
 | 
|  |    127 |   echo -e  "  val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
 | 
|  |    128 |   echo -e  "  val ls4 = ls3 zip ls3.tail" | tee -a $out
 | 
|  |    129 |   echo -e  "  val ls5 = ls4 ::: ls4.reverse" | tee -a $out
 | 
|  |    130 |   echo -e  "  groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
 | 
|  |    131 | 
 | 
|  |    132 |   if (scala_assert "danube.scala" "danube_test3.scala")
 | 
|  |    133 |   then
 | 
|  |    134 |       echo -e  -e "  --> success" | tee -a $out
 | 
| 264 |    135 |       marks=$(( marks + 1 ))
 | 
| 227 |    136 |   else
 | 
| 284 |    137 |       echo -e  -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    138 |   fi
 | 
|  |    139 | fi
 | 
|  |    140 | 
 | 
|  |    141 | ### danube favourites tests
 | 
|  |    142 | 
 | 
|  |    143 | if [ $tsts -eq 0 ]
 | 
|  |    144 | then
 | 
|  |    145 |   echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
 | 
|  |    146 |   echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
 | 
|  |    147 |   echo -e  "  favourites(ratings_map, \"912\").length  == 80 " | tee -a $out
 | 
|  |    148 |   echo -e  "  favourites(ratings_map, \"858\").length  == 158 " | tee -a $out
 | 
|  |    149 |   echo -e  "  favourites(ratings_map, \"260\").length  == 201 " | tee -a $out  
 | 
|  |    150 | 
 | 
|  |    151 |   if (scala_assert "danube.scala" "danube_test4.scala") 
 | 
|  |    152 |   then
 | 
|  |    153 |     echo -e  "  --> success" | tee -a $out
 | 
|  |    154 |     marks=$(( marks + 1 ))
 | 
|  |    155 |   else
 | 
|  |    156 |     echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    157 |   fi
 | 
|  |    158 | fi
 | 
|  |    159 | 
 | 
|  |    160 | ### danube suggestions tests
 | 
|  |    161 | 
 | 
|  |    162 | if [ $tsts -eq 0 ]
 | 
|  |    163 | then
 | 
|  |    164 |   echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
 | 
|  |    165 |   echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
 | 
|  |    166 |   echo -e  "  suggestions(ratings_map, \"912\").length  == 4110 " | tee -a $out
 | 
|  |    167 |   echo -e  "  suggestions(ratings_map, \"858\").length  == 4883 " | tee -a $out
 | 
|  |    168 |   echo -e  "  suggestions(ratings_map, \"260\").length  == 4970 " | tee -a $out  
 | 
|  |    169 | 
 | 
|  |    170 |   if (scala_assert "danube.scala" "danube_test5.scala") 
 | 
|  |    171 |   then
 | 
|  |    172 |     echo -e  "  --> success" | tee -a $out
 | 
|  |    173 |     marks=$(( marks + 1 ))
 | 
|  |    174 |   else
 | 
|  |    175 |     echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
|  |    176 |   fi
 | 
|  |    177 | fi
 | 
|  |    178 | 
 | 
|  |    179 | ### danube recommendation tests
 | 
|  |    180 | 
 | 
|  |    181 | if [ $tsts -eq 0 ]
 | 
|  |    182 | then
 | 
|  |    183 |   echo -e  "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " | tee -a $out
 | 
|  |    184 |   echo -e  "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " | tee -a $out
 | 
|  |    185 |   echo -e  "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " | tee -a $out
 | 
|  |    186 |   echo -e  "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " | tee -a $out
 | 
|  |    187 |   echo -e  "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " | tee -a $out
 | 
|  |    188 | 
 | 
|  |    189 |   if (scala_assert "danube.scala" "danube_test6.scala") 
 | 
|  |    190 |   then
 | 
|  |    191 |     echo -e  "  --> success" | tee -a $out
 | 
|  |    192 |     marks=$(( marks + 1 ))
 | 
|  |    193 |   else
 | 
|  |    194 |     echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
 | 
| 227 |    195 |   fi
 | 
|  |    196 | fi
 | 
|  |    197 | 
 | 
| 264 |    198 | 
 | 
|  |    199 | 
 | 
|  |    200 | ## final marks
 | 
| 331 |    201 | echo -e "" >> $out
 | 
| 284 |    202 | echo -e  "Overall mark for CW 7 Core Part" | tee -a $out
 | 
|  |    203 | echo -e  "$marks" | tee -a $out
 | 
| 264 |    204 | 
 | 
|  |    205 | 
 |