marking1/drumb_test2.sh
author Christian Urban <urbanc@in.tum.de>
Wed, 20 Mar 2019 21:50:20 +0000
changeset 264 ecd989eee8bd
parent 261 8997430d9765
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -euo pipefail
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
out=${1:-output}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
     7
echo "" > $out
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
     8
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo "Below is the feedback and provisional marks for your submission" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
echo "for assignment 6 Advanced Part 3.  Please note all marks are provisional until" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "ratified by the assessment board -- this is not an official" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
echo "results transcript." >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
# marks for CW6 part 3
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
marks=$(( 0 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
# compilation tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
function scala_compile {
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
# functional tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
function scala_assert {
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    28
    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i  "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
# purity test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
function scala_vars {
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
# var, .par return, ListBuffer test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
#
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
if (scala_vars drumb.scala)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  tsts0=$(( 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  tsts0=$(( 0 )) 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
# compilation test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
if  [ $tsts0 -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
then 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  echo "drumb.scala runs?" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  if (scala_compile drumb.scala)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    tsts=$(( 0 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    echo "  --> scala drumb.scala did not run successfully" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    tsts=$(( 1 )) 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  tsts=$(( 1 ))     
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
### get_delta test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  echo "  get_delta(None, None) == None" | tee -a $out
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    77
  echo "  get_delta(Some(50.0), None) == None" | tee -a $out
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    78
  echo "  get_delta(None, Some(100.0)) == None" | tee -a $out
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    79
  echo "  get_delta(Some(50.0), Some(100.0)) == Some(1.0)" | tee -a $out
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  if (scala_assert "drumb.scala" "drumb_test4.scala")
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
      echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
      marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
      echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
### get_deltas_test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  echo -e "    List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  echo -e "         List(Some(0.10103412653643493), Some(0.24777709700099845)))" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  echo -e "" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  echo -e "    List(List(None), List(None),                          " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  if (scala_assert "drumb.scala" "drumb_test5.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  then
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   105
     echo "  --> success" | tee -a $out
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
     marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
     echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
### yield_tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   118
  echo -e "  yearly_yield(get_deltas(ds, 100, 0)) == 125" | tee -a $out
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   119
  echo -e "  yearly_yield(get_deltas(ds, 100, 1)) == 117" | tee -a $out
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  if (scala_assert "drumb.scala" "drumb_test6.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  then
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   123
      echo "  --> success" | tee -a $out
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
      echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
### investment_test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
then
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   135
  echo -e "  All results need to be in the range of -/+ 1% of the given values."   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   136
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   137
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   138
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   139
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   140
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   141
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   142
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   143
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   144
  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 83061"   | tee -a $out
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
   145
  
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  if (scala_assert "drumb.scala" "drumb_test7.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  then
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   149
    echo "  --> success" | tee -a $out
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   150
    marks=$(( marks + 1 ))
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
  else
261
8997430d9765 updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
   152
    echo "  --> test failed" | tee -a $out
260
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
## final marks
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
echo "Overall mark for CW 6, Part 3" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
echo "$marks" | tee -a $out