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