testing3/knight1_test.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 16 Jan 2019 12:24:47 +0000
changeset 254 cc0154804096
parent 220 3020f8c76baa
child 261 8997430d9765
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
220
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -euo pipefail
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo -e "" > $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo -e "Below is the feedback for your submission of CW 8, Part 1 and 2." >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo -e "" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
# compilation tests
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
function scala_compile {
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# functional tests
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_assert_slow {
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
function scala_assert_thirty {
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
function scala_assert_quick {
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
# purity test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
function scala_vars {
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
}
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
# knights1: purity test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
echo -e "knight1.scala does not contain vars, returns etc?" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
if (scala_vars knight1.scala)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  echo -e "  --> fail (make triple-sure your program conforms to the required format)" >> $out  
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  tsts0=$(( 0 ))
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 0 )) 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
# compilation test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
if [ $tsts0 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
then    
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  echo -e "knight1.scala runs?" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  if (scala_compile knight1.scala)
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    echo -e "  --> success " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    tsts1=$(( 0 ))
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    tsts1=$(( 1 )) 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  tsts1=$(( 1 ))   
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
### knight1 test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
if [ $tsts1 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo -e "Takes 10 seconds or less to execute: " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out                          
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
    if (scala_assert_quick "knight1.scala" "knight_test1.scala")
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
    then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
        echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
    else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
        echo -e "  --> \n ONE TEST FAILED\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
### knight2 test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
if [ $tsts1 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  echo -e "Takes 10 seconds or less to execute: " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  echo -e " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  echo -e " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  if (scala_assert_quick "knight1.scala" "knight_test2.scala")
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
### knight3 test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
if [ $tsts1 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  echo -e "Takes 10 seconds or less to execute: " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  echo -e " count_tours from every position on the board" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  echo -e " dim = 1: 1" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  echo -e "       2: 0,0,0,0" >>  $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  echo -e "       3: 0,0,0,0,0,0,0,0,0" >>  $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  echo -e "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  #echo -e "       5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  if (scala_assert_quick "knight1.scala" "knight_test3.scala") 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
    echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
### knight4 test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
if [ $tsts1 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  echo -e "Takes 10 seconds or less to execute: " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  if (scala_assert_quick "knight1.scala" "knight_test4.scala") 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
    echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
### knight5 test
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
if [ $tsts1 -eq 0 ]
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  echo -e "Takes 10 seconds or less to execute: " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  echo -e " is first_tour(4, List((0, 0))) == None " >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
  if (scala_assert_quick "knight1.scala" "knight_test5.scala") 
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  then
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
    echo -e "  --> success" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  else
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
fi
3020f8c76baa updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166