testing1/drumb_test.sh
changeset 281 87b9e3e2c1a7
parent 266 ca48ac1d3c3e
child 284 9a04eb6a2291
--- a/testing1/drumb_test.sh	Tue Oct 29 11:11:44 2019 +0000
+++ b/testing1/drumb_test.sh	Tue Oct 29 14:12:24 2019 +0000
@@ -1,5 +1,5 @@
 #!/bin/bash
-set -e
+set -euo pipefail
 
 out=${1:-output}
 
@@ -17,7 +17,7 @@
 # functional tests
 
 function scala_assert {
-  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
+  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
 }
 
 # purity test
@@ -33,7 +33,7 @@
 
 if (scala_vars drumb.scala)
 then
-  echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
+  echo "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out
   tsts0=$(( 0 ))
 else
   echo "  --> success" >> $out
@@ -51,7 +51,7 @@
     echo "  --> success" >> $out
     tsts=$(( 0 ))
   else
-    echo "  --> scala did not run drumb.scala" >> $out
+    echo "  --> SCALA DID NOT RUN drumb.scala" >> $out
     tsts=$(( 1 )) 
   fi
 else
@@ -63,13 +63,13 @@
 if [ $tsts -eq 0 ]
 then
   echo "  get_january_data(\"GOOG\", 1980) == List()" >> $out
-  echo "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" >> $out
+  echo "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,312.204773\"" >> $out
 
   if (scala_assert "drumb.scala" "drumb_test1.scala")
   then
     echo "  --> success" >> $out
   else
-    echo "  --> test failed" >> $out
+    echo "  --> ONE OF THE TESTS FAILED\n" >> $out
   fi
 fi
 
@@ -78,13 +78,13 @@
 if [ $tsts -eq 0 ]
 then
   echo "  get_first_price(\"GOOG\", 1980) == None" >> $out
-  echo "  get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out
+  echo "  get_first_price(\"GOOG\", 2010) == Some(312.204773)" >> $out  
 
   if (scala_assert "drumb.scala" "drumb_test2.scala")
   then
     echo "  --> success" >> $out
   else
-    echo "  --> test failed" >> $out
+    echo "  --> ONE OF THE TESTS FAILED\n" >> $out
   fi
 fi
 
@@ -93,49 +93,95 @@
 if [ $tsts -eq 0 ]
 then
   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
-  echo "       List(List(Some(311.349976), Some(20.544939))," >> $out
-  echo "            List(Some(300.222351), Some(31.638695))," >> $out
-  echo "            List(Some(330.555054), Some(39.478039)))" >> $out
+  echo "       List(List(Some(311.349976), Some(20.544939))," >> $out 
+  echo "              List(Some(300.222351), Some(31.638695))," >> $out 
+  echo "              List(Some(330.555054), Some(39.478039))))" >> $out
 
   if (scala_assert "drumb.scala" "drumb_test3.scala")
   then
     echo "  --> success" >> $out
   else
-    echo "  --> test failed" >> $out
+    echo "  --> ONE OF THE TESTS FAILED\n" >> $out
   fi
 fi
 
+### get_delta_test
+
+if [ $tsts -eq 0 ]
+then
+  echo "  get_delta(None, None) == None" >> $out
+  echo "  get_delta(Some(50.0), None) == None" >> $out
+  echo "  get_delta(None, Some(100.0)) == None" >> $out
+  echo "  get_delta(Some(50.0), Some(100.0)) == Some(1.0)" >> $out
+
+  if (scala_assert "drumb.scala" "drumb_test4.scala")
+  then
+      echo "  --> success" >> $out
+  else
+      echo "  --> ONE OF THE TESTS FAILED\n" >> $out
+  fi
+fi
+
+
 ### get_deltas_test
 
-#if [ $tsts -eq 0 ]
-#then
-#  echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
-#  echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
-#  echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
-#  
-#  if (scala_assert "drumb.scala" "drumb_test2.scala") 
-#  then
-#    echo "  --> success" >> $out
-#  else
-#    echo "  --> test failed" >> $out
-#  fi
-#fi
+if [ $tsts -eq 0 ]
+then
+  echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
+  echo -e "    List(List(Some(-0.03573991804411003), Some(0.539974575389325)), " >> $out
+  echo -e "         List(Some(0.10103414222249969), Some(0.24777764141006836)))" >> $out
+  echo -e "" >> $out
+  echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " >> $out
+  echo -e "    List(List(None), List(None),                          " >> $out
+  echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " >> $out
+  
+  if (scala_assert "drumb.scala" "drumb_test5.scala") 
+  then
+     echo "  --> success" >> $out
+  else
+     echo "  --> ONE OF THE TESTS FAILED\n" >> $out
+  fi
+fi
 
 
-### yield_tests, investment_test
+### yield_tests
+
+if [ $tsts -eq 0 ]
+then
+  echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" >> $out
+  echo -e "  yearly_yield(get_deltas(ds, 100, 0)) == 125" >> $out
+  echo -e "  yearly_yield(get_deltas(ds, 100, 1)) == 117" >> $out
+  
+  if (scala_assert "drumb.scala" "drumb_test6.scala") 
+  then
+      echo "  --> success" >> $out
+  else
+      echo "  --> ONE OF THE TESTS FAILED\n" >> $out
+  fi
+fi
+
+
+### investment_test
 
-#if [ $tsts -eq 0 ]
-#then
-#  echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
-#  echo "" >> $out
-#  echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
-#  echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
-#  
-#  if (scala_assert "drumb.scala" "drumb_test3.scala") 
-#  then
-#    echo "  --> success" >> $out
-#  else
-#    echo "  --> test failed" >> $out
-#  fi
-#fi
+if [ $tsts -eq 0 ]
+then
+  echo -e "  All results need to be in the range of -/+ 1% of the given values."   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   >> $out
+  echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504"   >> $out
+  
+  
+  if (scala_assert "drumb.scala" "drumb_test7.scala") 
+  then
+    echo "  --> success" >> $out
+  else
+    echo "  --> ONE OF THE TESTS FAILED\n" >> $out
+  fi
+fi