marking1/drumb_test.sh
author Christian Urban <urbanc@in.tum.de>
Thu, 15 Nov 2018 14:23:55 +0000
changeset 203 eb188f9ac038
parent 169 b37052895281
child 210 63a1376cbebd
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
     2
set -euo pipefail
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
     3
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
out=${1:-output}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
echo "" > $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
     9
echo "Below is the feedback and provisional marks for your submission" >> $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    10
echo "for assignment 6 Part 3.  Please note all marks are provisional until" >> $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    11
echo "ratified by the assessment board -- this is not an official" >> $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    12
echo "results transcript." >> $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
echo "" >> $out
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    15
# marks for CW7 part 3
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    16
marks=$(( 0 ))
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    17
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
# compilation tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
function scala_compile {
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    21
    (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
# functional tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_assert {
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    27
    (ulimit -t 360; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    30
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
# purity test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
function scala_vars {
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    34
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
}
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    38
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
# var, .par return, ListBuffer test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
#
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    41
echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
if (scala_vars drumb.scala)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    45
  echo "  --> test failed" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  tsts0=$(( 1 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
else
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    48
  echo "  --> success" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  tsts0=$(( 0 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
# compilation test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
if  [ $tsts0 -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
then 
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    56
  echo "drumb.scala runs?" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    58
  if (scala_compile drumb.scala)
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    60
    echo "  --> success" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    tsts=$(( 0 ))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  else
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    63
    echo "  --> scala drumb.scala did not run successfully" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    tsts=$(( 1 )) 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
else
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  tsts=$(( 1 ))     
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
### get prices tests
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    76
  echo " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    77
  echo "       List(List(None), List(None), List(Some(6.35)), " | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    78
  echo "            List(Some(12.241)), List(Some(38.188)))" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    79
  echo " " | tee -a $out  
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    80
  echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    81
  echo "       List(List(Some(311.349976), Some(27.505054))," | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    82
  echo "            List(Some(300.222351), Some(42.357094))," | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    83
  echo "            List(Some(330.555054), Some(52.852215)))" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  if (scala_assert "drumb.scala" "drumb_test1.scala")
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    87
      echo "  --> success" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    88
      marks=$(( marks + 2 ))
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  else
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    90
      echo "  --> test failed" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
### get_deltas_test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    98
  echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
    99
  echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   100
  echo " " | tee -a $out  
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   101
  echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   102
  echo "                             List(Some(0.9277165354330709)), " | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   103
  echo "                             List(Some(2.119679764725104)))" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   104
  echo " " | tee -a $out  
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   105
  echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   106
  echo "                             List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  if (scala_assert "drumb.scala" "drumb_test2.scala") 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   110
      echo "  --> success" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   111
      marks=$(( marks + 1 ))
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  else
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   113
      echo "  --> test failed" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
### yield_tests, investment_test
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
if [ $tsts -eq 0 ]
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   122
  echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   123
  echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   124
  echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out 
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   125
  echo " val deltas1 = get_deltas(prices1)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   126
  echo " val deltas2 = get_deltas(prices2)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   127
  echo " val deltas3 = get_deltas(prices3)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   128
  echo "" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   129
  echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   130
  echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   131
  echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   132
  echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   133
  echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   134
  echo "" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   135
  echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   136
  echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   137
  echo "" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   138
  echo " inv1 >= 295 && inv1 <= 301" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   139
  echo " inv2 >= 194 && inv2 <= 198" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  if (scala_assert "drumb.scala" "drumb_test3.scala") 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  then
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   143
      echo "  --> success" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   144
      marks=$(( marks + 1 ))
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  else
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   146
      echo "  --> test failed" | tee -a $out
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
fi
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
169
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   150
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   151
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   152
## final marks
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   153
echo "Overall mark for CW 6, Part 3" | tee -a $out
b37052895281 updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
   154
echo "$marks" | tee -a $out