marking2/danube_test2.sh
changeset 259 43995ea34fe7
child 260 b4812c877b05
equal deleted inserted replaced
258:ebe71908b13e 259:43995ea34fe7
       
     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 ### compilation test
       
    54 
       
    55 
       
    56 if  [ $tsts0 -eq 0 ]
       
    57 then 
       
    58   echo "danube.scala runs?" | tee -a $out  
       
    59 
       
    60   if (scala_compile danube.scala)
       
    61   then
       
    62     echo -e "  --> success" | tee -a $out  
       
    63     tsts=$(( 0 ))
       
    64   else
       
    65     echo "  --> scala danube.scala did not run successfully" | tee -a $out  
       
    66     tsts=$(( 1 )) 
       
    67   fi
       
    68 else
       
    69   tsts=$(( 1 ))     
       
    70 fi
       
    71 
       
    72 ### danube groupById test
       
    73 
       
    74 if [ $tsts -eq 0 ]
       
    75 then
       
    76   echo "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
       
    77   echo "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
       
    78   echo "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
       
    79   echo "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
       
    80   echo "      where the order in the lists is unimportant" | tee -a $out
       
    81   echo "  val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
       
    82   echo "  val ls4 = ls3 zip ls3.tail" | tee -a $out
       
    83   echo "  val ls5 = ls4 ::: ls4.reverse" | tee -a $out
       
    84   echo "  groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
       
    85 
       
    86   if (scala_assert "danube.scala" "danube_test3.scala")
       
    87   then
       
    88       echo -e "  --> success" | tee -a $out
       
    89       marks=$(( marks + 1 ))
       
    90   else
       
    91       echo -e "  --> test failed" | tee -a $out
       
    92   fi
       
    93 fi
       
    94 
       
    95 ### danube favourites tests
       
    96 
       
    97 if [ $tsts -eq 0 ]
       
    98 then
       
    99   echo "  val good_ratings = process_ratings(ratings)" | tee -a $out
       
   100   echo "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
       
   101   echo "  favourites(ratings_map, \"912\").length  == 80 " | tee -a $out
       
   102   echo "  favourites(ratings_map, \"858\").length  == 158 " | tee -a $out
       
   103   echo "  favourites(ratings_map, \"260\").length  == 201 " | tee -a $out  
       
   104 
       
   105   if (scala_assert "danube.scala" "danube_test4.scala") 
       
   106   then
       
   107     echo "  --> success" | tee -a $out
       
   108     marks=$(( marks + 1 ))
       
   109   else
       
   110     echo "  --> one of the tests failed" | tee -a $out
       
   111   fi
       
   112 fi
       
   113 
       
   114 ### danube suggestions tests
       
   115 
       
   116 if [ $tsts -eq 0 ]
       
   117 then
       
   118   echo "  val good_ratings = process_ratings(ratings)" | tee -a $out
       
   119   echo "  val ratings_map = groupById(good_ratings, Map())" | tee -a $out
       
   120   echo "  suggestions(ratings_map, \"912\").length  == 4110 " | tee -a $out
       
   121   echo "  suggestions(ratings_map, \"858\").length  == 4883 " | tee -a $out
       
   122   echo "  suggestions(ratings_map, \"260\").length  == 4970 " | tee -a $out  
       
   123 
       
   124   if (scala_assert "danube.scala" "danube_test5.scala") 
       
   125   then
       
   126     echo "  --> success" | tee -a $out
       
   127     marks=$(( marks + 1 ))
       
   128   else
       
   129     echo "  --> one of the tests failed" | tee -a $out
       
   130   fi
       
   131 fi
       
   132 
       
   133 ### danube recommendation tests
       
   134 
       
   135 if [ $tsts -eq 0 ]
       
   136 then
       
   137   echo "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " | tee -a $out
       
   138   echo "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " | tee -a $out
       
   139   echo "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " | tee -a $out
       
   140   echo "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " | tee -a $out
       
   141   echo "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " | tee -a $out
       
   142 
       
   143   if (scala_assert "danube.scala" "danube_test6.scala") 
       
   144   then
       
   145     echo "  --> success" | tee -a $out
       
   146     marks=$(( marks + 1 ))
       
   147   else
       
   148     echo "  --> one of the tests failed" | tee -a $out
       
   149   fi
       
   150 fi
       
   151 
       
   152 
       
   153 ## final marks
       
   154 echo "Overall mark for CW 7, Part 3" | tee -a $out
       
   155 echo "$marks" | tee -a $out
       
   156