marking5/bf_test.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 16 Jan 2019 12:20:34 +0000
changeset 253 ec7a12806c3f
child 286 5c57c407e27b
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
253
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
# to make the script fail safely
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
set -euo pipefail
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
out=${1:-output}
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "" > $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "Below is the feedback and provisional marks for your submission" >> $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "for assignment 10 Part 1.  Please note all marks are provisional until" >> $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
echo "ratified by the assessment board -- this is not an official" >> $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
echo "results transcript." >> $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
echo "" >> $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# marks for CW10 part 1
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
marks=$(( 0 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
# compilation tests
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
function scala_compile {
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
}
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
# functional tests
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
function scala_assert {
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
# purity test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
function scala_vars {
ec7a12806c3f 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)
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
}
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
# var, return, ListBuffer test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
#
ec7a12806c3f 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
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
if (scala_vars bf.scala)
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  echo "  --> test failed" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 1 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  tsts0=$(( 0 )) 
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
# compilation test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
if  [ $tsts0 -eq 0 ]
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
then    
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  echo "bf.scala runs?" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  if (scala_compile bf.scala)
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts1=$(( 0 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    echo "  --> scala bf.scala did not run successfully" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    tsts1=$(( 1 )) 
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  tsts1=$(( 1 ))     
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
### bf1 test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
if [ $tsts1 -eq 0 ]
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  echo " load_bff(\"benchmark.bf\").length == 188" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  echo " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
   
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  if (scala_assert "bf.scala" "bf_test1.scala")
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
      echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
      marks=$(( marks + 1 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
    echo "  --> test failed" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
### bf2 test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
if [ $tsts1 -eq 0 ]
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  echo " sread(Map(), 2) == 0" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  echo " sread(Map(2 -> 1), 2) == 1" | tee -a $out  
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  echo " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  if (scala_assert "bf.scala" "bf_test2.scala")
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
      echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
      marks=$(( marks + 1 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    echo "  --> test failed" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
### bf3 test
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
if [ $tsts1 -eq 0 ]
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
    echo " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    echo " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
    echo " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
    echo " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
    echo " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
    echo " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    echo " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
    echo " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  if (scala_assert "bf.scala" "bf_test3.scala")
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
      marks=$(( marks + 2 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
      echo "  --> test failed" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
if [ $tsts1 -eq 0 ]
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  echo -e " run(hello, Map()) == " | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  if (scala_assert "bf.scala" "bf_test4.scala")
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  then
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
      echo "  --> success" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
      marks=$(( marks + 2 ))
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  else
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
      echo "  --> test failed" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
  fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
fi
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
## final marks
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
echo "Overall mark for CW 10, Part 1" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
echo "$marks" | tee -a $out
ec7a12806c3f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158