1 #!/bin/bash |
|
2 set -euo pipefail |
|
3 |
|
4 |
|
5 out=${1:-output} |
|
6 |
|
7 echo "" > $out |
|
8 |
|
9 echo "Below is the feedback and provisional marks for your submission" >> $out |
|
10 echo "for assignment 6 Advanced 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 |
|
13 echo "" >> $out |
|
14 |
|
15 # marks for CW6 part 3 |
|
16 marks=$(( 0 )) |
|
17 |
|
18 |
|
19 # compilation tests |
|
20 |
|
21 function scala_compile { |
|
22 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null) |
|
23 } |
|
24 |
|
25 # functional tests |
|
26 |
|
27 function scala_assert { |
|
28 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
29 } |
|
30 |
|
31 |
|
32 # purity test |
|
33 |
|
34 function scala_vars { |
|
35 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
36 } |
|
37 |
|
38 |
|
39 |
|
40 # var, .par return, ListBuffer test |
|
41 # |
|
42 echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
43 |
|
44 if (scala_vars drumb.scala) |
|
45 then |
|
46 echo " --> test failed" | tee -a $out |
|
47 tsts0=$(( 1 )) |
|
48 else |
|
49 echo " --> success" | tee -a $out |
|
50 tsts0=$(( 0 )) |
|
51 fi |
|
52 |
|
53 |
|
54 # compilation test |
|
55 if [ $tsts0 -eq 0 ] |
|
56 then |
|
57 echo "drumb.scala runs?" | tee -a $out |
|
58 |
|
59 if (scala_compile drumb.scala) |
|
60 then |
|
61 echo " --> success" | tee -a $out |
|
62 tsts=$(( 0 )) |
|
63 else |
|
64 echo " --> scala drumb.scala did not run successfully" | tee -a $out |
|
65 tsts=$(( 1 )) |
|
66 fi |
|
67 else |
|
68 tsts=$(( 1 )) |
|
69 fi |
|
70 |
|
71 |
|
72 ### get_delta test |
|
73 |
|
74 if [ $tsts -eq 0 ] |
|
75 then |
|
76 echo " get_delta(None, None) == None" | tee -a $out |
|
77 echo " get_delta(Some(50.0), None) == None" | tee -a $out |
|
78 echo " get_delta(None, Some(100.0)) == None" | tee -a $out |
|
79 echo " get_delta(Some(50.0), Some(100.0)) == Some(1.0)" | tee -a $out |
|
80 |
|
81 if (scala_assert "drumb.scala" "drumb_test4.scala") |
|
82 then |
|
83 echo " --> success" | tee -a $out |
|
84 marks=$(( marks + 1 )) |
|
85 else |
|
86 echo " --> test failed" | tee -a $out |
|
87 fi |
|
88 fi |
|
89 |
|
90 |
|
91 ### get_deltas_test |
|
92 |
|
93 if [ $tsts -eq 0 ] |
|
94 then |
|
95 echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out |
|
96 echo -e " List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " | tee -a $out |
|
97 echo -e " List(Some(0.10103412653643493), Some(0.24777709700099845)))" | tee -a $out |
|
98 echo -e "" | tee -a $out |
|
99 echo -e " get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out |
|
100 echo -e " List(List(None), List(None), " | tee -a $out |
|
101 echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " | tee -a $out |
|
102 |
|
103 if (scala_assert "drumb.scala" "drumb_test5.scala") |
|
104 then |
|
105 echo " --> success" | tee -a $out |
|
106 marks=$(( marks + 1 )) |
|
107 else |
|
108 echo " --> test failed" | tee -a $out |
|
109 fi |
|
110 fi |
|
111 |
|
112 |
|
113 ### yield_tests |
|
114 |
|
115 if [ $tsts -eq 0 ] |
|
116 then |
|
117 echo -e " val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out |
|
118 echo -e " yearly_yield(get_deltas(ds, 100, 0)) == 125" | tee -a $out |
|
119 echo -e " yearly_yield(get_deltas(ds, 100, 1)) == 117" | tee -a $out |
|
120 |
|
121 if (scala_assert "drumb.scala" "drumb_test6.scala") |
|
122 then |
|
123 echo " --> success" | tee -a $out |
|
124 marks=$(( marks + 1 )) |
|
125 else |
|
126 echo " --> test failed" | tee -a $out |
|
127 fi |
|
128 fi |
|
129 |
|
130 |
|
131 ### investment_test |
|
132 |
|
133 if [ $tsts -eq 0 ] |
|
134 then |
|
135 echo -e " All results need to be in the range of -/+ 1% of the given values." | tee -a $out |
|
136 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" | tee -a $out |
|
137 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " | tee -a $out |
|
138 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " | tee -a $out |
|
139 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " | tee -a $out |
|
140 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " | tee -a $out |
|
141 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" | tee -a $out |
|
142 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" | tee -a $out |
|
143 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" | tee -a $out |
|
144 echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 83061" | tee -a $out |
|
145 |
|
146 |
|
147 if (scala_assert "drumb.scala" "drumb_test7.scala") |
|
148 then |
|
149 echo " --> success" | tee -a $out |
|
150 marks=$(( marks + 1 )) |
|
151 else |
|
152 echo " --> test failed" | tee -a $out |
|
153 fi |
|
154 fi |
|
155 |
|
156 |
|
157 |
|
158 ## final marks |
|
159 echo "Overall mark for CW 6, Part 3" | tee -a $out |
|
160 echo "$marks" | tee -a $out |
|