testing3/testing3-bak/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 31 Oct 2019 09:20:32 +0000
changeset 293 f4f2227ac957
parent 245 975d34506e88
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
     2
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
     3
# to make the script fail safely
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
     4
set -euo pipefail
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
     5
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    11
echo "Below is the feedback and provisional marks for your submission" >> $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    12
echo "for assignment 7 Part 2.  Please note all marks are provisional until" >> $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    13
echo "ratified by the assessment board -- this is not an official" >> $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    14
echo "results transcript." >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    17
# marks for CW7 part 2
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    18
marks=$(( 0 ))
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# compilation tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
function scala_compile {
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    23
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
# functional tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    28
function scala_assert {
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    29
    (ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    30
}
168
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents: 153
diff changeset
    31
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
# purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
function scala_vars {
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    36
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
# knights3: purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
#
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    42
echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    43
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
if (scala_vars knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    47
  echo "  --> test failed" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  tsts0=$(( 1 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
else
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    50
  echo "  --> success" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  tsts0=$(( 0 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
# compilation test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
if  [ $tsts0 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
then    
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    58
  echo "knight3.scala runs?" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  if (scala_compile knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    62
    echo "  --> success" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    tsts1=$(( 0 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  else
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    65
    echo "  --> scala knight3.scala did not run successfully" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    tsts1=$(( 1 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  tsts1=$(( 1 ))     
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
# ordered move test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    76
  echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    77
  echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    78
  echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  if (scala_assert "knight3.scala" "knight3a_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    82
      echo "  --> success" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    83
      marks=$(( marks + 1 ))
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  else
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    85
    echo "  --> test failed" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
# first-closed-tour test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    94
  echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  if (scala_assert "knight3.scala" "knight3b_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    98
      echo "  --> success" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    99
      marks=$(( marks + 1 ))
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  else
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   101
      echo "  --> test failed" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   109
  echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   110
  echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  if (scala_assert "knight3.scala" "knight3c_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  then
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   114
      echo "  --> success" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   115
      marks=$(( marks + 1 ))
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  else
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   117
    echo "  --> test failed" | tee -a $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
## final marks
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   123
echo "Overall mark for CW 7, Part 2" | tee -a $out
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   124
echo "$marks" | tee -a $out