| 158 |      1 | #!/bin/bash
 | 
| 331 |      2 | 
 | 
|  |      3 | # to make the script fail safely
 | 
| 169 |      4 | set -euo pipefail
 | 
|  |      5 | 
 | 
| 158 |      6 | out=${1:-output}
 | 
|  |      7 | 
 | 
| 266 |      8 | echo "" > $out
 | 
| 158 |      9 | 
 | 
| 330 |     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 "for the Core Part of Assignment 6.  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
 | 
| 266 |     17 | 
 | 
|  |     18 | # marks for CW6 main part 
 | 
|  |     19 | marks=$(( 0 ))
 | 
|  |     20 | 
 | 
| 210 |     21 | 
 | 
| 330 |     22 | echo -e "" >> $out
 | 
|  |     23 | echo -e "Below is the feedback for your submission drumb.scala" >> $out
 | 
|  |     24 | echo -e "" >> $out
 | 
| 158 |     25 | 
 | 
| 169 |     26 | 
 | 
| 158 |     27 | # compilation tests
 | 
|  |     28 | 
 | 
|  |     29 | function scala_compile {
 | 
| 331 |     30 |     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
 | 
| 158 |     31 | }
 | 
|  |     32 | 
 | 
|  |     33 | # functional tests
 | 
|  |     34 | 
 | 
|  |     35 | function scala_assert {
 | 
| 331 |     36 |     (ulimit -t 30; JAVA_OPTS="-Xmx4g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
| 158 |     37 | }
 | 
|  |     38 | 
 | 
| 169 |     39 | 
 | 
| 158 |     40 | # purity test
 | 
|  |     41 | 
 | 
|  |     42 | function scala_vars {
 | 
| 169 |     43 |    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
 | 
| 158 |     44 | }
 | 
|  |     45 | 
 | 
|  |     46 | 
 | 
| 169 |     47 | 
 | 
| 158 |     48 | # var, .par return, ListBuffer test
 | 
|  |     49 | #
 | 
| 330 |     50 | echo -e "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
 | 
| 158 |     51 | 
 | 
|  |     52 | if (scala_vars drumb.scala)
 | 
|  |     53 | then
 | 
| 330 |     54 |   echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 158 |     55 |   tsts0=$(( 1 ))
 | 
|  |     56 | else
 | 
| 330 |     57 |   echo -e "  --> success" | tee -a $out
 | 
| 158 |     58 |   tsts0=$(( 0 )) 
 | 
|  |     59 | fi
 | 
|  |     60 | 
 | 
|  |     61 | 
 | 
|  |     62 | # compilation test
 | 
|  |     63 | if  [ $tsts0 -eq 0 ]
 | 
|  |     64 | then 
 | 
| 330 |     65 |   echo -e "drumb.scala runs?" | tee -a $out
 | 
| 158 |     66 | 
 | 
| 169 |     67 |   if (scala_compile drumb.scala)
 | 
| 158 |     68 |   then
 | 
| 330 |     69 |     echo -e "  --> success" | tee -a $out
 | 
| 158 |     70 |     tsts=$(( 0 ))
 | 
|  |     71 |   else
 | 
| 330 |     72 |     echo -e "  --> SCALA DID NOT RUN drumb.scala" | tee -a $out
 | 
| 158 |     73 |     tsts=$(( 1 )) 
 | 
|  |     74 |   fi
 | 
|  |     75 | else
 | 
|  |     76 |   tsts=$(( 1 ))     
 | 
|  |     77 | fi
 | 
|  |     78 | 
 | 
| 266 |     79 | echo >> $out
 | 
|  |     80 | 
 | 
| 210 |     81 | ### get january tests
 | 
| 158 |     82 | 
 | 
| 210 |     83 | if [ $tsts -eq 0 ]
 | 
|  |     84 | then
 | 
| 330 |     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
 | 
| 210 |     87 | 
 | 
|  |     88 |   if (scala_assert "drumb.scala" "drumb_test1.scala")
 | 
|  |     89 |   then
 | 
| 330 |     90 |       echo -e "  --> success" | tee -a $out
 | 
| 210 |     91 |       marks=$(( marks + 1 ))
 | 
|  |     92 |   else
 | 
| 330 |     93 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 210 |     94 |   fi
 | 
|  |     95 | fi
 | 
|  |     96 | 
 | 
|  |     97 | ### get first price tests
 | 
|  |     98 | 
 | 
|  |     99 | if [ $tsts -eq 0 ]
 | 
|  |    100 | then
 | 
| 330 |    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
 | 
| 210 |    103 | 
 | 
|  |    104 |   if (scala_assert "drumb.scala" "drumb_test2.scala")
 | 
|  |    105 |   then
 | 
| 330 |    106 |       echo -e "  --> success" | tee -a $out
 | 
| 210 |    107 |       marks=$(( marks + 1 ))
 | 
|  |    108 |   else
 | 
| 330 |    109 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 210 |    110 |   fi
 | 
|  |    111 | fi
 | 
| 158 |    112 | 
 | 
|  |    113 | ### get prices tests
 | 
|  |    114 | 
 | 
|  |    115 | if [ $tsts -eq 0 ]
 | 
|  |    116 | then
 | 
| 330 |    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
 | 
| 158 |    125 | 
 | 
| 210 |    126 |   if (scala_assert "drumb.scala" "drumb_test3.scala")
 | 
| 158 |    127 |   then
 | 
| 330 |    128 |       echo -e "  --> success" | tee -a $out
 | 
| 169 |    129 |       marks=$(( marks + 1 ))
 | 
| 158 |    130 |   else
 | 
| 330 |    131 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 158 |    132 |   fi
 | 
|  |    133 | fi
 | 
|  |    134 | 
 | 
| 266 |    135 | ### get_delta test
 | 
|  |    136 | 
 | 
|  |    137 | if [ $tsts -eq 0 ]
 | 
|  |    138 | then
 | 
| 330 |    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
 | 
| 266 |    143 | 
 | 
|  |    144 |   if (scala_assert "drumb.scala" "drumb_test4.scala")
 | 
|  |    145 |   then
 | 
| 330 |    146 |       echo -e "  --> success" | tee -a $out
 | 
| 266 |    147 |       marks=$(( marks + 1 ))
 | 
|  |    148 |   else
 | 
| 330 |    149 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 266 |    150 |   fi
 | 
|  |    151 | fi
 | 
|  |    152 | 
 | 
|  |    153 | 
 | 
| 210 |    154 | ### get_deltas_test
 | 
|  |    155 | 
 | 
| 266 |    156 | if [ $tsts -eq 0 ]
 | 
|  |    157 | then
 | 
|  |    158 |   echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out
 | 
| 268 |    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
 | 
| 266 |    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
 | 
| 284 |    164 |   echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))" | tee -a $out
 | 
| 266 |    165 |   
 | 
|  |    166 |   if (scala_assert "drumb.scala" "drumb_test5.scala") 
 | 
|  |    167 |   then
 | 
| 330 |    168 |      echo -e "  --> success" | tee -a $out
 | 
| 266 |    169 |      marks=$(( marks + 1 ))
 | 
|  |    170 |   else
 | 
| 330 |    171 |      echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 266 |    172 |   fi
 | 
|  |    173 | fi
 | 
| 210 |    174 | 
 | 
| 158 |    175 | 
 | 
| 266 |    176 | ### yield_tests
 | 
| 158 |    177 | 
 | 
| 266 |    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
 | 
| 330 |    181 |   echo -e "  yearly_yield(ds, 100, 0) == 125" | tee -a $out
 | 
|  |    182 |   echo -e "  yearly_yield(ds, 100, 1) == 117" | tee -a $out
 | 
| 266 |    183 |   
 | 
|  |    184 |   if (scala_assert "drumb.scala" "drumb_test6.scala") 
 | 
|  |    185 |   then
 | 
| 330 |    186 |       echo -e "  --> success" | tee -a $out
 | 
| 266 |    187 |       marks=$(( marks + 1 ))
 | 
|  |    188 |   else
 | 
| 330 |    189 |       echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 266 |    190 |   fi
 | 
|  |    191 | fi
 | 
| 158 |    192 | 
 | 
| 169 |    193 | 
 | 
| 266 |    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
 | 
| 268 |    207 |   echo -e "   investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504"   | tee -a $out
 | 
| 266 |    208 |   
 | 
|  |    209 |   
 | 
|  |    210 |   if (scala_assert "drumb.scala" "drumb_test7.scala") 
 | 
|  |    211 |   then
 | 
| 330 |    212 |     echo -e "  --> success" | tee -a $out
 | 
| 266 |    213 |     marks=$(( marks + 1 ))
 | 
|  |    214 |   else
 | 
| 330 |    215 |     echo -e "  --> TEST FAILED\n" | tee -a $out
 | 
| 266 |    216 |   fi
 | 
|  |    217 | fi
 | 
| 169 |    218 | 
 | 
|  |    219 | ## final marks
 | 
| 330 |    220 | echo -e "" >> $out
 | 
|  |    221 | echo -e "Overall mark for CW 6, Core Part" | tee -a $out
 | 
|  |    222 | echo -e "$marks" | tee -a $out
 |