testing2/docdiff_test.sh
author Christian Urban <urbanc@in.tum.de>
Sat, 02 Nov 2019 13:19:45 +0000
changeset 304 4a9d1153ccc5
parent 283 ef5f62bf5987
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 {
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    18
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $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 {
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    24
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 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 {
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
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
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# var, .par return, ListBuffer test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
#
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
echo "docdiff.scala does not contain vars, returns etc?" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
if (scala_vars docdiff.scala)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    40
  echo -e "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 ))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    43
  echo -e "  --> success" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  tsts0=$(( 0 )) 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
### compilation test
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
if  [ $tsts0 -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  echo "docdiff.scala runs?" >> $out
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  if (scala_compile docdiff.scala)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    56
    echo -e "  --> success" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    tsts=$(( 0 ))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    59
    echo -e "  --> SCALA DID NOT RUN docdiff.scala" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    tsts=$(( 1 )) 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
else
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  tsts=$(( 1 ))     
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
### docdiff clean tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    70
  echo -e "docdiff.scala tests:" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    71
  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    72
  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    76
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    78
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
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
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
### docdiff occurrences tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    86
  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    87
  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    88
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    89
  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    90
  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    94
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    96
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
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
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
### docdiff prod tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   104
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   105
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   106
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   107
  echo -e "  prod(l1, l2) == 7 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   108
  echo -e "  prod(l1, l1) == 7 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   109
  echo -e "  prod(l2, l2) == 13 " >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   113
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   115
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
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
fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
### docdiff overlap tests
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
if [ $tsts -eq 0 ]
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   123
  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   124
  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   125
  echo -e "  " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   126
  echo -e "  overlap(l1, l2) == 0.5384615384615384 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   127
  echo -e "  overlap(l1, l1) == 1.0 " >> $out
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   128
  echo -e "  overlap(l2, l2) == 1.0 " >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  then
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   132
    echo -e "  --> success\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  else
283
ef5f62bf5987 updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   134
    echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  fi
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
fi