testing2/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 17 Nov 2017 14:11:58 +0000
changeset 151 c5ca7f8e21a5
parent 145 d306102fd33b
child 153 4383809c176a
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 {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
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 {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
    (ulimit -t 300 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
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 {
d306102fd33b 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)
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> fail" >> $out
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  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
    70
  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
    71
  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
    72
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  if (scala_assert "knight3.scala" "knight3a_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  fi
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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
# first-closed-tour test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  if (scala_assert "knight3.scala" "knight3b_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  fi
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
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
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  echo " first_tour_heuristic(8, List((0,0))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  echo " first_tour_heuristic(40, List((0,0))) found and ok?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  if (scala_assert "knight3.scala" "knight3c_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
## final marks
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
##echo "Overall mark for CW 7, Part 2" | tee -a $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
##echo "$marks" | tee -a $out