marking1/drumb_test2.sh
author Christian Urban <urbanc@in.tum.de>
Sat, 02 Feb 2019 01:21:43 +0000
changeset 260 b4812c877b05
child 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
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
echo "Below is the feedback and provisional marks for your submission" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
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
     9
echo "ratified by the assessment board -- this is not an official" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
echo "results transcript." >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo "" >> $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
# marks for CW6 part 3
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
marks=$(( 0 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
# compilation tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
function scala_compile {
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    (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
    21
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
# functional tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_assert {
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
    (ulimit -t 30; JAVA_OPTS="-Xmx4g" scala -i -nc "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
# purity test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
function scala_vars {
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
   (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
    34
}
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
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
# var, .par return, ListBuffer test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
#
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
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
    41
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
if (scala_vars drumb.scala)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  tsts0=$(( 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  tsts0=$(( 0 )) 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
# compilation test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
if  [ $tsts0 -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
then 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  echo "drumb.scala runs?" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  if (scala_compile drumb.scala)
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    tsts=$(( 0 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    echo "  --> scala drumb.scala did not run successfully" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    tsts=$(( 1 )) 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  tsts=$(( 1 ))     
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
### get_delta test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  echo "  get_delta(None, None) == None" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  echo "  get_delta(Some(100.0), None) == None" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  echo "  get_delta(None, Some(50.0)) == None" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  echo "  get_delta(Some(100.0), Some(50.0)) == Some(1.0)" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  if (scala_assert "drumb.scala" "drumb_test4.scala")
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
      echo "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
      marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
      echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
### get_deltas_test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  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
    94
  echo -e "    List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  echo -e "         List(Some(0.10103412653643493), Some(0.24777709700099845)))" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  echo -e "" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  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
    98
  echo -e "    List(List(None), List(None),                          " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  if (scala_assert "drumb.scala" "drumb_test5.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
     echo -e "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
     marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
     echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
### yield_tests
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  echo -e "  yearly_yield(get_deltas(ds, 100, 0) == 125" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  echo -e "  yearly_yield(get_deltas(ds, 100, 1) == 117" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  if (scala_assert "drumb.scala" "drumb_test6.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
      echo -e "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
### investment_test
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
if [ $tsts -eq 0 ]
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  if (scala_assert "drumb.scala" "drumb_test7.scala") 
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  then
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
      echo -e "  --> success" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
      marks=$(( marks + 1 ))
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  else
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
      echo "  --> test failed" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
fi
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
## final marks
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
echo "Overall mark for CW 6, Part 3" | tee -a $out
b4812c877b05 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
echo "$marks" | tee -a $out