| 
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 {
 | 
| 
331
 | 
    43  | 
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
  | 
| 
227
 | 
    44  | 
}
  | 
| 
 | 
    45  | 
  | 
| 
 | 
    46  | 
  | 
| 
 | 
    47  | 
# var, .par return, ListBuffer test
  | 
| 
 | 
    48  | 
#
  | 
| 
331
 | 
    49  | 
echo -e  "danube.scala does not contain vars, returns,  Arrays, ListBuffers etc?" | tee -a $out
  | 
| 
227
 | 
    50  | 
  | 
| 
 | 
    51  | 
if (scala_vars danube.scala)
  | 
| 
 | 
    52  | 
then
  | 
| 
331
 | 
    53  | 
  echo -e  "  --> TEST FAILED\n" | tee -a $out
  | 
| 
264
 | 
    54  | 
  tsts0=$(( 1 ))  
  | 
| 
227
 | 
    55  | 
else
  | 
| 
284
 | 
    56  | 
  echo -e  "  --> success" | tee -a $out
  | 
| 
227
 | 
    57  | 
  tsts0=$(( 0 )) 
  | 
| 
 | 
    58  | 
fi
  | 
| 
 | 
    59  | 
  | 
| 
 | 
    60  | 
### compilation test
  | 
| 
 | 
    61  | 
  | 
| 
 | 
    62  | 
  | 
| 
 | 
    63  | 
if  [ $tsts0 -eq 0 ]
  | 
| 
 | 
    64  | 
then 
  | 
| 
284
 | 
    65  | 
  echo -e  "danube.scala runs?" | tee -a $out
  | 
| 
227
 | 
    66  | 
  | 
| 
 | 
    67  | 
  if (scala_compile danube.scala)
  | 
| 
 | 
    68  | 
  then
  | 
| 
284
 | 
    69  | 
    echo -e  "  --> success" | tee -a $out
  | 
| 
227
 | 
    70  | 
    tsts=$(( 0 ))
  | 
| 
 | 
    71  | 
  else
  | 
| 
284
 | 
    72  | 
    echo -e  "  --> SCALA DID NOT RUN danube.scala" | tee -a $out
  | 
| 
227
 | 
    73  | 
    tsts=$(( 1 )) 
  | 
| 
 | 
    74  | 
  fi
  | 
| 
 | 
    75  | 
else
  | 
| 
 | 
    76  | 
  tsts=$(( 1 ))     
  | 
| 
 | 
    77  | 
fi
  | 
| 
 | 
    78  | 
  | 
| 
 | 
    79  | 
### danube get_cvs_url tests
  | 
| 
 | 
    80  | 
  | 
| 
 | 
    81  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
    82  | 
then
  | 
| 
284
 | 
    83  | 
  echo -e  "danube.scala tests:" | tee -a $out
  | 
| 
 | 
    84  | 
  echo -e  "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
  | 
| 
 | 
    85  | 
  echo -e  "  get_csv_url(movies_url).length == 9742" | tee -a $out
  | 
| 
227
 | 
    86  | 
  | 
| 
 | 
    87  | 
  if (scala_assert "danube.scala" "danube_test1.scala")
  | 
| 
 | 
    88  | 
  then
  | 
| 
284
 | 
    89  | 
      echo -e  "  --> success" | tee -a $out
  | 
| 
264
 | 
    90  | 
      marks=$(( marks + 1 ))
  | 
| 
227
 | 
    91  | 
  else
  | 
| 
331
 | 
    92  | 
      echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
227
 | 
    93  | 
  fi
  | 
| 
 | 
    94  | 
fi
  | 
| 
 | 
    95  | 
  | 
| 
 | 
    96  | 
### danube processing tests
  | 
| 
 | 
    97  | 
  | 
| 
 | 
    98  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
    99  | 
then
  | 
| 
284
 | 
   100  | 
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
  | 
| 
 | 
   101  | 
  echo -e  "  val movie_names = process_movies(movies)" | tee -a $out  
  | 
| 
 | 
   102  | 
  echo -e  "  " | tee -a $out
  | 
| 
 | 
   103  | 
  echo -e  "  good_ratings.length == 48580 " | tee -a $out
  | 
| 
 | 
   104  | 
  echo -e  "  movie_names.length == 9742 " | tee -a $out
  | 
| 
227
 | 
   105  | 
  | 
| 
 | 
   106  | 
  if (scala_assert "danube.scala" "danube_test2.scala") 
  | 
| 
 | 
   107  | 
  then
  | 
| 
284
 | 
   108  | 
      echo -e  "  --> success" | tee -a $out
  | 
| 
 | 
   109  | 
      marks=$(( marks + 1 ))
  | 
| 
 | 
   110  | 
  else
  | 
| 
331
 | 
   111  | 
      echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
284
 | 
   112  | 
  fi
  | 
| 
 | 
   113  | 
fi
  | 
| 
 | 
   114  | 
  | 
| 
 | 
   115  | 
### danube groupById test
  | 
| 
 | 
   116  | 
  | 
| 
 | 
   117  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   118  | 
then
  | 
| 
 | 
   119  | 
  echo -e  "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
  | 
| 
 | 
   120  | 
  echo -e  "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
  | 
| 
 | 
   121  | 
  echo -e  "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
  | 
| 
 | 
   122  | 
  echo -e  "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
  | 
| 
 | 
   123  | 
  echo -e  "      where the order in the lists is unimportant" | tee -a $out
  | 
| 
 | 
   124  | 
  echo -e  "  val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
  | 
| 
 | 
   125  | 
  echo -e  "  val ls4 = ls3 zip ls3.tail" | tee -a $out
  | 
| 
 | 
   126  | 
  echo -e  "  val ls5 = ls4 ::: ls4.reverse" | tee -a $out
  | 
| 
 | 
   127  | 
  echo -e  "  groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
  | 
| 
 | 
   128  | 
  | 
| 
 | 
   129  | 
  if (scala_assert "danube.scala" "danube_test3.scala")
  | 
| 
 | 
   130  | 
  then
  | 
| 
 | 
   131  | 
      echo -e  -e "  --> success" | tee -a $out
  | 
| 
264
 | 
   132  | 
      marks=$(( marks + 1 ))
  | 
| 
227
 | 
   133  | 
  else
  | 
| 
284
 | 
   134  | 
      echo -e  -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
 | 
   135  | 
  fi
  | 
| 
 | 
   136  | 
fi
  | 
| 
 | 
   137  | 
  | 
| 
 | 
   138  | 
### danube favourites tests
  | 
| 
 | 
   139  | 
  | 
| 
 | 
   140  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   141  | 
then
  | 
| 
 | 
   142  | 
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
  | 
| 
 | 
   143  | 
  echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
  | 
| 
 | 
   144  | 
  echo -e  "  favourites(ratings_map, \"912\").length  == 80 " | tee -a $out
  | 
| 
 | 
   145  | 
  echo -e  "  favourites(ratings_map, \"858\").length  == 158 " | tee -a $out
  | 
| 
 | 
   146  | 
  echo -e  "  favourites(ratings_map, \"260\").length  == 201 " | tee -a $out  
  | 
| 
 | 
   147  | 
  | 
| 
 | 
   148  | 
  if (scala_assert "danube.scala" "danube_test4.scala") 
  | 
| 
 | 
   149  | 
  then
  | 
| 
 | 
   150  | 
    echo -e  "  --> success" | tee -a $out
  | 
| 
 | 
   151  | 
    marks=$(( marks + 1 ))
  | 
| 
 | 
   152  | 
  else
  | 
| 
 | 
   153  | 
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
 | 
   154  | 
  fi
  | 
| 
 | 
   155  | 
fi
  | 
| 
 | 
   156  | 
  | 
| 
 | 
   157  | 
### danube suggestions tests
  | 
| 
 | 
   158  | 
  | 
| 
 | 
   159  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   160  | 
then
  | 
| 
 | 
   161  | 
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
  | 
| 
 | 
   162  | 
  echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
  | 
| 
 | 
   163  | 
  echo -e  "  suggestions(ratings_map, \"912\").length  == 4110 " | tee -a $out
  | 
| 
 | 
   164  | 
  echo -e  "  suggestions(ratings_map, \"858\").length  == 4883 " | tee -a $out
  | 
| 
 | 
   165  | 
  echo -e  "  suggestions(ratings_map, \"260\").length  == 4970 " | tee -a $out  
  | 
| 
 | 
   166  | 
  | 
| 
 | 
   167  | 
  if (scala_assert "danube.scala" "danube_test5.scala") 
  | 
| 
 | 
   168  | 
  then
  | 
| 
 | 
   169  | 
    echo -e  "  --> success" | tee -a $out
  | 
| 
 | 
   170  | 
    marks=$(( marks + 1 ))
  | 
| 
 | 
   171  | 
  else
  | 
| 
 | 
   172  | 
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
 | 
   173  | 
  fi
  | 
| 
 | 
   174  | 
fi
  | 
| 
 | 
   175  | 
  | 
| 
 | 
   176  | 
### danube recommendation tests
  | 
| 
 | 
   177  | 
  | 
| 
 | 
   178  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   179  | 
then
  | 
| 
 | 
   180  | 
  echo -e  "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " | tee -a $out
  | 
| 
 | 
   181  | 
  echo -e  "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " | tee -a $out
  | 
| 
 | 
   182  | 
  echo -e  "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " | tee -a $out
  | 
| 
 | 
   183  | 
  echo -e  "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " | tee -a $out
  | 
| 
 | 
   184  | 
  echo -e  "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " | tee -a $out
  | 
| 
 | 
   185  | 
  | 
| 
 | 
   186  | 
  if (scala_assert "danube.scala" "danube_test6.scala") 
  | 
| 
 | 
   187  | 
  then
  | 
| 
 | 
   188  | 
    echo -e  "  --> success" | tee -a $out
  | 
| 
 | 
   189  | 
    marks=$(( marks + 1 ))
  | 
| 
 | 
   190  | 
  else
  | 
| 
 | 
   191  | 
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
  | 
| 
227
 | 
   192  | 
  fi
  | 
| 
 | 
   193  | 
fi
  | 
| 
 | 
   194  | 
  | 
| 
264
 | 
   195  | 
  | 
| 
 | 
   196  | 
  | 
| 
 | 
   197  | 
## final marks
  | 
| 
331
 | 
   198  | 
echo -e "" >> $out
  | 
| 
284
 | 
   199  | 
echo -e  "Overall mark for CW 7 Core Part" | tee -a $out
  | 
| 
 | 
   200  | 
echo -e  "$marks" | tee -a $out
  | 
| 
264
 | 
   201  | 
  | 
| 
 | 
   202  | 
  |