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