marking1/drumb_test.sh
changeset 210 63a1376cbebd
parent 169 b37052895281
child 261 8997430d9765
equal deleted inserted replaced
209:40bdf9064e13 210:63a1376cbebd
     2 set -euo pipefail
     2 set -euo pipefail
     3 
     3 
     4 
     4 
     5 out=${1:-output}
     5 out=${1:-output}
     6 
     6 
     7 echo "" > $out
     7 # read marks for CW6 part 1
       
     8 marks=$(( `tail -1 $out` ))
     8 
     9 
     9 echo "Below is the feedback and provisional marks for your submission" >> $out
    10 echo $marks
    10 echo "for assignment 6 Part 3.  Please note all marks are provisional until" >> $out
    11 
    11 echo "ratified by the assessment board -- this is not an official" >> $out
    12 echo "" >> $out
    12 echo "results transcript." >> $out
    13 echo "Below is the feedback for your submission drumb.scala" >> $out
    13 echo "" >> $out
    14 echo "" >> $out
    14 
    15 
    15 # marks for CW7 part 3
       
    16 marks=$(( 0 ))
       
    17 
    16 
    18 # compilation tests
    17 # compilation tests
    19 
    18 
    20 function scala_compile {
    19 function scala_compile {
    21     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
    20     (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
    22 }
    21 }
    23 
    22 
    24 # functional tests
    23 # functional tests
    25 
    24 
    26 function scala_assert {
    25 function scala_assert {
    27     (ulimit -t 360; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    26     (ulimit -t 60; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    28 }
    27 }
    29 
    28 
    30 
    29 
    31 # purity test
    30 # purity test
    32 
    31 
    65   fi
    64   fi
    66 else
    65 else
    67   tsts=$(( 1 ))     
    66   tsts=$(( 1 ))     
    68 fi
    67 fi
    69 
    68 
    70 
    69 ### get january tests
    71 
       
    72 ### get prices tests
       
    73 
    70 
    74 if [ $tsts -eq 0 ]
    71 if [ $tsts -eq 0 ]
    75 then
    72 then
    76   echo " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
    73   echo "  get_january_data(\"GOOG\", 1980) == List()" | tee -a $out
    77   echo "       List(List(None), List(None), List(Some(6.35)), " | tee -a $out
    74   echo "  get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" | tee -a $out
    78   echo "            List(Some(12.241)), List(Some(38.188)))" | tee -a $out
       
    79   echo " " | tee -a $out  
       
    80   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
       
    81   echo "       List(List(Some(311.349976), Some(27.505054))," | tee -a $out
       
    82   echo "            List(Some(300.222351), Some(42.357094))," | tee -a $out
       
    83   echo "            List(Some(330.555054), Some(52.852215)))" | tee -a $out
       
    84 
    75 
    85   if (scala_assert "drumb.scala" "drumb_test1.scala")
    76   if (scala_assert "drumb.scala" "drumb_test1.scala")
    86   then
       
    87       echo "  --> success" | tee -a $out
       
    88       marks=$(( marks + 2 ))
       
    89   else
       
    90       echo "  --> test failed" | tee -a $out
       
    91   fi
       
    92 fi
       
    93 
       
    94 ### get_deltas_test
       
    95 
       
    96 if [ $tsts -eq 0 ]
       
    97 then
       
    98   echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
       
    99   echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
       
   100   echo " " | tee -a $out  
       
   101   echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out
       
   102   echo "                             List(Some(0.9277165354330709)), " | tee -a $out
       
   103   echo "                             List(Some(2.119679764725104)))" | tee -a $out
       
   104   echo " " | tee -a $out  
       
   105   echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out
       
   106   echo "                             List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out
       
   107   
       
   108   if (scala_assert "drumb.scala" "drumb_test2.scala") 
       
   109   then
    77   then
   110       echo "  --> success" | tee -a $out
    78       echo "  --> success" | tee -a $out
   111       marks=$(( marks + 1 ))
    79       marks=$(( marks + 1 ))
   112   else
    80   else
   113       echo "  --> test failed" | tee -a $out
    81       echo "  --> test failed" | tee -a $out
   114   fi
    82   fi
   115 fi
    83 fi
   116 
    84 
   117 
    85 ### get first price tests
   118 ### yield_tests, investment_test
       
   119 
    86 
   120 if [ $tsts -eq 0 ]
    87 if [ $tsts -eq 0 ]
   121 then
    88 then
   122   echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
    89   echo "  get_first_price(\"GOOG\", 1980) == None" | tee -a $out
   123   echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
    90   echo "  get_first_price(\"GOOG\", 2010) == Some(311.349976)" | tee -a $out
   124   echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out 
    91 
   125   echo " val deltas1 = get_deltas(prices1)" | tee -a $out
    92   if (scala_assert "drumb.scala" "drumb_test2.scala")
   126   echo " val deltas2 = get_deltas(prices2)" | tee -a $out
       
   127   echo " val deltas3 = get_deltas(prices3)" | tee -a $out
       
   128   echo "" | tee -a $out
       
   129   echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out
       
   130   echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out
       
   131   echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out
       
   132   echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out
       
   133   echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out
       
   134   echo "" | tee -a $out
       
   135   echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out
       
   136   echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out
       
   137   echo "" | tee -a $out
       
   138   echo " inv1 >= 295 && inv1 <= 301" | tee -a $out
       
   139   echo " inv2 >= 194 && inv2 <= 198" | tee -a $out
       
   140   
       
   141   if (scala_assert "drumb.scala" "drumb_test3.scala") 
       
   142   then
    93   then
   143       echo "  --> success" | tee -a $out
    94       echo "  --> success" | tee -a $out
   144       marks=$(( marks + 1 ))
    95       marks=$(( marks + 1 ))
   145   else
    96   else
   146       echo "  --> test failed" | tee -a $out
    97       echo "  --> test failed" | tee -a $out
   147   fi
    98   fi
   148 fi
    99 fi
   149 
   100 
       
   101 ### get prices tests
       
   102 
       
   103 if [ $tsts -eq 0 ]
       
   104 then
       
   105   echo "  get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
       
   106   echo "       List(List(None), List(None), List(Some(6.35)), " | tee -a $out
       
   107   echo "            List(Some(12.241)), List(Some(38.188)))" | tee -a $out
       
   108   echo " " | tee -a $out  
       
   109   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
       
   110   echo "       List(List(Some(311.349976), Some(20.544939))," | tee -a $out
       
   111   echo "            List(Some(300.222351), Some(31.638695))," | tee -a $out
       
   112   echo "            List(Some(330.555054), Some(39.478039)))" | tee -a $out
       
   113 
       
   114   if (scala_assert "drumb.scala" "drumb_test3.scala")
       
   115   then
       
   116       echo "  --> success" | tee -a $out
       
   117       marks=$(( marks + 1 ))
       
   118   else
       
   119       echo "  --> test failed" | tee -a $out
       
   120   fi
       
   121 fi
       
   122 
       
   123 ### get_deltas_test
       
   124 
       
   125 #if [ $tsts -eq 0 ]
       
   126 #then
       
   127 #  echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
       
   128 #  echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
       
   129 #  echo " " | tee -a $out  
       
   130 #  echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out
       
   131 #  echo "                             List(Some(0.9277165354330709)), " | tee -a $out
       
   132 #  echo "                             List(Some(2.119679764725104)))" | tee -a $out
       
   133 #  echo " " | tee -a $out  
       
   134 #  echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out
       
   135 #  echo "                             List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out
       
   136 #  
       
   137 #  if (scala_assert "drumb.scala" "drumb_test2.scala") 
       
   138 #  then
       
   139 #      echo "  --> success" | tee -a $out
       
   140 #      marks=$(( marks + 1 ))
       
   141 #  else
       
   142 #      echo "  --> test failed" | tee -a $out
       
   143 #  fi
       
   144 #fi
       
   145 
       
   146 
       
   147 ### yield_tests, investment_test
       
   148 
       
   149 #if [ $tsts -eq 0 ]
       
   150 #then
       
   151 #  echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
       
   152 #  echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
       
   153 #  echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out 
       
   154 #  echo " val deltas1 = get_deltas(prices1)" | tee -a $out
       
   155 #  echo " val deltas2 = get_deltas(prices2)" | tee -a $out
       
   156 #  echo " val deltas3 = get_deltas(prices3)" | tee -a $out
       
   157 #  echo "" | tee -a $out
       
   158 #  echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out
       
   159 #  echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out
       
   160 #  echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out
       
   161 #  echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out
       
   162 #  echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out
       
   163 #  echo "" | tee -a $out
       
   164 #  echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out
       
   165 #  echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out
       
   166 #  echo "" | tee -a $out
       
   167 #  echo " inv1 >= 295 && inv1 <= 301" | tee -a $out
       
   168 #  echo " inv2 >= 194 && inv2 <= 198" | tee -a $out
       
   169 #  
       
   170 #  if (scala_assert "drumb.scala" "drumb_test3.scala") 
       
   171 #  then
       
   172 #      echo "  --> success" | tee -a $out
       
   173 #      marks=$(( marks + 1 ))
       
   174 #  else
       
   175 #      echo "  --> test failed" | tee -a $out
       
   176 #  fi
       
   177 #fi
       
   178 
   150 
   179 
   151 
   180 
   152 ## final marks
   181 ## final marks
   153 echo "Overall mark for CW 6, Part 3" | tee -a $out
   182 echo "Overall mark for CW 6, Part 1 + 2" | tee -a $out
   154 echo "$marks" | tee -a $out
   183 echo "$marks" | tee -a $out