testing/drumb_test.sh
changeset 144 716042628398
parent 143 11396c17cd8b
child 145 d306102fd33b
equal deleted inserted replaced
143:11396c17cd8b 144:716042628398
     1 #!/bin/bash
       
     2 set -e
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo "" > $out
       
     7 
       
     8 echo "Below is the feedback for your submission for drumb.scala" >> $out
       
     9 echo "" >> $out
       
    10 
       
    11 # compilation tests
       
    12 
       
    13 function scala_compile {
       
    14   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
       
    15 }
       
    16 
       
    17 # functional tests
       
    18 
       
    19 function scala_assert {
       
    20   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    21 }
       
    22 
       
    23 # purity test
       
    24 
       
    25 function scala_vars {
       
    26    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
       
    27 }
       
    28 
       
    29 
       
    30 # var, .par return, ListBuffer test
       
    31 #
       
    32 echo "drumb.scala does not contain vars, returns etc?" >> $out
       
    33 
       
    34 if (scala_vars drumb.scala)
       
    35 then
       
    36   echo "  --> fail" >> $out
       
    37   tsts0=$(( 1 ))
       
    38 else
       
    39   echo "  --> success" >> $out
       
    40   tsts0=$(( 0 )) 
       
    41 fi
       
    42 
       
    43 
       
    44 # compilation test
       
    45 if  [ $tsts0 -eq 0 ]
       
    46 then 
       
    47   echo "drumb.scala runs?" >> $out
       
    48 
       
    49   if (scala_compile alcohol.scala)
       
    50   then
       
    51     echo "  --> success" >> $out
       
    52     tsts=$(( 0 ))
       
    53   else
       
    54     echo "  --> scala did not run alcohol.scala" >> $out
       
    55     tsts=$(( 1 )) 
       
    56   fi
       
    57 else
       
    58   tsts=$(( 1 ))     
       
    59 fi
       
    60 
       
    61 
       
    62 
       
    63 ### get prices tests
       
    64 
       
    65 if [ $tsts -eq 0 ]
       
    66 then
       
    67   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
       
    68   echo "       List(List(Some(311.349976), Some(27.505054))," >> $out
       
    69   echo "            List(Some(300.222351), Some(42.357094))," >> $out
       
    70   echo "            List(Some(330.555054), Some(52.852215)))" >> $out
       
    71 
       
    72   if (scala_assert "drumb.scala" "drumb_test1.scala")
       
    73   then
       
    74     echo "  --> success" >> $out
       
    75   else
       
    76     echo "  --> test failed" >> $out
       
    77   fi
       
    78 fi
       
    79 
       
    80 ### get_deltas_test
       
    81 
       
    82 if [ $tsts -eq 0 ]
       
    83 then
       
    84   echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
       
    85   echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
       
    86   echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
       
    87   
       
    88   if (scala_assert "drumb.scala" "drumb_test2.scala") 
       
    89   then
       
    90     echo "  --> success" >> $out
       
    91   else
       
    92     echo "  --> test failed" >> $out
       
    93   fi
       
    94 fi
       
    95 
       
    96 
       
    97 ### yield_tests, investment_test
       
    98 
       
    99 if [ $tsts -eq 0 ]
       
   100 then
       
   101   echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
       
   102   echo "" >> $out
       
   103   echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
       
   104   echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
       
   105   
       
   106   if (scala_assert "drumb.scala" "drumb_test3.scala") 
       
   107   then
       
   108     echo "  --> success" >> $out
       
   109   else
       
   110     echo "  --> test failed" >> $out
       
   111   fi
       
   112 fi
       
   113