marking3/knight3_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 17 Jan 2019 00:31:32 +0000
changeset 255 44f2b6e34015
parent 243 9bb36426c781
child 258 ebe71908b13e
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
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "for assignment 7 Part 2.  Please note all marks are provisional until" >> $out
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
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
# marks for CW7 part 2
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 {
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
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 {
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
    (ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
# purity test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
function scala_vars {
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
   (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
    37
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
# knights3: 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
echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
if (scala_vars knight3.scala)
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  tsts0=$(( 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  tsts0=$(( 0 )) 
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
# compilation test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
if  [ $tsts0 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
then    
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  echo "knight3.scala runs?" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  if (scala_compile knight3.scala)
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    tsts1=$(( 0 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    echo "  --> scala knight3.scala did not run successfully" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    tsts1=$(( 1 )) 
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  tsts1=$(( 1 ))     
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
# ordered move test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  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
    77
  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
    78
  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
    79
  
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  if (scala_assert "knight3.scala" "knight3a_test.scala")
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
# first-closed-tour test
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  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
    95
  
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  if (scala_assert "knight3.scala" "knight3b_test.scala")
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
      echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
if [ $tsts1 -eq 0 ]
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  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
   110
  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
   111
  
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  if (scala_assert "knight3.scala" "knight3c_test.scala")
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  then
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
      echo "  --> success" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
      marks=$(( marks + 1 ))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  else
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
    echo "  --> test failed" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
fi
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
## final marks
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
echo "Overall mark for CW 7, Part 2" | tee -a $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
echo "$marks" | tee -a $out