marking3/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Sat, 02 Feb 2019 13:28:05 +0000
changeset 261 8997430d9765
parent 259 43995ea34fe7
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "Below is the feedback and provisional marks for your submission" >> $out
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    12
echo "for assignment 8 Advanced Part 2.  Please note all marks are provisional until" >> $out
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "ratified by the assessment board -- this is not an official" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "results transcript." >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    17
# marks for CW8 part 2
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
marks=$(( 0 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# compilation tests
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
function scala_compile {
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    23
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
# functional tests
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
function scala_assert {
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    29
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    32
function scala_assert_long {
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    33
  (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    34
}
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    35
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    36
function scala_assert_elong {
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    37
  (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    38
}
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
# purity test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
function scala_vars {
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    47
# knights2: purity test
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
#
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    49
echo "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    52
if (scala_vars knight2.scala)
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  tsts0=$(( 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  tsts0=$(( 0 )) 
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
# compilation test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
if  [ $tsts0 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
then    
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    65
  echo "knight2.scala runs?" | tee -a $out
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    67
  if (scala_compile knight2.scala)
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
    tsts1=$(( 0 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  else
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    72
    echo "  --> scala knight2.scala did not run successfully" | tee -a $out
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    tsts1=$(( 1 )) 
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  tsts1=$(( 1 ))     
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
# ordered move test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
    87
  if (scala_assert "knight2.scala" "knight_test6.scala")
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
# first-closed-tour test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   103
  if (scala_assert "knight2.scala" "knight_test7.scala")
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
      echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   119
  if (scala_assert "knight2.scala" "knight_test8.scala")
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
    echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   129
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   130
# knights3: purity test
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   131
#
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   132
echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   133
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   134
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   135
if (scala_vars knight3.scala)
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   136
then
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   137
  echo "  --> test failed" | tee -a $out
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   138
  tsts0=$(( 1 ))
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   139
else
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   140
  echo "  --> success" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   141
  tsts0=$(( 0 )) 
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   142
fi
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   143
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   144
# compilation test
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   145
if  [ $tsts0 -eq 0 ]
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   146
then    
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   147
  echo "knight3.scala runs?" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   148
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   149
  if (scala_compile knight3.scala)
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   150
  then
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   151
    echo "  --> success" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   152
    tsts1=$(( 0 ))
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   153
  else
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   154
    echo -e "  --> test failed" | tee -a $out  
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   155
    tsts1=$(( 1 )) 
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   156
  fi
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   157
else
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   158
  tsts1=$(( 1 ))     
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   159
fi
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   160
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   161
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   162
if [ $tsts1 -eq 0 ]
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   163
then
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   164
  echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   165
  
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   166
  if (scala_assert_long "knight3.scala" "knight_test9.scala")
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   167
  then
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   168
      echo -e "  --> success" | tee -a $out
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   169
      marks=$(( marks + 1 ))
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   170
  else
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   171
      echo -e "  --> test  failed" | tee -a $out 
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   172
  fi
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   173
fi
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   174
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   175
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
## final marks
258
ebe71908b13e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
   177
echo "Overall mark for CW 8, Part 2" | tee -a $out
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
echo "$marks" | tee -a $out