|         |      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 1 + 2.  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 echo "Below is the feedback for your submission docdiff.scala" >> $out | 
|         |     18 echo "" >> $out | 
|         |     19  | 
|         |     20 # marks for CW7 parts 1 + 2 | 
|         |     21 marks=$(( 0 )) | 
|         |     22  | 
|         |     23  | 
|         |     24 # compilation tests | 
|         |     25  | 
|         |     26 function scala_compile { | 
|         |     27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)  | 
|         |     28 } | 
|         |     29  | 
|         |     30 # functional tests | 
|         |     31  | 
|         |     32 function scala_assert { | 
|         |     33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) | 
|         |     34 } | 
|         |     35  | 
|         |     36 # purity test | 
|         |     37  | 
|         |     38 function scala_vars { | 
|         |     39    (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) | 
|         |     40 } | 
|         |     41  | 
|         |     42  | 
|         |     43 # var, .par return, ListBuffer test | 
|         |     44 # | 
|         |     45 echo "docdiff.scala does not contain vars, returns etc?" |  tee -a $out | 
|         |     46  | 
|         |     47 if (scala_vars docdiff.scala) | 
|         |     48 then | 
|         |     49   echo "  --> test failed" | tee -a $out   | 
|         |     50   tsts0=$(( 1 )) | 
|         |     51 else | 
|         |     52   echo "  --> success" |  tee -a $out | 
|         |     53   tsts0=$(( 0 ))  | 
|         |     54 fi | 
|         |     55  | 
|         |     56 ### compilation test | 
|         |     57  | 
|         |     58  | 
|         |     59 if  [ $tsts0 -eq 0 ] | 
|         |     60 then  | 
|         |     61   echo "docdiff.scala runs?" |  tee -a $out | 
|         |     62  | 
|         |     63   if (scala_compile docdiff.scala) | 
|         |     64   then | 
|         |     65     echo "  --> success" |  tee -a $out | 
|         |     66     tsts=$(( 0 )) | 
|         |     67   else | 
|         |     68     echo "  --> scala did not run docdiff.scala" |  tee -a $out | 
|         |     69     tsts=$(( 1 ))  | 
|         |     70   fi | 
|         |     71 else | 
|         |     72   tsts=$(( 1 ))      | 
|         |     73 fi | 
|         |     74  | 
|         |     75 ### docdiff clean tests | 
|         |     76  | 
|         |     77 if [ $tsts -eq 0 ] | 
|         |     78 then | 
|         |     79   echo "docdiff.scala tests:" |  tee -a $out | 
|         |     80   echo "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out | 
|         |     81   echo "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out | 
|         |     82  | 
|         |     83   if (scala_assert "docdiff.scala" "docdiff_test1.scala") | 
|         |     84   then | 
|         |     85       echo "  --> success" |  tee -a $out | 
|         |     86       marks=$(( marks + 1 )) | 
|         |     87   else | 
|         |     88     echo "  --> one of the tests failed" |  tee -a $out | 
|         |     89   fi | 
|         |     90 fi | 
|         |     91  | 
|         |     92 ### docdiff occurrences tests | 
|         |     93  | 
|         |     94 if [ $tsts -eq 0 ] | 
|         |     95 then | 
|         |     96   echo "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out | 
|         |     97   echo "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out | 
|         |     98   echo "  " |  tee -a $out | 
|         |     99   echo "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out | 
|         |    100   echo "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out | 
|         |    101  | 
|         |    102   if (scala_assert "docdiff.scala" "docdiff_test2.scala")  | 
|         |    103   then | 
|         |    104       echo "  --> success" |  tee -a $out | 
|         |    105       marks=$(( marks + 1 )) | 
|         |    106   else | 
|         |    107     echo "  --> one of the tests failed" |  tee -a $out | 
|         |    108   fi | 
|         |    109 fi | 
|         |    110  | 
|         |    111 ### docdiff prod tests | 
|         |    112  | 
|         |    113 if [ $tsts -eq 0 ] | 
|         |    114 then | 
|         |    115   echo "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out | 
|         |    116   echo "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out | 
|         |    117   echo "  " |  tee -a $out | 
|         |    118   echo "  prod(l1, l2) == 7 " |  tee -a $out | 
|         |    119   echo "  prod(l1, l1) == 7 " |  tee -a $out | 
|         |    120   echo "  prod(l2, l2) == 13 " |  tee -a $out | 
|         |    121  | 
|         |    122   if (scala_assert "docdiff.scala" "docdiff_test3.scala")  | 
|         |    123   then | 
|         |    124       echo "  --> success" |  tee -a $out | 
|         |    125       marks=$(( marks + 1 )) | 
|         |    126   else | 
|         |    127     echo "  --> one of the tests failed" |  tee -a $out | 
|         |    128   fi | 
|         |    129 fi | 
|         |    130  | 
|         |    131 ### docdiff overlap tests | 
|         |    132  | 
|         |    133 if [ $tsts -eq 0 ] | 
|         |    134 then | 
|         |    135   echo "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out | 
|         |    136   echo "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out | 
|         |    137   echo "  " |  tee -a $out | 
|         |    138   echo "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out | 
|         |    139   echo "  overlap(l1, l1) == 1.0 " |  tee -a $out | 
|         |    140   echo "  overlap(l2, l2) == 1.0 " |  tee -a $out | 
|         |    141  | 
|         |    142   if (scala_assert "docdiff.scala" "docdiff_test4.scala")  | 
|         |    143   then | 
|         |    144       echo "  --> success" |  tee -a $out | 
|         |    145       marks=$(( marks + 1 )) | 
|         |    146   else | 
|         |    147     echo "  --> one of the tests failed" |  tee -a $out | 
|         |    148   fi | 
|         |    149 fi | 
|         |    150  | 
|         |    151  | 
|         |    152 ## final marks | 
|         |    153 echo "Overall mark for Part 1" | tee -a $out | 
|         |    154 echo " $marks" | tee -a $out | 
|         |    155  |