testing2/knight1_test.sh
author Christian Urban <urbanc@in.tum.de>
Fri, 17 Nov 2017 09:13:03 +0000
changeset 148 ead6089209ba
parent 145 d306102fd33b
child 152 114a89518aea
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 1 and 2." >> $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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
# compilation tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
function scala_compile {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# functional tests
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_assert {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  (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
    22
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_vars {
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
   (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
    28
}
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# knights1: purity test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
echo "knight1.scala does not contain vars, returns etc?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
if (scala_vars knight1.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  echo "  --> fail" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  tsts0=$(( 1 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  tsts0=$(( 0 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# compilation test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
if [ $tsts0 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
then    
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  echo "knight1.scala runs?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  if (scala_compile knight1.scala)
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 "  --> success " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
    tsts1=$(( 0 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    echo "  --> scala did not run knight1.scala" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    tsts1=$(( 1 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  fi
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
  tsts1=$(( 1 ))   
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
### knight1a test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    echo " is_legal(8, Nil) (3, 4) == true " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
    echo " is_legal(8, List((4, 1), (1, 0))) (4, 1) == false " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    echo " is_legal(2, Nil) (0, 0) == true" >> $out                          
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    if (scala_assert "knight1.scala" "knight1a_test.scala")
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
        echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
    else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
        echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
### knight1b test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $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 "knight1.scala" "knight1b_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
### knight1c test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  echo " all_tours from every position on the board" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  echo " dim = 1: 1" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  echo "       2: 0,0,0,0" >>  $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  echo "       3: 0,0,0,0,0,0,0,0,0" >>  $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  echo "       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
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  if (scala_assert "knight1.scala" "knight1c_test.scala") 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
# knights2: var test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
echo "knight2.scala does not contain vars, returns etc?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
if (scala_vars knight2.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  echo "  --> fail" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  tsts0=$(( 1 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  tsts0=$(( 0 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
# compilation test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
if  [ $tsts0 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
then    
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  echo "knight2.scala runs?" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  if (scala_compile knight2.scala)
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
    tsts1=$(( 0 ))
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
    echo "  --> scala did not run knight2.scala" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
    tsts1=$(( 1 )) 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  tsts1=$(( 1 ))     
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
### knight2a test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  echo "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  echo "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  if (scala_assert "knight2.scala" "knight2a_test.scala") 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
### knight2b test
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
if [ $tsts1 -eq 0 ]
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  echo " is first_tour(8, (0, 0)) ok? " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  echo " is first_tour(4, (0, 0)) == None " >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  if (scala_assert "knight2.scala" "knight2b_test.scala") 
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
  then
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
    echo "  --> success" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  else
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
    echo "  --> test failed" >> $out
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
fi
d306102fd33b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183