main_marking1/drumb_test.sh
changeset 388 ed63dca8068a
child 424 daf561a83ba6
equal deleted inserted replaced
387:6282b88511d8 388:ed63dca8068a
       
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 out=${1:-output}
       
     7 
       
     8 echo "" > $out
       
     9 
       
    10 echo -e `date` >> $out
       
    11 echo -e "" >> $out
       
    12 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo -e "of the Main Part 1 (Scala).  Please note all marks are provisional until" >> $out
       
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    15 echo -e "results transcript." >> $out
       
    16 echo -e "" >> $out
       
    17 
       
    18 # marks for CW6 main part 
       
    19 marks=$(( 0 ))
       
    20 
       
    21 
       
    22 echo -e "" >> $out
       
    23 echo -e "Below is the feedback for your submission drumb.scala" >> $out
       
    24 echo -e "" >> $out
       
    25 
       
    26 
       
    27 # compilation tests
       
    28 
       
    29 function scala_compile {
       
    30   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    31 }
       
    32 
       
    33 # functional tests
       
    34 
       
    35 function scala_assert {
       
    36   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    37 }
       
    38 
       
    39 
       
    40 # purity test
       
    41 
       
    42 function scala_vars {
       
    43    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    44 }
       
    45 
       
    46 # compilation test
       
    47 echo -e "drumb.scala runs?" | tee -a $out
       
    48 
       
    49 if (scala_compile drumb.scala)
       
    50 then
       
    51     echo -e "  --> success" | tee -a $out
       
    52     tsts=$(( 0 ))
       
    53 else
       
    54     echo -e "  --> SCALA DID NOT RUN drumb.scala\n" | tee -a $out
       
    55     tsts=$(( 1 )) 
       
    56 fi
       
    57 
       
    58 
       
    59 # var, .par return, ListBuffer test
       
    60 #
       
    61 if  [ $tsts -eq 0 ]
       
    62 then  
       
    63     echo -e "drumb.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    64     
       
    65     if (scala_vars drumb.scala)
       
    66     then
       
    67 	echo -e "  --> TEST FAILED\n" | tee -a $out
       
    68 	tsts=$(( 1 ))
       
    69     else
       
    70 	echo -e "  --> success" | tee -a $out
       
    71 	tsts=$(( 0 )) 
       
    72     fi
       
    73 else
       
    74   tsts=$(( 1 ))  
       
    75 fi     
       
    76 
       
    77 echo >> $out
       
    78 
       
    79 sleep 15
       
    80 
       
    81 ### get january tests
       
    82 
       
    83 if [ $tsts -eq 0 ]
       
    84 then
       
    85   echo -e "  get_january_data(\"GOOG\", 1980) == List()" | tee -a $out
       
    86   echo -e "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,312.204773\"" | tee -a $out
       
    87 
       
    88   if (scala_assert "drumb.scala" "drumb_test1.scala")
       
    89   then
       
    90       echo -e "  --> success" | tee -a $out
       
    91       marks=$(( marks + 1 ))
       
    92   else
       
    93       echo -e "  --> TEST FAILED\n" | tee -a $out
       
    94   fi
       
    95 fi
       
    96 
       
    97 ### get first price tests
       
    98 
       
    99 if [ $tsts -eq 0 ]
       
   100 then
       
   101   echo -e "  get_first_price(\"GOOG\", 1980) == None" | tee -a $out
       
   102   echo -e "  get_first_price(\"GOOG\", 2010) == Some(312.204773)" | tee -a $out
       
   103 
       
   104   if (scala_assert "drumb.scala" "drumb_test2.scala")
       
   105   then
       
   106       echo -e "  --> success" | tee -a $out
       
   107       marks=$(( marks + 1 ))
       
   108   else
       
   109       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   110   fi
       
   111 fi
       
   112 
       
   113 ### get prices tests
       
   114 
       
   115 if [ $tsts -eq 0 ]
       
   116 then
       
   117   echo -e "  get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
       
   118   echo -e "       List(List(None), List(None), List(Some(6.35)), " | tee -a $out
       
   119   echo -e "            List(Some(12.241)), List(Some(38.188)))" | tee -a $out
       
   120   echo -e " " | tee -a $out  
       
   121   echo -e "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
       
   122   echo -e "       List(List(Some(312.204773), Some(26.782711))," | tee -a $out
       
   123   echo -e "            List(Some(301.0466),   Some(41.244694))," | tee -a $out
       
   124   echo -e "            List(Some(331.462585), Some(51.464207)))" | tee -a $out
       
   125 
       
   126   if (scala_assert "drumb.scala" "drumb_test3.scala")
       
   127   then
       
   128       echo -e "  --> success" | tee -a $out
       
   129       marks=$(( marks + 1 ))
       
   130   else
       
   131       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   132   fi
       
   133 fi
       
   134 
       
   135 ### get_delta test
       
   136 
       
   137 if [ $tsts -eq 0 ]
       
   138 then
       
   139   echo -e "  get_delta(None, None) == None" | tee -a $out
       
   140   echo -e "  get_delta(Some(50.0), None) == None" | tee -a $out
       
   141   echo -e "  get_delta(None, Some(100.0)) == None" | tee -a $out
       
   142   echo -e "  get_delta(Some(50.0), Some(100.0)) == Some(1.0)" | tee -a $out
       
   143 
       
   144   if (scala_assert "drumb.scala" "drumb_test4.scala")
       
   145   then
       
   146       echo -e "  --> success" | tee -a $out
       
   147       marks=$(( marks + 1 ))
       
   148   else
       
   149       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   150   fi
       
   151 fi
       
   152 
       
   153 
       
   154 ### get_deltas_test
       
   155 
       
   156 if [ $tsts -eq 0 ]
       
   157 then
       
   158   echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out
       
   159   echo -e "    List(List(Some(-0.03573991804411003), Some(0.539974575389325)), " | tee -a $out
       
   160   echo -e "         List(Some(0.10103414222249969), Some(0.24777764141006836)))" | tee -a $out
       
   161   echo -e "" | tee -a $out
       
   162   echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out
       
   163   echo -e "    List(List(None), List(None),                          " | tee -a $out
       
   164   echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))" | tee -a $out
       
   165   
       
   166   if (scala_assert "drumb.scala" "drumb_test5.scala") 
       
   167   then
       
   168      echo -e "  --> success" | tee -a $out
       
   169      marks=$(( marks + 1 ))
       
   170   else
       
   171      echo -e "  --> TEST FAILED\n" | tee -a $out
       
   172   fi
       
   173 fi
       
   174 
       
   175 
       
   176 ### yield_tests
       
   177 
       
   178 if [ $tsts -eq 0 ]
       
   179 then
       
   180   echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out
       
   181   echo -e "  yearly_yield(ds, 100, 0) == 125" | tee -a $out
       
   182   echo -e "  yearly_yield(ds, 100, 1) == 117" | tee -a $out
       
   183   
       
   184   if (scala_assert "drumb.scala" "drumb_test6.scala") 
       
   185   then
       
   186       echo -e "  --> success" | tee -a $out
       
   187       marks=$(( marks + 1 ))
       
   188   else
       
   189       echo -e "  --> TEST FAILED\n" | tee -a $out
       
   190   fi
       
   191 fi
       
   192 
       
   193 
       
   194 ### investment_test
       
   195 
       
   196 if [ $tsts -eq 0 ]
       
   197 then
       
   198   echo -e "  All results need to be in the range of -/+ 1% of the given values."   | tee -a $out
       
   199   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   | tee -a $out
       
   200   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   | tee -a $out
       
   201   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   | tee -a $out
       
   202   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   | tee -a $out
       
   203   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   | tee -a $out
       
   204   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   | tee -a $out
       
   205   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   | tee -a $out
       
   206   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   | tee -a $out
       
   207   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504"   | tee -a $out
       
   208   
       
   209   
       
   210   if (scala_assert "drumb.scala" "drumb_test7.scala") 
       
   211   then
       
   212     echo -e "  --> success" | tee -a $out
       
   213     marks=$(( marks + 1 ))
       
   214   else
       
   215     echo -e "  --> TEST FAILED\n" | tee -a $out
       
   216   fi
       
   217 fi
       
   218 
       
   219 ## final marks
       
   220 echo -e "" >> $out
       
   221 echo -e "Overall mark for Main Part 1 (Scala)" | tee -a $out
       
   222 echo -e "$marks" | tee -a $out
       
   223 
       
   224 
       
   225 sleep 10