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