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