158
|
1 |
#!/bin/bash
|
169
|
2 |
set -euo pipefail
|
|
3 |
|
158
|
4 |
|
|
5 |
out=${1:-output}
|
|
6 |
|
210
|
7 |
# read marks for CW6 part 1
|
|
8 |
marks=$(( `tail -1 $out` ))
|
158
|
9 |
|
210
|
10 |
echo $marks
|
|
11 |
|
|
12 |
echo "" >> $out
|
|
13 |
echo "Below is the feedback for your submission drumb.scala" >> $out
|
158
|
14 |
echo "" >> $out
|
|
15 |
|
169
|
16 |
|
158
|
17 |
# compilation tests
|
|
18 |
|
|
19 |
function scala_compile {
|
261
|
20 |
(ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
|
158
|
21 |
}
|
|
22 |
|
|
23 |
# functional tests
|
|
24 |
|
|
25 |
function scala_assert {
|
261
|
26 |
(ulimit -t 60; JAVA_OPTS="-Xmx4g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
158
|
27 |
}
|
|
28 |
|
169
|
29 |
|
158
|
30 |
# purity test
|
|
31 |
|
|
32 |
function scala_vars {
|
169
|
33 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
158
|
34 |
}
|
|
35 |
|
|
36 |
|
169
|
37 |
|
158
|
38 |
# var, .par return, ListBuffer test
|
|
39 |
#
|
169
|
40 |
echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
|
158
|
41 |
|
|
42 |
if (scala_vars drumb.scala)
|
|
43 |
then
|
169
|
44 |
echo " --> test failed" | tee -a $out
|
158
|
45 |
tsts0=$(( 1 ))
|
|
46 |
else
|
169
|
47 |
echo " --> success" | tee -a $out
|
158
|
48 |
tsts0=$(( 0 ))
|
|
49 |
fi
|
|
50 |
|
|
51 |
|
|
52 |
# compilation test
|
|
53 |
if [ $tsts0 -eq 0 ]
|
|
54 |
then
|
169
|
55 |
echo "drumb.scala runs?" | tee -a $out
|
158
|
56 |
|
169
|
57 |
if (scala_compile drumb.scala)
|
158
|
58 |
then
|
169
|
59 |
echo " --> success" | tee -a $out
|
158
|
60 |
tsts=$(( 0 ))
|
|
61 |
else
|
169
|
62 |
echo " --> scala drumb.scala did not run successfully" | tee -a $out
|
158
|
63 |
tsts=$(( 1 ))
|
|
64 |
fi
|
|
65 |
else
|
|
66 |
tsts=$(( 1 ))
|
|
67 |
fi
|
|
68 |
|
210
|
69 |
### get january tests
|
158
|
70 |
|
210
|
71 |
if [ $tsts -eq 0 ]
|
|
72 |
then
|
|
73 |
echo " get_january_data(\"GOOG\", 1980) == List()" | tee -a $out
|
|
74 |
echo " get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" | tee -a $out
|
|
75 |
|
|
76 |
if (scala_assert "drumb.scala" "drumb_test1.scala")
|
|
77 |
then
|
|
78 |
echo " --> success" | tee -a $out
|
|
79 |
marks=$(( marks + 1 ))
|
|
80 |
else
|
|
81 |
echo " --> test failed" | tee -a $out
|
|
82 |
fi
|
|
83 |
fi
|
|
84 |
|
|
85 |
### get first price tests
|
|
86 |
|
|
87 |
if [ $tsts -eq 0 ]
|
|
88 |
then
|
|
89 |
echo " get_first_price(\"GOOG\", 1980) == None" | tee -a $out
|
|
90 |
echo " get_first_price(\"GOOG\", 2010) == Some(311.349976)" | tee -a $out
|
|
91 |
|
|
92 |
if (scala_assert "drumb.scala" "drumb_test2.scala")
|
|
93 |
then
|
|
94 |
echo " --> success" | tee -a $out
|
|
95 |
marks=$(( marks + 1 ))
|
|
96 |
else
|
|
97 |
echo " --> test failed" | tee -a $out
|
|
98 |
fi
|
|
99 |
fi
|
158
|
100 |
|
|
101 |
### get prices tests
|
|
102 |
|
|
103 |
if [ $tsts -eq 0 ]
|
|
104 |
then
|
210
|
105 |
echo " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
|
169
|
106 |
echo " List(List(None), List(None), List(Some(6.35)), " | tee -a $out
|
|
107 |
echo " List(Some(12.241)), List(Some(38.188)))" | tee -a $out
|
|
108 |
echo " " | tee -a $out
|
|
109 |
echo " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
|
210
|
110 |
echo " List(List(Some(311.349976), Some(20.544939))," | tee -a $out
|
|
111 |
echo " List(Some(300.222351), Some(31.638695))," | tee -a $out
|
|
112 |
echo " List(Some(330.555054), Some(39.478039)))" | tee -a $out
|
158
|
113 |
|
210
|
114 |
if (scala_assert "drumb.scala" "drumb_test3.scala")
|
158
|
115 |
then
|
169
|
116 |
echo " --> success" | tee -a $out
|
|
117 |
marks=$(( marks + 1 ))
|
158
|
118 |
else
|
169
|
119 |
echo " --> test failed" | tee -a $out
|
158
|
120 |
fi
|
|
121 |
fi
|
|
122 |
|
210
|
123 |
### get_deltas_test
|
|
124 |
|
|
125 |
#if [ $tsts -eq 0 ]
|
|
126 |
#then
|
|
127 |
# echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
|
|
128 |
# echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
|
|
129 |
# echo " " | tee -a $out
|
|
130 |
# echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out
|
|
131 |
# echo " List(Some(0.9277165354330709)), " | tee -a $out
|
|
132 |
# echo " List(Some(2.119679764725104)))" | tee -a $out
|
|
133 |
# echo " " | tee -a $out
|
|
134 |
# echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out
|
|
135 |
# echo " List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out
|
|
136 |
#
|
|
137 |
# if (scala_assert "drumb.scala" "drumb_test2.scala")
|
|
138 |
# then
|
|
139 |
# echo " --> success" | tee -a $out
|
|
140 |
# marks=$(( marks + 1 ))
|
|
141 |
# else
|
|
142 |
# echo " --> test failed" | tee -a $out
|
|
143 |
# fi
|
|
144 |
#fi
|
|
145 |
|
158
|
146 |
|
|
147 |
### yield_tests, investment_test
|
|
148 |
|
210
|
149 |
#if [ $tsts -eq 0 ]
|
|
150 |
#then
|
|
151 |
# echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
|
|
152 |
# echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
|
|
153 |
# echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out
|
|
154 |
# echo " val deltas1 = get_deltas(prices1)" | tee -a $out
|
|
155 |
# echo " val deltas2 = get_deltas(prices2)" | tee -a $out
|
|
156 |
# echo " val deltas3 = get_deltas(prices3)" | tee -a $out
|
|
157 |
# echo "" | tee -a $out
|
|
158 |
# echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out
|
|
159 |
# echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out
|
|
160 |
# echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out
|
|
161 |
# echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out
|
|
162 |
# echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out
|
|
163 |
# echo "" | tee -a $out
|
|
164 |
# echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out
|
|
165 |
# echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out
|
|
166 |
# echo "" | tee -a $out
|
|
167 |
# echo " inv1 >= 295 && inv1 <= 301" | tee -a $out
|
|
168 |
# echo " inv2 >= 194 && inv2 <= 198" | tee -a $out
|
|
169 |
#
|
|
170 |
# if (scala_assert "drumb.scala" "drumb_test3.scala")
|
|
171 |
# then
|
|
172 |
# echo " --> success" | tee -a $out
|
|
173 |
# marks=$(( marks + 1 ))
|
|
174 |
# else
|
|
175 |
# echo " --> test failed" | tee -a $out
|
|
176 |
# fi
|
|
177 |
#fi
|
158
|
178 |
|
169
|
179 |
|
|
180 |
|
|
181 |
## final marks
|
210
|
182 |
echo "Overall mark for CW 6, Part 1 + 2" | tee -a $out
|
169
|
183 |
echo "$marks" | tee -a $out
|