main_testing1/drumb_test.sh
changeset 347 4de31fdc0d67
parent 320 cdfb2ce30a3d
child 352 97bcf8efe4e0
equal deleted inserted replaced
346:663c2a9108d1 347:4de31fdc0d67
       
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo -e "" > $out
       
     7 
       
     8 echo -e "Below is the feedback for your submission for drumb.scala" >> $out
       
     9 echo -e "" >> $out
       
    10 
       
    11 # compilation tests
       
    12 
       
    13 function scala_compile {
       
    14   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    15 }
       
    16 
       
    17 # functional tests
       
    18 
       
    19 function scala_assert {
       
    20   (ulimit -t 30; JAVA_OPTS="-Xmx1g" 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\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    27 }
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 # compilation test
       
    34 echo -e "drumb.scala runs?" >> $out
       
    35 
       
    36 if (scala_compile drumb.scala)
       
    37 then
       
    38     echo -e "  --> success" >> $out
       
    39     tsts=$(( 0 ))
       
    40 else
       
    41     echo -e "  --> SCALA DID NOT RUN drumb.scala" >> $out
       
    42     tsts=$(( 1 )) 
       
    43 fi
       
    44 
       
    45 
       
    46 
       
    47 # var, .par return, ListBuffer test
       
    48 #
       
    49 
       
    50 if [ $tsts -eq 0 ]
       
    51 then
       
    52     echo -e "drumb.scala does not contain vars, returns etc?" >> $out
       
    53 
       
    54     if (scala_vars drumb.scala)
       
    55     then
       
    56 	echo -e "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out
       
    57 	tsts=$(( 1 ))
       
    58     else
       
    59 	echo -e "  --> success" >> $out
       
    60 	tsts=$(( 0 )) 
       
    61     fi
       
    62 fi    
       
    63 
       
    64 
       
    65 ### get january data
       
    66 
       
    67 if [ $tsts -eq 0 ]
       
    68 then
       
    69   echo -e "  get_january_data(\"GOOG\", 1980) == List()" >> $out
       
    70   echo -e "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,312.204773\"" >> $out
       
    71 
       
    72   if (scala_assert "drumb.scala" "drumb_test1.scala")
       
    73   then
       
    74     echo -e "  --> success" >> $out
       
    75   else
       
    76     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
    77   fi
       
    78 fi
       
    79 
       
    80 ### get first price
       
    81 
       
    82 if [ $tsts -eq 0 ]
       
    83 then
       
    84   echo -e "  get_first_price(\"GOOG\", 1980) == None" >> $out
       
    85   echo -e "  get_first_price(\"GOOG\", 2010) == Some(312.204773)" >> $out  
       
    86 
       
    87   if (scala_assert "drumb.scala" "drumb_test2.scala")
       
    88   then
       
    89     echo -e "  --> success" >> $out
       
    90   else
       
    91     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
    92   fi
       
    93 fi
       
    94 
       
    95 ### get prices tests
       
    96 
       
    97 if [ $tsts -eq 0 ]
       
    98 then
       
    99   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
       
   100   echo "       List(List(Some(312.204773), Some(26.782711))," >> $out
       
   101   echo "            List(Some(301.0466),   Some(41.244694))," >> $out
       
   102   echo "            List(Some(331.462585), Some(51.464207)))" >> $out
       
   103 
       
   104   if (scala_assert "drumb.scala" "drumb_test3.scala")
       
   105   then
       
   106     echo -e "  --> success" >> $out
       
   107   else
       
   108     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   109   fi
       
   110 fi
       
   111 
       
   112 ### get_delta_test
       
   113 
       
   114 if [ $tsts -eq 0 ]
       
   115 then
       
   116   echo -e "  get_delta(None, None) == None" >> $out
       
   117   echo -e "  get_delta(Some(50.0), None) == None" >> $out
       
   118   echo -e "  get_delta(None, Some(100.0)) == None" >> $out
       
   119   echo -e "  get_delta(Some(50.0), Some(100.0)) == Some(1.0)" >> $out
       
   120 
       
   121   if (scala_assert "drumb.scala" "drumb_test4.scala")
       
   122   then
       
   123       echo -e "  --> success" >> $out
       
   124   else
       
   125       echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   126   fi
       
   127 fi
       
   128 
       
   129 
       
   130 ### get_deltas_test
       
   131 
       
   132 if [ $tsts -eq 0 ]
       
   133 then
       
   134   echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
       
   135   echo -e "    List(List(Some(-0.03573991804411003), Some(0.539974575389325)), " >> $out
       
   136   echo -e "         List(Some(0.10103414222249969), Some(0.24777764141006836)))" >> $out
       
   137   echo -e "" >> $out
       
   138   echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " >> $out
       
   139   echo -e "    List(List(None), List(None),                          " >> $out
       
   140   echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104))) " >> $out
       
   141   
       
   142   if (scala_assert "drumb.scala" "drumb_test5.scala") 
       
   143   then
       
   144      echo -e "  --> success" >> $out
       
   145   else
       
   146      echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   147   fi
       
   148 fi
       
   149 
       
   150 
       
   151 ### yield_tests
       
   152 
       
   153 if [ $tsts -eq 0 ]
       
   154 then
       
   155   echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" >> $out
       
   156   echo -e "  yearly_yield(ds, 100, 0) == 125" >> $out
       
   157   echo -e "  yearly_yield(ds, 100, 1) == 117" >> $out
       
   158   
       
   159   if (scala_assert "drumb.scala" "drumb_test6.scala") 
       
   160   then
       
   161       echo -e "  --> success" >> $out
       
   162   else
       
   163       echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   164   fi
       
   165 fi
       
   166 
       
   167 
       
   168 ### investment_test
       
   169 
       
   170 if [ $tsts -eq 0 ]
       
   171 then
       
   172   echo -e "  All results need to be in the range of -/+ 1% of the given values."   >> $out
       
   173   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   >> $out
       
   174   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   >> $out
       
   175   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   >> $out
       
   176   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   >> $out
       
   177   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   >> $out
       
   178   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   >> $out
       
   179   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   >> $out
       
   180   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   >> $out
       
   181   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504"   >> $out
       
   182   
       
   183   
       
   184   if (scala_assert "drumb.scala" "drumb_test7.scala") 
       
   185   then
       
   186     echo -e "  --> success" >> $out
       
   187   else
       
   188     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   189   fi
       
   190 fi
       
   191