testing1/drumb_test2.sh
author Christian Urban <urbanc@in.tum.de>
Tue, 18 Dec 2018 23:31:45 +0000
changeset 250 1b08b8ac13fd
parent 249 1997cfcd6334
child 266 ca48ac1d3c3e
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -e
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo -e "" > $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo -e "Below is the feedback for your submission advanced part of drumb.scala:" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo -e "" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
# compilation tests
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
function scala_compile {
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
}
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
# functional tests
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
function scala_assert {
249
1997cfcd6334 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)
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
}
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
# purity test
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_vars {
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
   (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
# var, .par return, ListBuffer test
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
#
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
echo -e "drumb.scala does not contain vars, returns etc?" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
if (scala_vars drumb.scala)
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  echo -e "  --> fail (make triple-sure your program conforms to the required format)" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  tsts0=$(( 0 ))
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  echo -e "  --> success" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  tsts0=$(( 0 )) 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
# compilation test
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
if  [ $tsts0 -eq 0 ]
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
then 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  echo -e "drumb.scala runs?" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  if (scala_compile drumb.scala)
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    echo -e "  --> success" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
    tsts=$(( 0 ))
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
    echo -e "  --> SCALA DID NOT RUN DRUMB.SCALA\n" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    tsts=$(( 1 )) 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  tsts=$(( 1 ))     
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
### get_deltas_test
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
if [ $tsts -eq 0 ]
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  echo -e "    List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  echo -e "         List(Some(0.10103412653643493), Some(0.24777709700099845)))" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  echo -e "" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  echo -e "    List(List(None), List(None),                          " >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  if (scala_assert "drumb.scala" "drumb_test5.scala") 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo -e "  --> success" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
### yield_tests
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
if [ $tsts -eq 0 ]
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" >> $out
250
1b08b8ac13fd updated
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
    87
  echo -e "  yearly_yield(get_deltas(ds, 100, 0) == 125" >> $out
1b08b8ac13fd updated
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
    88
  echo -e "  yearly_yield(get_deltas(ds, 100, 1) == 117" >> $out
248
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  if (scala_assert "drumb.scala" "drumb_test6.scala") 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
      echo -e "  --> success" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
      echo -e "  --> \n ONE TEST FAILED\n" >> $out  
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
### investment_test
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
if [ $tsts -eq 0 ]
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  if (scala_assert "drumb.scala" "drumb_test7.scala") 
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  then
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
      echo -e "  --> success" >> $out
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  else
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
      echo -e "  --> \n ONE TEST FAILED\n" >> $out    
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
fi
1616d06a0893 updared
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118