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