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