| 
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
  | 
| 
421
 | 
    13  | 
echo -e "for the Core 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  | 
  | 
| 
421
 | 
    21  | 
# marks for C2 core part
  | 
| 
382
 | 
    22  | 
marks=$(( 0.0 ))
  | 
| 
227
 | 
    23  | 
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
# compilation tests
  | 
| 
 | 
    26  | 
  | 
| 
 | 
    27  | 
function scala_compile {
 | 
| 
491
 | 
    28  | 
    (ulimit -t 30; scala-cli compile --server=false -color never -Xprint:parser "$1" 2> c$out 1> c$out)
  | 
| 
227
 | 
    29  | 
}
  | 
| 
 | 
    30  | 
  | 
| 
 | 
    31  | 
# functional tests
  | 
| 
 | 
    32  | 
  | 
| 
 | 
    33  | 
function scala_assert {
 | 
| 
491
 | 
    34  | 
  (ulimit -t 30; scala-cli --server=false -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null)
  | 
| 
227
 | 
    35  | 
}
  | 
| 
 | 
    36  | 
  | 
| 
 | 
    37  | 
# purity test
  | 
| 
421
 | 
    38  | 
function scala_vars {
 | 
| 
 | 
    39  | 
   (sed 's/immutable/ok/g' c$out > cb$out;
  | 
| 
 | 
    40  | 
    egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
  | 
| 
 | 
    41  | 
}
  | 
| 
227
 | 
    42  | 
  | 
| 
 | 
    43  | 
  | 
| 
 | 
    44  | 
  | 
| 
382
 | 
    45  | 
### compilation test
  | 
| 
 | 
    46  | 
  | 
| 
 | 
    47  | 
echo -e "docdiff.scala runs?" |  tee -a $out
  | 
| 
 | 
    48  | 
  | 
| 
 | 
    49  | 
if (scala_compile docdiff.scala)
  | 
| 
 | 
    50  | 
then
  | 
| 
 | 
    51  | 
    echo -e "  --> success" |  tee -a $out
  | 
| 
 | 
    52  | 
    tsts=$(( 0 ))
  | 
| 
 | 
    53  | 
else
  | 
| 
 | 
    54  | 
    echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" |  tee -a $out
  | 
| 
 | 
    55  | 
    tsts=$(( 1 )) 
  | 
| 
 | 
    56  | 
fi
  | 
| 
 | 
    57  | 
  | 
| 
 | 
    58  | 
  | 
| 
227
 | 
    59  | 
# var, .par return, ListBuffer test
  | 
| 
 | 
    60  | 
#
  | 
| 
 | 
    61  | 
  | 
| 
382
 | 
    62  | 
if  [ $tsts -eq 0 ]
  | 
| 
 | 
    63  | 
then     
  | 
| 
 | 
    64  | 
   echo -e "docdiff.scala does not contain VARS, RETURNS etc?" |  tee -a $out
  | 
| 
227
 | 
    65  | 
  | 
| 
382
 | 
    66  | 
   if (scala_vars docdiff.scala)
  | 
| 
 | 
    67  | 
   then
  | 
| 
 | 
    68  | 
      echo -e "  --> test failed\n" | tee -a $out  
  | 
| 
 | 
    69  | 
      tsts=$(( 1 ))
  | 
| 
 | 
    70  | 
   else
  | 
| 
 | 
    71  | 
      echo -e "  --> success" |  tee -a $out
  | 
| 
 | 
    72  | 
      tsts=$(( 0 )) 
  | 
| 
 | 
    73  | 
   fi
  | 
| 
 | 
    74  | 
else
  | 
| 
 | 
    75  | 
   tsts=$(( 1 ))  
  | 
| 
 | 
    76  | 
fi 
  | 
| 
227
 | 
    77  | 
  | 
| 
382
 | 
    78  | 
echo >> $out
  | 
| 
 | 
    79  | 
  | 
| 
227
 | 
    80  | 
  | 
| 
 | 
    81  | 
### docdiff clean tests
  | 
| 
 | 
    82  | 
  | 
| 
 | 
    83  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
    84  | 
then
  | 
| 
283
 | 
    85  | 
  echo -e "docdiff.scala tests:" |  tee -a $out
  | 
| 
 | 
    86  | 
  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
  | 
| 
 | 
    87  | 
  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
  | 
| 
227
 | 
    88  | 
  | 
| 
 | 
    89  | 
  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
  | 
| 
 | 
    90  | 
  then
  | 
| 
460
 | 
    91  | 
      echo -e "  --> success (+ 0.5 Marks)\n" |  tee -a $out
  | 
| 
382
 | 
    92  | 
      marks=$(( marks + 0.5 ))
  | 
| 
227
 | 
    93  | 
  else
  | 
| 
283
 | 
    94  | 
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
  | 
| 
227
 | 
    95  | 
  fi
  | 
| 
 | 
    96  | 
fi
  | 
| 
 | 
    97  | 
  | 
| 
 | 
    98  | 
### docdiff occurrences tests
  | 
| 
 | 
    99  | 
  | 
| 
 | 
   100  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   101  | 
then
  | 
| 
283
 | 
   102  | 
  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
  | 
| 
421
 | 
   103  | 
  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)"  |  tee -a $out
  | 
| 
283
 | 
   104  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   105  | 
  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
  | 
| 
 | 
   106  | 
  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
  | 
| 
323
 | 
   107  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   108  | 
  echo -e "  occurrences(Nil) == Map() " |  tee -a $out
  | 
| 
 | 
   109  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   110  | 
  echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
  | 
| 
227
 | 
   111  | 
  | 
| 
 | 
   112  | 
  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
  | 
| 
 | 
   113  | 
  then
  | 
| 
460
 | 
   114  | 
      echo -e "  --> success (+ 1 Mark)\n" |  tee -a $out
  | 
| 
382
 | 
   115  | 
      marks=$(( marks + 1.0 ))
  | 
| 
227
 | 
   116  | 
  else
  | 
| 
382
 | 
   117  | 
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
  | 
| 
227
 | 
   118  | 
  fi
  | 
| 
 | 
   119  | 
fi
  | 
| 
 | 
   120  | 
  | 
| 
 | 
   121  | 
### docdiff prod tests
  | 
| 
 | 
   122  | 
  | 
| 
 | 
   123  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   124  | 
then
  | 
| 
283
 | 
   125  | 
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
  | 
| 
 | 
   126  | 
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
  | 
| 
 | 
   127  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   128  | 
  echo -e "  prod(l1, l2) == 7 " |  tee -a $out
  | 
| 
 | 
   129  | 
  echo -e "  prod(l1, l1) == 7 " |  tee -a $out
  | 
| 
 | 
   130  | 
  echo -e "  prod(l2, l2) == 13 " |  tee -a $out
  | 
| 
323
 | 
   131  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   132  | 
  echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
  | 
| 
 | 
   133  | 
  echo -e "  prod(l1, l3) == 0 " |  tee -a $out
  | 
| 
227
 | 
   134  | 
  | 
| 
 | 
   135  | 
  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
  | 
| 
 | 
   136  | 
  then
  | 
| 
460
 | 
   137  | 
      echo -e "  --> success (+ 1 Mark)\n" |  tee -a $out
  | 
| 
382
 | 
   138  | 
      marks=$(( marks + 1.0 ))
  | 
| 
227
 | 
   139  | 
  else
  | 
| 
382
 | 
   140  | 
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
  | 
| 
227
 | 
   141  | 
  fi
  | 
| 
 | 
   142  | 
fi
  | 
| 
 | 
   143  | 
  | 
| 
 | 
   144  | 
### docdiff overlap tests
  | 
| 
 | 
   145  | 
  | 
| 
 | 
   146  | 
if [ $tsts -eq 0 ]
  | 
| 
 | 
   147  | 
then
  | 
| 
283
 | 
   148  | 
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
  | 
| 
 | 
   149  | 
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
  | 
| 
 | 
   150  | 
  echo -e "  " |  tee -a $out
  | 
| 
 | 
   151  | 
  echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
  | 
| 
 | 
   152  | 
  echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
  | 
| 
 | 
   153  | 
  echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
  | 
| 
227
 | 
   154  | 
  | 
| 
 | 
   155  | 
  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
  | 
| 
 | 
   156  | 
  then
  | 
| 
460
 | 
   157  | 
      echo -e "  --> success  (+ 0.5 Marks)\n" |  tee -a $out
  | 
| 
382
 | 
   158  | 
      marks=$(( marks + 0.5 ))
  | 
| 
227
 | 
   159  | 
  else
  | 
| 
283
 | 
   160  | 
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
  | 
| 
227
 | 
   161  | 
  fi
  | 
| 
 | 
   162  | 
fi
  | 
| 
 | 
   163  | 
  | 
| 
 | 
   164  | 
  | 
| 
 | 
   165  | 
## final marks
  | 
| 
421
 | 
   166  | 
echo -e "Overall mark for the Core Part 2 (Scala)" | tee -a $out
  | 
| 
382
 | 
   167  | 
printf " %0.1f\n" $marks | tee -a $out
  | 
| 
227
 | 
   168  | 
  | 
| 
382
 | 
   169  | 
  | 
| 
 | 
   170  | 
#echo -e " $marks" | tee -a $out
  | 
| 
 | 
   171  | 
  |