1 #!/bin/bash |
|
2 set -euo pipefail |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo -e "" > $out |
|
7 |
|
8 echo -e "Below is the feedback for your submission for drumb.scala" >> $out |
|
9 echo -e "" >> $out |
|
10 |
|
11 # compilation tests |
|
12 |
|
13 function scala_compile { |
|
14 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
|
15 } |
|
16 |
|
17 # functional tests |
|
18 |
|
19 function scala_assert { |
|
20 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
21 } |
|
22 |
|
23 # purity test |
|
24 |
|
25 function scala_vars { |
|
26 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
27 } |
|
28 |
|
29 |
|
30 # var, .par return, ListBuffer test |
|
31 # |
|
32 echo -e "drumb.scala does not contain vars, returns etc?" >> $out |
|
33 |
|
34 if (scala_vars drumb.scala) |
|
35 then |
|
36 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
37 tsts0=$(( 0 )) |
|
38 else |
|
39 echo -e " --> success" >> $out |
|
40 tsts0=$(( 0 )) |
|
41 fi |
|
42 |
|
43 |
|
44 # compilation test |
|
45 if [ $tsts0 -eq 0 ] |
|
46 then |
|
47 echo -e "drumb.scala runs?" >> $out |
|
48 |
|
49 if (scala_compile drumb.scala) |
|
50 then |
|
51 echo -e " --> success" >> $out |
|
52 tsts=$(( 0 )) |
|
53 else |
|
54 echo -e " --> SCALA DID NOT RUN drumb.scala" >> $out |
|
55 tsts=$(( 1 )) |
|
56 fi |
|
57 else |
|
58 tsts=$(( 1 )) |
|
59 fi |
|
60 |
|
61 ### get january data |
|
62 |
|
63 if [ $tsts -eq 0 ] |
|
64 then |
|
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 |
|
67 |
|
68 if (scala_assert "drumb.scala" "drumb_test1.scala") |
|
69 then |
|
70 echo -e " --> success" >> $out |
|
71 else |
|
72 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
73 fi |
|
74 fi |
|
75 |
|
76 ### get first price |
|
77 |
|
78 if [ $tsts -eq 0 ] |
|
79 then |
|
80 echo -e " get_first_price(\"GOOG\", 1980) == None" >> $out |
|
81 echo -e " get_first_price(\"GOOG\", 2010) == Some(312.204773)" >> $out |
|
82 |
|
83 if (scala_assert "drumb.scala" "drumb_test2.scala") |
|
84 then |
|
85 echo -e " --> success" >> $out |
|
86 else |
|
87 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
88 fi |
|
89 fi |
|
90 |
|
91 ### get prices tests |
|
92 |
|
93 if [ $tsts -eq 0 ] |
|
94 then |
|
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 |
|
99 |
|
100 if (scala_assert "drumb.scala" "drumb_test3.scala") |
|
101 then |
|
102 echo -e " --> success" >> $out |
|
103 else |
|
104 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
105 fi |
|
106 fi |
|
107 |
|
108 ### get_delta_test |
|
109 |
|
110 if [ $tsts -eq 0 ] |
|
111 then |
|
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 |
|
116 |
|
117 if (scala_assert "drumb.scala" "drumb_test4.scala") |
|
118 then |
|
119 echo -e " --> success" >> $out |
|
120 else |
|
121 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
122 fi |
|
123 fi |
|
124 |
|
125 |
|
126 ### get_deltas_test |
|
127 |
|
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 |
|
136 echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104))) " >> $out |
|
137 |
|
138 if (scala_assert "drumb.scala" "drumb_test5.scala") |
|
139 then |
|
140 echo -e " --> success" >> $out |
|
141 else |
|
142 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
143 fi |
|
144 fi |
|
145 |
|
146 |
|
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 |
|
152 echo -e " yearly_yield(ds, 100, 0) == 125" >> $out |
|
153 echo -e " yearly_yield(ds, 100, 1) == 117" >> $out |
|
154 |
|
155 if (scala_assert "drumb.scala" "drumb_test6.scala") |
|
156 then |
|
157 echo -e " --> success" >> $out |
|
158 else |
|
159 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
160 fi |
|
161 fi |
|
162 |
|
163 |
|
164 ### investment_test |
|
165 |
|
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 |
|
182 echo -e " --> success" >> $out |
|
183 else |
|
184 echo -e " --> ONE OF THE TESTS FAILED\n" >> $out |
|
185 fi |
|
186 fi |
|
187 |
|