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