testing2/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Tue, 05 Dec 2017 00:34:14 +0000
changeset 162 6d25ccbb3cf2
parent 153 4383809c176a
child 168 03530cb87cd0
permissions -rwxr-xr-x
marking 2
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -e
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo "" > $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo "Below is the feedback for your submission of CW 7, Part 3." >> $out
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
function scala_vars {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
   (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# compilation tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
function scala_compile {
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    18
  (ulimit -t 30 ; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# functional tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_assert {
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    24
    (ulimit -t 20 ; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_vars {
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    30
   (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
    31
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# knights3: purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
#
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
echo "knight3.scala does not contain vars, returns etc?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
if (scala_vars knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    40
  echo "  --> fail: if you do not fix this, you will receive a mark of zero" >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 1 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  tsts0=$(( 0 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
# compilation test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
if  [ $tsts0 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
then    
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  echo "knight3.scala runs?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  if (scala_compile knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    tsts1=$(( 0 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
    echo "  --> scala knight3.scala did not run successfully" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    tsts1=$(( 1 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  tsts1=$(( 1 ))     
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
# ordered move test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    69
  echo "Takes 20 seconds or less to execute: " >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  echo " ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
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 (scala_assert "knight3.scala" "knight3a_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
# first-closed-tour test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  if (scala_assert "knight3.scala" "knight3b_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
   101
  echo "Takes 20 seconds or less to execute: " >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  echo " first_tour_heuristic(8, List((0,0))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  echo " first_tour_heuristic(40, List((0,0))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  if (scala_assert "knight3.scala" "knight3c_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
## final marks
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
##echo "Overall mark for CW 7, Part 2" | tee -a $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
##echo "$marks" | tee -a $out