marking2/docdiff_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 24 Nov 2020 23:36:21 +0000
changeset 367 e6ae724255a8
parent 323 1f8005b4cdf6
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    11
echo -e "Below is the feedback and provisional marks for your submission" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    12
echo -e "for the Preliminary Part of Assignemnt 7.  Please note all marks are provisional until" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    13
echo -e "ratified by the assessment board -- this is not an official" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    14
echo -e "results transcript." >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    15
echo -e "" >> $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    17
echo -e "Below is the feedback for your submission docdiff.scala" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    18
echo -e "" >> $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# marks for CW7 parts 1 + 2
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
marks=$(( 0 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# compilation tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_compile {
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    27
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
# functional tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
function scala_assert {
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    33
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
# purity test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
function scala_vars {
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
   (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
}
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
# var, .par return, ListBuffer test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
#
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    45
echo -e "docdiff.scala does not contain vars, returns etc?" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
if (scala_vars docdiff.scala)
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    49
  echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" | tee -a $out  
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  tsts0=$(( 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    52
  echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  tsts0=$(( 0 )) 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
### compilation test
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
if  [ $tsts0 -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
then 
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    61
  echo -e "docdiff.scala runs?" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  if (scala_compile docdiff.scala)
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    65
    echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    tsts=$(( 0 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    68
    echo -e "  --> scala did not run docdiff.scala" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    tsts=$(( 1 )) 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
else
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  tsts=$(( 1 ))     
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
### docdiff clean tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    79
  echo -e "docdiff.scala tests:" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    80
  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    81
  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    85
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    88
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
### docdiff occurrences tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    96
  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    97
  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    98
  echo -e "  " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    99
  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   100
  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
323
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   101
  echo -e "  " |  tee -a $out
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   102
  echo -e "  occurrences(Nil) == Map() " |  tee -a $out
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   103
  echo -e "  " |  tee -a $out
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   104
  echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   108
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   111
    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
### docdiff prod tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   119
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   120
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   121
  echo -e "  " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   122
  echo -e "  prod(l1, l2) == 7 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   123
  echo -e "  prod(l1, l1) == 7 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   124
  echo -e "  prod(l2, l2) == 13 " |  tee -a $out
323
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   125
  echo -e "  " |  tee -a $out
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   126
  echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
1f8005b4cdf6 updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   127
  echo -e "  prod(l1, l3) == 0 " |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   131
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   134
    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
### docdiff overlap tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   142
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   143
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   144
  echo -e "  " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   145
  echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   146
  echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   147
  echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   151
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   154
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
## final marks
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   160
echo -e "Overall mark for the Preliminary Part" | tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   161
echo -e " $marks" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162