pre_testing2/docdiff_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 25 Nov 2020 17:28:48 +0000
changeset 369 569aea2d052b
parent 352 97bcf8efe4e0
child 376 6cc36d0ef79e
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "Below is the feedback for your submission docdiff.scala" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# compilation tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
function scala_compile {
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    18
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# functional tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_assert {
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    24
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# purity test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_vars {
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    30
   (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    34
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    35
### compilation test
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    36
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    37
echo -e "docdiff.scala runs?" >> $out
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    38
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    39
if (scala_compile docdiff.scala)
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    40
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 346
diff changeset
    41
    echo -e "  --> passed" >> $out
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    42
    tsts=$(( 0 ))
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    43
else
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    44
    echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" >> $out
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    45
    tsts=$(( 1 )) 
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    46
fi
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    47
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    48
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
# var, .par return, ListBuffer test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
#
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    51
echo -e "docdiff.scala does not contain vars, returns etc?" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    53
if  [ $tsts -eq 0 ]
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
then 
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    55
   if (scala_vars docdiff.scala)
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    56
   then
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    57
      echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" >> $out
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    58
      tsts=$(( 1 ))
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    59
   else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 346
diff changeset
    60
      echo -e "  --> passed" >> $out
346
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    61
      tsts=$(( 0 )) 
663c2a9108d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 283
diff changeset
    62
   fi
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
### docdiff clean tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    69
  echo -e "docdiff.scala tests:" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    70
  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    71
  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    75
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    77
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
### docdiff occurrences tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    85
  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    86
  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    87
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    88
  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    89
  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    93
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    95
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
### docdiff prod tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   103
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   104
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   105
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   106
  echo -e "  prod(l1, l2) == 7 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   107
  echo -e "  prod(l1, l1) == 7 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   108
  echo -e "  prod(l2, l2) == 13 " >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   112
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   114
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
### docdiff overlap tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   122
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   123
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   124
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   125
  echo -e "  overlap(l1, l2) == 0.5384615384615384 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   126
  echo -e "  overlap(l1, l1) == 1.0 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   127
  echo -e "  overlap(l2, l2) == 1.0 " >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   131
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   133
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
fi