testing2/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 15 Nov 2018 03:35:38 +0000
changeset 202 f7bcb27d1940
parent 168 03530cb87cd0
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
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
168
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents: 153
diff changeset
    23
# not sure yet what the right kind of stack should be
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents: 153
diff changeset
    24
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_assert {
168
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents: 153
diff changeset
    26
    (ulimit -t 20 ; JAVA_OPTS="-Xmx1g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
# purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
function scala_vars {
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    32
   (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
    33
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
# knights3: purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
#
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
echo "knight3.scala does not contain vars, returns etc?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
if (scala_vars knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    42
  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
    43
  tsts0=$(( 1 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  tsts0=$(( 0 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
# compilation test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
if  [ $tsts0 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
then    
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  echo "knight3.scala runs?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  if (scala_compile knight3.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
    tsts1=$(( 0 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    echo "  --> scala knight3.scala did not run successfully" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    tsts1=$(( 1 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  tsts1=$(( 1 ))     
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
# ordered move test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    71
  echo "Takes 20 seconds or less to execute: " >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  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
    73
  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
    74
  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
    75
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  if (scala_assert "knight3.scala" "knight3a_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
# first-closed-tour test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  if (scala_assert "knight3.scala" "knight3b_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
then
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
   103
  echo "Takes 20 seconds or less to execute: " >> $out
145
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  echo " first_tour_heuristic(8, List((0,0))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  echo " first_tour_heuristic(40, List((0,0))) found and ok?" >> $out
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 (scala_assert "knight3.scala" "knight3c_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
## final marks
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
##echo "Overall mark for CW 7, Part 2" | tee -a $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
##echo "$marks" | tee -a $out