testing3/knight2_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 31 Oct 2019 09:49:33 +0000
changeset 295 3f34da7a3094
parent 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
295
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    11
echo -e "Below is the feedback for your submission of CW 8, Core Part." >> $out
248
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 {
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
    19
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
247
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
295
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    24
function scala_assert_slow {
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    25
  (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "-- $2" 2> /dev/null 1> /dev/null)
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
}
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
295
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    28
function scala_assert_thirty {
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    29
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    30
}
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    31
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    32
function scala_assert_quick {
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    33
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2"  2> /dev/null 1> /dev/null)
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    34
}
247
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
# purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
function scala_vars {
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
   (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
    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
295
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    44
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    45
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    46
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    47
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    48
3f34da7a3094 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    49
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
# knights2: purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
#
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    52
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
    53
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
if (scala_vars knight2.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    57
  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
    58
  tsts0=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
else
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
  tsts0=$(( 0 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
# compilation test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
if  [ $tsts0 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
then    
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    68
  echo -e "knight2.scala runs?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  if (scala_compile knight2.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    72
    echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    tsts1=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo -e "  --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    tsts1=$(( 1 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  tsts1=$(( 1 ))     
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
# ordered move test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    86
  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
    87
  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
    88
  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
    89
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  if (scala_assert "knight2.scala" "knight_test6.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    92
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
      echo -e "  --> \n ONE TEST FAILED\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
# first-closed-tour test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   103
  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
   104
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  if (scala_assert "knight2.scala" "knight_test7.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   107
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
      echo -e "  --> \n ONE TEST FAILED\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   117
  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
   118
  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
   119
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  if (scala_assert "knight2.scala" "knight_test8.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   122
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      echo -e "  --> \n ONE TEST FAILED\n" >> $out 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
# knights3: purity test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
#
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   131
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
   132
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
if (scala_vars knight3.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   136
  echo "  --> test failed" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  tsts0=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
else
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
  tsts0=$(( 0 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
# compilation test
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
if  [ $tsts0 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
then    
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   147
  echo "knight3.scala runs?" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  if (scala_compile knight3.scala)
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   151
    echo "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
    tsts1=$(( 0 ))
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
    echo -e "  --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
    tsts1=$(( 1 )) 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  fi
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
  tsts1=$(( 1 ))     
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
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
if [ $tsts1 -eq 0 ]
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   164
  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
   165
  
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  if (scala_assert "knight3.scala" "knight_test9.scala")
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  then
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
   168
      echo -e "  --> success" >> $out
247
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  else
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
      echo -e "  --> \n ONE TEST FAILED\n" >> $out 
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
  fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
fi
50a3b874008a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173