marking2/danube_test2.sh
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 05 Aug 2019 20:14:06 +0100
changeset 269 86a85865e772
parent 260 b4812c877b05
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "Below is the feedback and provisional marks for your submission" >> $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "for assignment 7 Part 3.  Please note all marks are provisional until" >> $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "ratified by the assessment board -- this is not an official" >> $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "results transcript." >> $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "" >> $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
# marks for CW7 part 3
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
marks=$(( 0 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# compilation tests
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_compile {
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# functional tests
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_assert {
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    30
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
# purity test
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
function scala_vars {
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
}
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
# var, .par return, ListBuffer test
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
#
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
echo "danube.scala does not contain vars, returns etc?" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
if (scala_vars danube.scala)
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  echo "  --> test failed" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  tsts0=$(( 1 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  echo -e "  --> success" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  tsts0=$(( 0 )) 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    53
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
### compilation test
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
if  [ $tsts0 -eq 0 ]
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
then 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  echo "danube.scala runs?" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  if (scala_compile danube.scala)
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    echo -e "  --> success" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts=$(( 0 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    echo "  --> scala danube.scala did not run successfully" | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    tsts=$(( 1 )) 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  tsts=$(( 1 ))     
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
### danube groupById test
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
if [ $tsts -eq 0 ]
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  echo "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  echo "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  echo "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  echo "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  echo "      where the order in the lists is unimportant" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  echo "  val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  echo "  val ls4 = ls3 zip ls3.tail" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  echo "  val ls5 = ls4 ::: ls4.reverse" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  echo "  groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  if (scala_assert "danube.scala" "danube_test3.scala")
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      echo -e "  --> success" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
      marks=$(( marks + 1 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
      echo -e "  --> test failed" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
### danube favourites tests
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
if [ $tsts -eq 0 ]
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  echo "  val good_ratings = process_ratings(ratings)" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  echo "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  echo "  favourites(ratings_map, \"912\").length  == 80 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  echo "  favourites(ratings_map, \"858\").length  == 158 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  echo "  favourites(ratings_map, \"260\").length  == 201 " | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  if (scala_assert "danube.scala" "danube_test4.scala") 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
    echo "  --> success" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
    marks=$(( marks + 1 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
    echo "  --> one of the tests failed" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
### danube suggestions tests
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
if [ $tsts -eq 0 ]
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  echo "  val good_ratings = process_ratings(ratings)" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  echo "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  echo "  suggestions(ratings_map, \"912\").length  == 4110 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  echo "  suggestions(ratings_map, \"858\").length  == 4883 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  echo "  suggestions(ratings_map, \"260\").length  == 4970 " | tee -a $out  
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  if (scala_assert "danube.scala" "danube_test5.scala") 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
    echo "  --> success" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
    marks=$(( marks + 1 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
    echo "  --> one of the tests failed" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
### danube recommendation tests
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
if [ $tsts -eq 0 ]
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  echo "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  echo "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  echo "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  echo "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  echo "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  if (scala_assert "danube.scala" "danube_test6.scala") 
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  then
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
    echo "  --> success" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
    marks=$(( marks + 1 ))
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  else
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
    echo "  --> one of the tests failed" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
fi
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
## final marks
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
echo "Overall mark for CW 7, Part 3" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
echo "$marks" | tee -a $out
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157