main_marking2/danube_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 25 Jan 2021 00:21:00 +0000
changeset 389 4113d4d8cf62
child 390 175a950470a9
permissions -rwxr-xr-x
updated marking 2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
389
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
#!/bin/zsh
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
# to make the script fail safely
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
set -euo pipefail
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
out=${1:-output}
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
echo "" > $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
echo -e `date` >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
echo -e  "" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
echo -e  "Below is the feedback and provisional marks for your submission" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
echo -e  "of the Main Part 2 (Scala).  Please note all marks are provisional until" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
echo -e  "ratified by the assessment board -- this is not an official" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
echo -e  "results transcript." >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
echo -e  "" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
# marks for core CW7
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
marks=$(( 0.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
echo -e "" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
echo -e  "Below is the feedback for your submission danube.scala" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
echo -e  "" >> $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
# compilation tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
function scala_compile {
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
}
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
# functional tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
function scala_assert {
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
}
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
function scala_assert_thirty {
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
  (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
}
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
# purity test
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
function scala_vars {
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
   (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
}
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
### compilation test
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54
echo -e  "danube.scala runs?" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    55
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
if (scala_compile danube.scala)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
    echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
    tsts=$(( 0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
    echo -e  "  --> SCALA DID NOT RUN danube.scala" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
    tsts=$(( 1 )) 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
# var, .par return, ListBuffer test
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
#
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
if  [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
  then 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
      echo -e  "danube.scala does not contain VARS, RETURNS etc?" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
      if (scala_vars danube.scala)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
      then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
	  echo -e  "  --> TEST FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
	  tsts=$(( 1 ))  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
      else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
	  echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
	  tsts=$(( 0 )) 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
      fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
    tsts=$(( 1 ))  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    87
### danube get_cvs_url tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    89
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    90
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    91
  echo -e  "danube.scala tests:" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
  echo -e  "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
  echo -e  "  get_csv_url(movies_url).length == 9742" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    94
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    95
  if (scala_assert "danube.scala" "danube_test1.scala")
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    97
      echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
      marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
      echo -e  "  --> TEST FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   104
### danube processing tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   105
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
  echo -e  "  val movie_names = process_movies(movies)" | tee -a $out  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
  echo -e  "  " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
  echo -e  "  good_ratings.length == 48580 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
  echo -e  "  movie_names.length == 9742 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
  if (scala_assert "danube.scala" "danube_test2.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
      echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
      marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
      echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
### danube groupById test
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
  echo -e  "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
  echo -e  "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
  echo -e  "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
  echo -e  "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
  echo -e  "      where the order in the lists is unimportant" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
  echo -e  "  val ls3 = (11 to 1000 by 5).map(_.toString).toList" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
  echo -e  "  val ls4 = ls3 zip ls3.tail" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
  echo -e  "  val ls5 = ls4 ::: ls4.reverse" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
  echo -e  "  groupById(ls5, Map()) == Map(11 -> List(16,16), 16 -> List(21,21), ....)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
  if (scala_assert "danube.scala" "danube_test3.scala")
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
      echo -e  -e "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
      marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
      echo -e  -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
### danube favourites tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
  echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
  echo -e  "  favourites(ratings_map, \"912\").length  == 80 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
  echo -e  "  favourites(ratings_map, \"858\").length  == 158 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   154
  echo -e  "  favourites(ratings_map, \"260\").length  == 201 " | tee -a $out  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   155
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
  if (scala_assert "danube.scala" "danube_test4.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   158
    echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
    marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
### danube suggestions tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
  echo -e  "  val good_ratings = process_ratings(ratings)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
  echo -e  "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
  echo -e  "  suggestions(ratings_map, \"912\").length  == 4110 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
  echo -e  "  suggestions(ratings_map, \"858\").length  == 4883 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
  echo -e  "  suggestions(ratings_map, \"260\").length  == 4970 " | tee -a $out  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   175
  if (scala_assert "danube.scala" "danube_test5.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177
    echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   178
    marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   183
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   184
### danube recommendation tests
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   185
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   186
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   187
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   188
  echo -e  "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   189
  echo -e  "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   190
  echo -e  "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   191
  echo -e  "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   192
  echo -e  "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   193
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   194
  if (scala_assert "danube.scala" "danube_test6.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   195
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   196
    echo -e  "  --> success" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   197
    marks=$(( marks + 1.0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   198
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   199
    echo -e  "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   200
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   201
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   202
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   203
### danube most_recommended 1
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   204
gd=$(( 0 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   205
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   206
if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   207
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   208
    echo -e  "  val rmap =  Map(\"1\" -> List(\"b\", \"a\"), " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   209
    echo -e  "                  \"2\" -> List(\"y\", \"x\"), " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   210
    echo -e  "                  \"3\" -> List(\"c\", \"a\")) " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   211
    echo -e  "  val nmap = Map(\"a\" -> \"A\", \"b\" -> \"B\", \"c\" -> \"C\",  " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   212
    echo -e  "                 \"x\" -> \"X\", \"y\" -> \"Y\") " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   213
    echo -e  "  most_recommended(rmap, nmap).toSet == " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   214
    echo -e  "      Set((\"A\",2), (\"B\",1), (\"C\",1), (\"X\",1), (\"Y\",1)) " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   215
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   216
  if (scala_assert "danube.scala" "danube_test7a.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   217
  then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   218
      echo -e  "  --> success (0.5% Marks)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   219
      marks=$(( marks + 0.5 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   220
  else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   221
      echo -e  "  --> TEST FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   222
      gd=$(( 1 ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   223
  fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   224
fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   225
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   226
### danube most_recommended 2
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   227
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   228
sleep 10
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   229
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   230
if [ $gd -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   231
then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   232
   if [ $tsts -eq 0 ]
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   233
   then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   234
       echo -e  "  most_recommended(ratings_map, movie_map) runs within allocated time? " | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   235
       START=$(date +%s)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   236
       
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   237
       if (scala_assert_thirty "danube.scala" "danube_test7b.scala") 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   238
       then
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   239
	   END=$(date +%s)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   240
	   DIFF=$(( $END - $START ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   241
	   echo "   This test ran for $DIFF seconds." | tee -a $out 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   242
	   echo -e  "  --> success (0.5% Marks)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   243
	   marks=$(( marks + 0.5 ))  
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   244
       else
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   245
	   END=$(date +%s)
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   246
	   DIFF=$(( $END - $START ))
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   247
	   echo "  This test ran for $DIFF seconds." | tee -a $out 
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   248
	   echo -e  "  --> TEST FAILED\n" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   249
       fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   250
   fi
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   251
fi   
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   252
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   253
sleep 10
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   254
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   255
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   256
## final marks
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   257
echo -e "Overall mark for Main Part 2 (Scala)" | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   258
printf " %0.1f\n" $marks | tee -a $out
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   259
4113d4d8cf62 updated marking 2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   260