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 |
|
333
|
42 |
#function scala_vars {
|
|
43 |
# (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
44 |
#}
|
|
45 |
|
158
|
46 |
function scala_vars {
|
333
|
47 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|new Array' "$1" 2> /dev/null 1> /dev/null)
|
158
|
48 |
}
|
|
49 |
|
|
50 |
# var, .par return, ListBuffer test
|
|
51 |
#
|
330
|
52 |
echo -e "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
158
|
53 |
|
|
54 |
if (scala_vars drumb.scala)
|
|
55 |
then
|
330
|
56 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
158
|
57 |
tsts0=$(( 1 ))
|
|
58 |
else
|
330
|
59 |
echo -e " --> success" | tee -a $out
|
158
|
60 |
tsts0=$(( 0 ))
|
|
61 |
fi
|
|
62 |
|
|
63 |
|
|
64 |
# compilation test
|
|
65 |
if [ $tsts0 -eq 0 ]
|
|
66 |
then
|
330
|
67 |
echo -e "drumb.scala runs?" | tee -a $out
|
158
|
68 |
|
169
|
69 |
if (scala_compile drumb.scala)
|
158
|
70 |
then
|
330
|
71 |
echo -e " --> success" | tee -a $out
|
158
|
72 |
tsts=$(( 0 ))
|
|
73 |
else
|
330
|
74 |
echo -e " --> SCALA DID NOT RUN drumb.scala" | tee -a $out
|
158
|
75 |
tsts=$(( 1 ))
|
|
76 |
fi
|
|
77 |
else
|
|
78 |
tsts=$(( 1 ))
|
|
79 |
fi
|
|
80 |
|
266
|
81 |
echo >> $out
|
|
82 |
|
210
|
83 |
### get january tests
|
158
|
84 |
|
210
|
85 |
if [ $tsts -eq 0 ]
|
|
86 |
then
|
330
|
87 |
echo -e " get_january_data(\"GOOG\", 1980) == List()" | tee -a $out
|
|
88 |
echo -e " get_january_data(\"GOOG\", 2010).head == \"2010-01-04,312.204773\"" | tee -a $out
|
210
|
89 |
|
|
90 |
if (scala_assert "drumb.scala" "drumb_test1.scala")
|
|
91 |
then
|
330
|
92 |
echo -e " --> success" | tee -a $out
|
210
|
93 |
marks=$(( marks + 1 ))
|
|
94 |
else
|
330
|
95 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
210
|
96 |
fi
|
|
97 |
fi
|
|
98 |
|
|
99 |
### get first price tests
|
|
100 |
|
|
101 |
if [ $tsts -eq 0 ]
|
|
102 |
then
|
330
|
103 |
echo -e " get_first_price(\"GOOG\", 1980) == None" | tee -a $out
|
|
104 |
echo -e " get_first_price(\"GOOG\", 2010) == Some(312.204773)" | tee -a $out
|
210
|
105 |
|
|
106 |
if (scala_assert "drumb.scala" "drumb_test2.scala")
|
|
107 |
then
|
330
|
108 |
echo -e " --> success" | tee -a $out
|
210
|
109 |
marks=$(( marks + 1 ))
|
|
110 |
else
|
330
|
111 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
210
|
112 |
fi
|
|
113 |
fi
|
158
|
114 |
|
|
115 |
### get prices tests
|
|
116 |
|
|
117 |
if [ $tsts -eq 0 ]
|
|
118 |
then
|
330
|
119 |
echo -e " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
|
|
120 |
echo -e " List(List(None), List(None), List(Some(6.35)), " | tee -a $out
|
|
121 |
echo -e " List(Some(12.241)), List(Some(38.188)))" | tee -a $out
|
|
122 |
echo -e " " | tee -a $out
|
|
123 |
echo -e " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
|
|
124 |
echo -e " List(List(Some(312.204773), Some(26.782711))," | tee -a $out
|
|
125 |
echo -e " List(Some(301.0466), Some(41.244694))," | tee -a $out
|
|
126 |
echo -e " List(Some(331.462585), Some(51.464207)))" | tee -a $out
|
158
|
127 |
|
210
|
128 |
if (scala_assert "drumb.scala" "drumb_test3.scala")
|
158
|
129 |
then
|
330
|
130 |
echo -e " --> success" | tee -a $out
|
169
|
131 |
marks=$(( marks + 1 ))
|
158
|
132 |
else
|
330
|
133 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
158
|
134 |
fi
|
|
135 |
fi
|
|
136 |
|
266
|
137 |
### get_delta test
|
|
138 |
|
|
139 |
if [ $tsts -eq 0 ]
|
|
140 |
then
|
330
|
141 |
echo -e " get_delta(None, None) == None" | tee -a $out
|
|
142 |
echo -e " get_delta(Some(50.0), None) == None" | tee -a $out
|
|
143 |
echo -e " get_delta(None, Some(100.0)) == None" | tee -a $out
|
|
144 |
echo -e " get_delta(Some(50.0), Some(100.0)) == Some(1.0)" | tee -a $out
|
266
|
145 |
|
|
146 |
if (scala_assert "drumb.scala" "drumb_test4.scala")
|
|
147 |
then
|
330
|
148 |
echo -e " --> success" | tee -a $out
|
266
|
149 |
marks=$(( marks + 1 ))
|
|
150 |
else
|
330
|
151 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
266
|
152 |
fi
|
|
153 |
fi
|
|
154 |
|
|
155 |
|
210
|
156 |
### get_deltas_test
|
|
157 |
|
266
|
158 |
if [ $tsts -eq 0 ]
|
|
159 |
then
|
|
160 |
echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out
|
268
|
161 |
echo -e " List(List(Some(-0.03573991804411003), Some(0.539974575389325)), " | tee -a $out
|
|
162 |
echo -e " List(Some(0.10103414222249969), Some(0.24777764141006836)))" | tee -a $out
|
266
|
163 |
echo -e "" | tee -a $out
|
|
164 |
echo -e " get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out
|
|
165 |
echo -e " List(List(None), List(None), " | tee -a $out
|
284
|
166 |
echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))" | tee -a $out
|
266
|
167 |
|
|
168 |
if (scala_assert "drumb.scala" "drumb_test5.scala")
|
|
169 |
then
|
330
|
170 |
echo -e " --> success" | tee -a $out
|
266
|
171 |
marks=$(( marks + 1 ))
|
|
172 |
else
|
330
|
173 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
266
|
174 |
fi
|
|
175 |
fi
|
210
|
176 |
|
158
|
177 |
|
266
|
178 |
### yield_tests
|
158
|
179 |
|
266
|
180 |
if [ $tsts -eq 0 ]
|
|
181 |
then
|
|
182 |
echo -e " val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out
|
330
|
183 |
echo -e " yearly_yield(ds, 100, 0) == 125" | tee -a $out
|
|
184 |
echo -e " yearly_yield(ds, 100, 1) == 117" | tee -a $out
|
266
|
185 |
|
|
186 |
if (scala_assert "drumb.scala" "drumb_test6.scala")
|
|
187 |
then
|
330
|
188 |
echo -e " --> success" | tee -a $out
|
266
|
189 |
marks=$(( marks + 1 ))
|
|
190 |
else
|
330
|
191 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
266
|
192 |
fi
|
|
193 |
fi
|
158
|
194 |
|
169
|
195 |
|
266
|
196 |
### investment_test
|
|
197 |
|
|
198 |
if [ $tsts -eq 0 ]
|
|
199 |
then
|
|
200 |
echo -e " All results need to be in the range of -/+ 1% of the given values." | tee -a $out
|
|
201 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" | tee -a $out
|
|
202 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " | tee -a $out
|
|
203 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " | tee -a $out
|
|
204 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " | tee -a $out
|
|
205 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " | tee -a $out
|
|
206 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" | tee -a $out
|
|
207 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" | tee -a $out
|
|
208 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" | tee -a $out
|
268
|
209 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504" | tee -a $out
|
266
|
210 |
|
|
211 |
|
|
212 |
if (scala_assert "drumb.scala" "drumb_test7.scala")
|
|
213 |
then
|
330
|
214 |
echo -e " --> success" | tee -a $out
|
266
|
215 |
marks=$(( marks + 1 ))
|
|
216 |
else
|
330
|
217 |
echo -e " --> TEST FAILED\n" | tee -a $out
|
266
|
218 |
fi
|
|
219 |
fi
|
169
|
220 |
|
|
221 |
## final marks
|
330
|
222 |
echo -e "" >> $out
|
|
223 |
echo -e "Overall mark for CW 6, Core Part" | tee -a $out
|
|
224 |
echo -e "$marks" | tee -a $out
|