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