testing1/drumb_test2.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 05 Aug 2019 20:14:06 +0100
changeset 269 3ef2542207c4
parent 248 e8d966b1826d
child 281 32dfd2ca577b
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
248
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     1
#!/bin/bash
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     2
set -e
130
d272307e6c02 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
248
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     4
out=${1:-output}
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     5
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     6
echo "" > $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     7
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     8
echo "Below is the feedback for your submission for drumb.scala" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     9
echo "" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    10
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    11
# compilation tests
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    12
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    13
function scala_compile {
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    14
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    15
}
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    16
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    17
# functional tests
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    18
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    19
function scala_assert {
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    20
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    21
}
199
2e13dedd922e updated
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
    22
248
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    23
# purity test
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    24
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    25
function scala_vars {
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    26
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    27
}
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    28
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    29
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    30
# var, .par return, ListBuffer test
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    31
#
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    32
echo "drumb.scala does not contain vars, returns etc?" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    33
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    34
if (scala_vars drumb.scala)
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    35
then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    36
  echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    37
  tsts0=$(( 0 ))
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    38
else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    39
  echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    40
  tsts0=$(( 0 )) 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    41
fi
130
d272307e6c02 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
d272307e6c02 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
248
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    44
# compilation test
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    45
if  [ $tsts0 -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    46
then 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    47
  echo "drumb.scala runs?" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    48
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    49
  if (scala_compile drumb.scala)
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    50
  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    51
    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    52
    tsts=$(( 0 ))
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    53
  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    54
    echo -e "  --> SCALA DID NOT RUN DRUMB.SCALA\n" >> $out    
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    55
    tsts=$(( 1 )) 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    56
  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    57
else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    58
  tsts=$(( 1 ))     
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    59
fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    60
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    61
### get january data
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    62
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    63
if [ $tsts -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    64
then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    65
  echo "  get_january_data(\"GOOG\", 1980) == List()" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    66
  echo "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    67
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    68
  if (scala_assert "drumb.scala" "drumb_test1.scala")
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    69
  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    70
    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    71
  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    72
    echo -e "  --> \n ONE TEST FAILED\n" >> $out    
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    73
  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    74
fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    75
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    76
### get first price
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    77
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    78
if [ $tsts -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    79
then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    80
  echo "  get_first_price(\"GOOG\", 1980) == None" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    81
  echo "  get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    82
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    83
  if (scala_assert "drumb.scala" "drumb_test2.scala")
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    84
  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    85
    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    86
  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    87
    echo "  --> test failed" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    88
  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    89
fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    90
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    91
### get prices tests
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    92
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    93
if [ $tsts -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    94
then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    95
  echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    96
  echo "       List(List(Some(311.349976), Some(20.544939))," >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    97
  echo "            List(Some(300.222351), Some(31.638695))," >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    98
  echo "            List(Some(330.555054), Some(39.478039)))" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    99
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   100
  if (scala_assert "drumb.scala" "drumb_test3.scala")
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   101
  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   102
    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   103
  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   104
    echo "  --> test failed" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   105
  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   106
fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   107
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   108
### get_deltas_test
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   109
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   110
#if [ $tsts -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   111
#then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   112
#  echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   113
#  echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   114
#  echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   115
#  
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   116
#  if (scala_assert "drumb.scala" "drumb_test2.scala") 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   117
#  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   118
#    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   119
#  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   120
#    echo "  --> test failed" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   121
#  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   122
#fi
130
d272307e6c02 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
199
2e13dedd922e updated
Christian Urban <urbanc@in.tum.de>
parents: 144
diff changeset
   124
248
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   125
### yield_tests, investment_test
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   126
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   127
#if [ $tsts -eq 0 ]
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   128
#then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   129
#  echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   130
#  echo "" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   131
#  echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   132
#  echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   133
#  
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   134
#  if (scala_assert "drumb.scala" "drumb_test3.scala") 
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   135
#  then
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   136
#    echo "  --> success" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   137
#  else
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   138
#    echo "  --> test failed" >> $out
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   139
#  fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   140
#fi
e8d966b1826d updared
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
   141