testing3/knight2_test.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 16 Jan 2019 12:24:47 +0000
changeset 254 cc0154804096
parent 249 1997cfcd6334
child 266 ca48ac1d3c3e
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    11
echo -e "Below is the feedback for your submission of CW 8, Advanced Part 2." >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    12
echo -e "" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    14
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
# compilation tests
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
function scala_compile {
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
}
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
# functional tests
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_assert {
249
1997cfcd6334 updated
Christian Urban <urbanc@in.tum.de>
parents: 248
diff changeset
    26
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
function scala_vars {
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
}
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
# knights2: purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
#
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    40
echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
if (scala_vars knight2.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    45
  echo -e "  --> fail (make triple-sure your program conforms to the required format)" >> $out    
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  tsts0=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
else
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    48
  echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 0 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
# compilation test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
if  [ $tsts0 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
then    
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    56
  echo -e "knight2.scala runs?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  if (scala_compile knight2.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    60
    echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    tsts1=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    echo -e "  --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts1=$(( 1 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  tsts1=$(( 1 ))     
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
# ordered move test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    74
  echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    75
  echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    76
  echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  if (scala_assert "knight2.scala" "knight_test6.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    80
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
      echo -e "  --> \n ONE TEST FAILED\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
# first-closed-tour test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    91
  echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  if (scala_assert "knight2.scala" "knight_test7.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    95
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
      echo -e "  --> \n ONE TEST FAILED\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   105
  echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   106
  echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  if (scala_assert "knight2.scala" "knight_test8.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   110
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
      echo -e "  --> \n ONE TEST FAILED\n" >> $out 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
# knights3: purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
#
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   119
echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
if (scala_vars knight3.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   124
  echo "  --> test failed" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  tsts0=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
else
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   127
  echo "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  tsts0=$(( 0 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
# compilation test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
if  [ $tsts0 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
then    
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   135
  echo "knight3.scala runs?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  if (scala_compile knight3.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   139
    echo "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
    tsts1=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
    echo -e "  --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
    tsts1=$(( 1 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  tsts1=$(( 1 ))     
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   152
  echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  if (scala_assert "knight3.scala" "knight_test9.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   156
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
      echo -e "  --> \n ONE TEST FAILED\n" >> $out 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161