marking4/bf_test.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 07 Aug 2019 16:15:42 +0100
changeset 273 b19227660752
parent 227 b5f3e814a710
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "Below is the feedback and provisional marks for your submission" >> $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "for assignment 8 Part 2.  Please note all marks are provisional until" >> $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "ratified by the assessment board -- this is not an official" >> $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "results transcript." >> $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
echo "" >> $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# marks for CW8 part 2
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
marks=$(( 0 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# compilation tests
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_compile {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# functional tests
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_assert {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# purity test
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
function scala_vars {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
# var, return, ListBuffer test
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
#
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
echo "bf.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if (scala_vars bf.scala)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  echo "  --> test failed" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 1 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  echo "  --> success" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  tsts0=$(( 0 )) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
# compilation test
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
if  [ $tsts0 -eq 0 ]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
then    
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  echo "bf.scala runs?" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  if (scala_compile bf.scala)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    echo "  --> success" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts1=$(( 0 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    echo "  --> scala bf.scala did not run successfully" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    tsts1=$(( 1 )) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  tsts1=$(( 1 ))     
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
if [ $tsts1 -eq 0 ]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  echo " sread(Map(), 2) == 0" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  echo " sread(Map(2 -> 1), 2) == 1" | tee -a $out  
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  echo " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  if (scala_assert "bf.scala" "bf1a_test.scala")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
      echo "  --> success" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
      marks=$(( marks + 1 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo "  --> test failed" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
if [ $tsts1 -eq 0 ]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    echo " jumpRight(\"[******]***\", 1, 0) == 8" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
    echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
    echo " jumpRight(\"[**[***]***\", 1, 0) == 11" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    echo " jumpRight(\"[*[][]*]***\", 1, 0) == 8" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
    echo " jumpLeft(\"[******]***\", 6, 0) == 1" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    echo " jumpLeft(\"[******]***\", 7, 0) == -1" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  if (scala_assert "bf.scala" "bf1b_test.scala")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
      echo "  --> success" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
      marks=$(( marks + 1 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
      echo "  --> test failed" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
if [ $tsts1 -eq 0 ]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  echo " start(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  echo " start(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  echo " start(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  echo " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  echo "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  echo " start(hello, Map()) == " | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  echo "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  echo " start(\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\", Map()) == " | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  echo "       Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  if (scala_assert "bf.scala" "bf1c_test.scala")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  then
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
      echo "  --> success" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
      marks=$(( marks + 2 ))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  else
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
      echo "  --> test failed" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
fi
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
## final marks
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
echo "Overall mark for CW 8, Part 2" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
echo "$marks" | tee -a $out
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140