testing1/drumb_test.sh
changeset 199 54befaf23648
parent 169 b37052895281
child 206 bbe00108a6f3
equal deleted inserted replaced
198:d59c7995bcb2 199:54befaf23648
     9 echo "" >> $out
     9 echo "" >> $out
    10 
    10 
    11 # compilation tests
    11 # compilation tests
    12 
    12 
    13 function scala_compile {
    13 function scala_compile {
    14   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
    14   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    15 }
    15 }
    16 
    16 
    17 # functional tests
    17 # functional tests
    18 
    18 
    19 function scala_assert {
    19 function scala_assert {
    20   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
    20   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
    21 }
    21 }
    22 
    22 
    23 # purity test
    23 # purity test
    24 
    24 
    25 function scala_vars {
    25 function scala_vars {
    31 #
    31 #
    32 echo "drumb.scala does not contain vars, returns etc?" >> $out
    32 echo "drumb.scala does not contain vars, returns etc?" >> $out
    33 
    33 
    34 if (scala_vars drumb.scala)
    34 if (scala_vars drumb.scala)
    35 then
    35 then
    36   echo "  --> fail" >> $out
    36   echo "  --> fail (make tripply-sure your program conforms to the required format)" >> $out
    37   tsts0=$(( 1 ))
    37   tsts0=$(( 0 ))
    38 else
    38 else
    39   echo "  --> success" >> $out
    39   echo "  --> success" >> $out
    40   tsts0=$(( 0 )) 
    40   tsts0=$(( 0 )) 
    41 fi
    41 fi
    42 
    42 
    56   fi
    56   fi
    57 else
    57 else
    58   tsts=$(( 1 ))     
    58   tsts=$(( 1 ))     
    59 fi
    59 fi
    60 
    60 
    61 
    61 ### get january data
    62 
       
    63 ### get prices tests
       
    64 
    62 
    65 if [ $tsts -eq 0 ]
    63 if [ $tsts -eq 0 ]
    66 then
    64 then
    67   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
    65   echo "  get_january_data(\"GOOG\", 1980) == List()" >> $out
    68   echo "       List(List(Some(311.349976), Some(27.505054))," >> $out
    66   echo "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" >> $out
    69   echo "            List(Some(300.222351), Some(42.357094))," >> $out
       
    70   echo "            List(Some(330.555054), Some(52.852215)))" >> $out
       
    71 
    67 
    72   if (scala_assert "drumb.scala" "drumb_test1.scala")
    68   if (scala_assert "drumb.scala" "drumb_test1.scala")
    73   then
    69   then
    74     echo "  --> success" >> $out
    70     echo "  --> success" >> $out
    75   else
    71   else
    76     echo "  --> test failed" >> $out
    72     echo "  --> test failed" >> $out
    77   fi
    73   fi
    78 fi
    74 fi
    79 
    75 
    80 ### get_deltas_test
    76 ### get first price
    81 
    77 
    82 if [ $tsts -eq 0 ]
    78 if [ $tsts -eq 0 ]
    83 then
    79 then
    84   echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
    80   echo "  get_first_price(\"GOOG\", 1980) == None" >> $out
    85   echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
    81   echo "  get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out
    86   echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
    82 
    87   
    83   if (scala_assert "drumb.scala" "drumb_test2.scala")
    88   if (scala_assert "drumb.scala" "drumb_test2.scala") 
       
    89   then
    84   then
    90     echo "  --> success" >> $out
    85     echo "  --> success" >> $out
    91   else
    86   else
    92     echo "  --> test failed" >> $out
    87     echo "  --> test failed" >> $out
    93   fi
    88   fi
    94 fi
    89 fi
    95 
    90 
    96 
    91 ### get prices tests
    97 ### yield_tests, investment_test
       
    98 
    92 
    99 if [ $tsts -eq 0 ]
    93 if [ $tsts -eq 0 ]
   100 then
    94 then
   101   echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
    95   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
   102   echo "" >> $out
    96   echo "       List(List(Some(311.349976), Some(20.544939))," >> $out
   103   echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
    97   echo "            List(Some(300.222351), Some(31.638695))," >> $out
   104   echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
    98   echo "            List(Some(330.555054), Some(39.478039)))" >> $out
   105   
    99 
   106   if (scala_assert "drumb.scala" "drumb_test3.scala") 
   100   if (scala_assert "drumb.scala" "drumb_test3.scala")
   107   then
   101   then
   108     echo "  --> success" >> $out
   102     echo "  --> success" >> $out
   109   else
   103   else
   110     echo "  --> test failed" >> $out
   104     echo "  --> test failed" >> $out
   111   fi
   105   fi
   112 fi
   106 fi
   113 
   107 
       
   108 ### get_deltas_test
       
   109 
       
   110 #if [ $tsts -eq 0 ]
       
   111 #then
       
   112 #  echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
       
   113 #  echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
       
   114 #  echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
       
   115 #  
       
   116 #  if (scala_assert "drumb.scala" "drumb_test2.scala") 
       
   117 #  then
       
   118 #    echo "  --> success" >> $out
       
   119 #  else
       
   120 #    echo "  --> test failed" >> $out
       
   121 #  fi
       
   122 #fi
       
   123 
       
   124 
       
   125 ### yield_tests, investment_test
       
   126 
       
   127 #if [ $tsts -eq 0 ]
       
   128 #then
       
   129 #  echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
       
   130 #  echo "" >> $out
       
   131 #  echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
       
   132 #  echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
       
   133 #  
       
   134 #  if (scala_assert "drumb.scala" "drumb_test3.scala") 
       
   135 #  then
       
   136 #    echo "  --> success" >> $out
       
   137 #  else
       
   138 #    echo "  --> test failed" >> $out
       
   139 #  fi
       
   140 #fi
       
   141