marking2/docdiff_test.sh
author Christian Urban <urbanc@in.tum.de>
Tue, 19 Nov 2019 06:38:10 +0000
changeset 321 7b0055205ec9
parent 283 ef5f62bf5987
child 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
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   104
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   107
    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
### docdiff prod tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   115
  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
   116
  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
   117
  echo -e "  " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   118
  echo -e "  prod(l1, l2) == 7 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   119
  echo -e "  prod(l1, l1) == 7 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   120
  echo -e "  prod(l2, l2) == 13 " |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   124
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   127
    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
### docdiff overlap tests
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
if [ $tsts -eq 0 ]
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   135
  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
   136
  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
   137
  echo -e "  " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   138
  echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   139
  echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   140
  echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   144
      echo -e "  --> success" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
      marks=$(( marks + 1 ))
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   147
      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
fi
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
## final marks
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   153
echo -e "Overall mark for the Preliminary Part" | tee -a $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   154
echo -e " $marks" | tee -a $out
227
b5f3e814a710 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155