| 382 |      1 | #!/bin/zsh
 | 
| 227 |      2 | 
 | 
|  |      3 | # to make the script fail safely
 | 
|  |      4 | set -euo pipefail
 | 
|  |      5 | 
 | 
|  |      6 | 
 | 
|  |      7 | out=${1:-output}
 | 
|  |      8 | 
 | 
|  |      9 | echo "" > $out
 | 
|  |     10 | 
 | 
| 382 |     11 | echo `date` >> $out
 | 
| 283 |     12 | echo -e "Below is the feedback and provisional marks for your submission" >> $out
 | 
| 382 |     13 | echo -e "for the Preliminary Part of Part 2 (Scala).  Please note all marks are provisional until" >> $out
 | 
| 283 |     14 | echo -e "ratified by the assessment board -- this is not an official" >> $out
 | 
|  |     15 | echo -e "results transcript." >> $out
 | 
|  |     16 | echo -e "" >> $out
 | 
| 227 |     17 | 
 | 
| 283 |     18 | echo -e "Below is the feedback for your submission docdiff.scala" >> $out
 | 
|  |     19 | echo -e "" >> $out
 | 
| 227 |     20 | 
 | 
| 382 |     21 | # marks for CW7 preliminary part
 | 
|  |     22 | marks=$(( 0.0 ))
 | 
| 227 |     23 | 
 | 
|  |     24 | 
 | 
|  |     25 | # compilation tests
 | 
|  |     26 | 
 | 
|  |     27 | function scala_compile {
 | 
| 382 |     28 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
 | 
| 227 |     29 | }
 | 
|  |     30 | 
 | 
|  |     31 | # functional tests
 | 
|  |     32 | 
 | 
|  |     33 | function scala_assert {
 | 
| 382 |     34 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 227 |     35 | }
 | 
|  |     36 | 
 | 
|  |     37 | # purity test
 | 
|  |     38 | 
 | 
|  |     39 | function scala_vars {
 | 
| 382 |     40 |    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
 | 
| 227 |     41 | }
 | 
|  |     42 | 
 | 
|  |     43 | 
 | 
| 382 |     44 | ### compilation test
 | 
|  |     45 | 
 | 
|  |     46 | echo -e "docdiff.scala runs?" |  tee -a $out
 | 
|  |     47 | 
 | 
|  |     48 | if (scala_compile docdiff.scala)
 | 
|  |     49 | then
 | 
|  |     50 |     echo -e "  --> success" |  tee -a $out
 | 
|  |     51 |     tsts=$(( 0 ))
 | 
|  |     52 | else
 | 
|  |     53 |     echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" |  tee -a $out
 | 
|  |     54 |     tsts=$(( 1 )) 
 | 
|  |     55 | fi
 | 
|  |     56 | 
 | 
|  |     57 | 
 | 
| 227 |     58 | # var, .par return, ListBuffer test
 | 
|  |     59 | #
 | 
|  |     60 | 
 | 
| 382 |     61 | if  [ $tsts -eq 0 ]
 | 
|  |     62 | then     
 | 
|  |     63 |    echo -e "docdiff.scala does not contain VARS, RETURNS etc?" |  tee -a $out
 | 
| 227 |     64 | 
 | 
| 382 |     65 |    if (scala_vars docdiff.scala)
 | 
|  |     66 |    then
 | 
|  |     67 |       echo -e "  --> test failed\n" | tee -a $out  
 | 
|  |     68 |       tsts=$(( 1 ))
 | 
|  |     69 |    else
 | 
|  |     70 |       echo -e "  --> success" |  tee -a $out
 | 
|  |     71 |       tsts=$(( 0 )) 
 | 
|  |     72 |    fi
 | 
|  |     73 | else
 | 
|  |     74 |    tsts=$(( 1 ))  
 | 
|  |     75 | fi 
 | 
| 227 |     76 | 
 | 
| 382 |     77 | echo >> $out
 | 
|  |     78 | 
 | 
| 227 |     79 | 
 | 
|  |     80 | ### docdiff clean tests
 | 
|  |     81 | 
 | 
|  |     82 | if [ $tsts -eq 0 ]
 | 
|  |     83 | then
 | 
| 283 |     84 |   echo -e "docdiff.scala tests:" |  tee -a $out
 | 
|  |     85 |   echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
 | 
|  |     86 |   echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
 | 
| 227 |     87 | 
 | 
|  |     88 |   if (scala_assert "docdiff.scala" "docdiff_test1.scala")
 | 
|  |     89 |   then
 | 
| 283 |     90 |       echo -e "  --> success" |  tee -a $out
 | 
| 382 |     91 |       marks=$(( marks + 0.5 ))
 | 
| 227 |     92 |   else
 | 
| 283 |     93 |       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
 | 
| 227 |     94 |   fi
 | 
|  |     95 | fi
 | 
|  |     96 | 
 | 
|  |     97 | ### docdiff occurrences tests
 | 
|  |     98 | 
 | 
|  |     99 | if [ $tsts -eq 0 ]
 | 
|  |    100 | then
 | 
| 283 |    101 |   echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
 | 
|  |    102 |   echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
 | 
|  |    103 |   echo -e "  " |  tee -a $out
 | 
|  |    104 |   echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
 | 
|  |    105 |   echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
 | 
| 323 |    106 |   echo -e "  " |  tee -a $out
 | 
|  |    107 |   echo -e "  occurrences(Nil) == Map() " |  tee -a $out
 | 
|  |    108 |   echo -e "  " |  tee -a $out
 | 
|  |    109 |   echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
 | 
| 227 |    110 | 
 | 
|  |    111 |   if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
 | 
|  |    112 |   then
 | 
| 283 |    113 |       echo -e "  --> success" |  tee -a $out
 | 
| 382 |    114 |       marks=$(( marks + 1.0 ))
 | 
| 227 |    115 |   else
 | 
| 382 |    116 |       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
 | 
| 227 |    117 |   fi
 | 
|  |    118 | fi
 | 
|  |    119 | 
 | 
|  |    120 | ### docdiff prod tests
 | 
|  |    121 | 
 | 
|  |    122 | if [ $tsts -eq 0 ]
 | 
|  |    123 | then
 | 
| 283 |    124 |   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
 | 
|  |    125 |   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
 | 
|  |    126 |   echo -e "  " |  tee -a $out
 | 
|  |    127 |   echo -e "  prod(l1, l2) == 7 " |  tee -a $out
 | 
|  |    128 |   echo -e "  prod(l1, l1) == 7 " |  tee -a $out
 | 
|  |    129 |   echo -e "  prod(l2, l2) == 13 " |  tee -a $out
 | 
| 323 |    130 |   echo -e "  " |  tee -a $out
 | 
|  |    131 |   echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
 | 
|  |    132 |   echo -e "  prod(l1, l3) == 0 " |  tee -a $out
 | 
| 227 |    133 | 
 | 
|  |    134 |   if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
 | 
|  |    135 |   then
 | 
| 283 |    136 |       echo -e "  --> success" |  tee -a $out
 | 
| 382 |    137 |       marks=$(( marks + 1.0 ))
 | 
| 227 |    138 |   else
 | 
| 382 |    139 |       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
 | 
| 227 |    140 |   fi
 | 
|  |    141 | fi
 | 
|  |    142 | 
 | 
|  |    143 | ### docdiff overlap tests
 | 
|  |    144 | 
 | 
|  |    145 | if [ $tsts -eq 0 ]
 | 
|  |    146 | then
 | 
| 283 |    147 |   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
 | 
|  |    148 |   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
 | 
|  |    149 |   echo -e "  " |  tee -a $out
 | 
|  |    150 |   echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
 | 
|  |    151 |   echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
 | 
|  |    152 |   echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
 | 
| 227 |    153 | 
 | 
|  |    154 |   if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
 | 
|  |    155 |   then
 | 
| 283 |    156 |       echo -e "  --> success" |  tee -a $out
 | 
| 382 |    157 |       marks=$(( marks + 0.5 ))
 | 
| 227 |    158 |   else
 | 
| 283 |    159 |       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
 | 
| 227 |    160 |   fi
 | 
|  |    161 | fi
 | 
|  |    162 | 
 | 
|  |    163 | 
 | 
|  |    164 | ## final marks
 | 
| 382 |    165 | echo -e "Overall mark for the Preliminary Part 2 (Scala)" | tee -a $out
 | 
|  |    166 | printf " %0.1f\n" $marks | tee -a $out
 | 
| 227 |    167 | 
 | 
| 382 |    168 | 
 | 
|  |    169 | #echo -e " $marks" | tee -a $out
 | 
|  |    170 | 
 |