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