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