1 #!/bin/bash |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 out=${1:-output} |
|
7 |
|
8 echo "" > $out |
|
9 |
|
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 |
|
17 |
|
18 # marks for CW6 main part |
|
19 marks=$(( 0 )) |
|
20 |
|
21 |
|
22 echo -e "" >> $out |
|
23 echo -e "Below is the feedback for your submission drumb.scala" >> $out |
|
24 echo -e "" >> $out |
|
25 |
|
26 |
|
27 # compilation tests |
|
28 |
|
29 function scala_compile { |
|
30 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) |
|
31 } |
|
32 |
|
33 # functional tests |
|
34 |
|
35 function scala_assert { |
|
36 (ulimit -t 30; JAVA_OPTS="-Xmx4g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
37 } |
|
38 |
|
39 |
|
40 # purity test |
|
41 |
|
42 #function scala_vars { |
|
43 # (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
44 #} |
|
45 |
|
46 function scala_vars { |
|
47 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
48 } |
|
49 |
|
50 # var, .par return, ListBuffer test |
|
51 # |
|
52 echo -e "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
53 |
|
54 if (scala_vars drumb.scala) |
|
55 then |
|
56 echo -e " --> TEST FAILED\n" | tee -a $out |
|
57 tsts0=$(( 1 )) |
|
58 else |
|
59 echo -e " --> success" | tee -a $out |
|
60 tsts0=$(( 0 )) |
|
61 fi |
|
62 |
|
63 |
|
64 # compilation test |
|
65 if [ $tsts0 -eq 0 ] |
|
66 then |
|
67 echo -e "drumb.scala runs?" | tee -a $out |
|
68 |
|
69 if (scala_compile drumb.scala) |
|
70 then |
|
71 echo -e " --> success" | tee -a $out |
|
72 tsts=$(( 0 )) |
|
73 else |
|
74 echo -e " --> SCALA DID NOT RUN drumb.scala" | tee -a $out |
|
75 tsts=$(( 1 )) |
|
76 fi |
|
77 else |
|
78 tsts=$(( 1 )) |
|
79 fi |
|
80 |
|
81 echo >> $out |
|
82 |
|
83 ### get january tests |
|
84 |
|
85 if [ $tsts -eq 0 ] |
|
86 then |
|
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 |
|
89 |
|
90 if (scala_assert "drumb.scala" "drumb_test1.scala") |
|
91 then |
|
92 echo -e " --> success" | tee -a $out |
|
93 marks=$(( marks + 1 )) |
|
94 else |
|
95 echo -e " --> TEST FAILED\n" | tee -a $out |
|
96 fi |
|
97 fi |
|
98 |
|
99 ### get first price tests |
|
100 |
|
101 if [ $tsts -eq 0 ] |
|
102 then |
|
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 |
|
105 |
|
106 if (scala_assert "drumb.scala" "drumb_test2.scala") |
|
107 then |
|
108 echo -e " --> success" | tee -a $out |
|
109 marks=$(( marks + 1 )) |
|
110 else |
|
111 echo -e " --> TEST FAILED\n" | tee -a $out |
|
112 fi |
|
113 fi |
|
114 |
|
115 ### get prices tests |
|
116 |
|
117 if [ $tsts -eq 0 ] |
|
118 then |
|
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 |
|
127 |
|
128 if (scala_assert "drumb.scala" "drumb_test3.scala") |
|
129 then |
|
130 echo -e " --> success" | tee -a $out |
|
131 marks=$(( marks + 1 )) |
|
132 else |
|
133 echo -e " --> TEST FAILED\n" | tee -a $out |
|
134 fi |
|
135 fi |
|
136 |
|
137 ### get_delta test |
|
138 |
|
139 if [ $tsts -eq 0 ] |
|
140 then |
|
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 |
|
145 |
|
146 if (scala_assert "drumb.scala" "drumb_test4.scala") |
|
147 then |
|
148 echo -e " --> success" | tee -a $out |
|
149 marks=$(( marks + 1 )) |
|
150 else |
|
151 echo -e " --> TEST FAILED\n" | tee -a $out |
|
152 fi |
|
153 fi |
|
154 |
|
155 |
|
156 ### get_deltas_test |
|
157 |
|
158 if [ $tsts -eq 0 ] |
|
159 then |
|
160 echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out |
|
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 |
|
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 |
|
166 echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))" | tee -a $out |
|
167 |
|
168 if (scala_assert "drumb.scala" "drumb_test5.scala") |
|
169 then |
|
170 echo -e " --> success" | tee -a $out |
|
171 marks=$(( marks + 1 )) |
|
172 else |
|
173 echo -e " --> TEST FAILED\n" | tee -a $out |
|
174 fi |
|
175 fi |
|
176 |
|
177 |
|
178 ### yield_tests |
|
179 |
|
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 |
|
183 echo -e " yearly_yield(ds, 100, 0) == 125" | tee -a $out |
|
184 echo -e " yearly_yield(ds, 100, 1) == 117" | tee -a $out |
|
185 |
|
186 if (scala_assert "drumb.scala" "drumb_test6.scala") |
|
187 then |
|
188 echo -e " --> success" | tee -a $out |
|
189 marks=$(( marks + 1 )) |
|
190 else |
|
191 echo -e " --> TEST FAILED\n" | tee -a $out |
|
192 fi |
|
193 fi |
|
194 |
|
195 |
|
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 |
|
209 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504" | tee -a $out |
|
210 |
|
211 |
|
212 if (scala_assert "drumb.scala" "drumb_test7.scala") |
|
213 then |
|
214 echo -e " --> success" | tee -a $out |
|
215 marks=$(( marks + 1 )) |
|
216 else |
|
217 echo -e " --> TEST FAILED\n" | tee -a $out |
|
218 fi |
|
219 fi |
|
220 |
|
221 ## final marks |
|
222 echo -e "" >> $out |
|
223 echo -e "Overall mark for CW 6, Core Part" | tee -a $out |
|
224 echo -e "$marks" | tee -a $out |
|