130
|
1 |
#!/bin/bash
|
|
2 |
set -e
|
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
|
6 |
echo "" > $out
|
|
7 |
|
|
8 |
echo "Below is the feedback for your submission for drumb.scala" >> $out
|
|
9 |
echo "" >> $out
|
|
10 |
|
|
11 |
# compilation tests
|
|
12 |
|
|
13 |
function scala_compile {
|
199
|
14 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
130
|
15 |
}
|
|
16 |
|
|
17 |
# functional tests
|
|
18 |
|
|
19 |
function scala_assert {
|
199
|
20 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
|
130
|
21 |
}
|
|
22 |
|
|
23 |
# purity test
|
|
24 |
|
|
25 |
function scala_vars {
|
|
26 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
|
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
# var, .par return, ListBuffer test
|
|
31 |
#
|
|
32 |
echo "drumb.scala does not contain vars, returns etc?" >> $out
|
|
33 |
|
|
34 |
if (scala_vars drumb.scala)
|
|
35 |
then
|
206
|
36 |
echo " --> fail (make triple-sure your program conforms to the required format)" >> $out
|
199
|
37 |
tsts0=$(( 0 ))
|
130
|
38 |
else
|
|
39 |
echo " --> success" >> $out
|
|
40 |
tsts0=$(( 0 ))
|
|
41 |
fi
|
|
42 |
|
|
43 |
|
|
44 |
# compilation test
|
|
45 |
if [ $tsts0 -eq 0 ]
|
|
46 |
then
|
|
47 |
echo "drumb.scala runs?" >> $out
|
|
48 |
|
169
|
49 |
if (scala_compile drumb.scala)
|
130
|
50 |
then
|
|
51 |
echo " --> success" >> $out
|
|
52 |
tsts=$(( 0 ))
|
|
53 |
else
|
169
|
54 |
echo " --> scala did not run drumb.scala" >> $out
|
130
|
55 |
tsts=$(( 1 ))
|
|
56 |
fi
|
|
57 |
else
|
|
58 |
tsts=$(( 1 ))
|
|
59 |
fi
|
|
60 |
|
199
|
61 |
### get january data
|
130
|
62 |
|
199
|
63 |
if [ $tsts -eq 0 ]
|
|
64 |
then
|
|
65 |
echo " get_january_data(\"GOOG\", 1980) == List()" >> $out
|
|
66 |
echo " get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" >> $out
|
|
67 |
|
|
68 |
if (scala_assert "drumb.scala" "drumb_test1.scala")
|
|
69 |
then
|
|
70 |
echo " --> success" >> $out
|
|
71 |
else
|
|
72 |
echo " --> test failed" >> $out
|
|
73 |
fi
|
|
74 |
fi
|
|
75 |
|
|
76 |
### get first price
|
|
77 |
|
|
78 |
if [ $tsts -eq 0 ]
|
|
79 |
then
|
|
80 |
echo " get_first_price(\"GOOG\", 1980) == None" >> $out
|
|
81 |
echo " get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out
|
|
82 |
|
|
83 |
if (scala_assert "drumb.scala" "drumb_test2.scala")
|
|
84 |
then
|
|
85 |
echo " --> success" >> $out
|
|
86 |
else
|
|
87 |
echo " --> test failed" >> $out
|
|
88 |
fi
|
|
89 |
fi
|
130
|
90 |
|
|
91 |
### get prices tests
|
|
92 |
|
|
93 |
if [ $tsts -eq 0 ]
|
|
94 |
then
|
|
95 |
echo " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
|
199
|
96 |
echo " List(List(Some(311.349976), Some(20.544939))," >> $out
|
|
97 |
echo " List(Some(300.222351), Some(31.638695))," >> $out
|
|
98 |
echo " List(Some(330.555054), Some(39.478039)))" >> $out
|
130
|
99 |
|
199
|
100 |
if (scala_assert "drumb.scala" "drumb_test3.scala")
|
130
|
101 |
then
|
|
102 |
echo " --> success" >> $out
|
|
103 |
else
|
|
104 |
echo " --> test failed" >> $out
|
|
105 |
fi
|
|
106 |
fi
|
|
107 |
|
|
108 |
### get_deltas_test
|
|
109 |
|
199
|
110 |
#if [ $tsts -eq 0 ]
|
|
111 |
#then
|
|
112 |
# echo " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
|
|
113 |
# echo " List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
|
|
114 |
# echo " List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
|
|
115 |
#
|
|
116 |
# if (scala_assert "drumb.scala" "drumb_test2.scala")
|
|
117 |
# then
|
|
118 |
# echo " --> success" >> $out
|
|
119 |
# else
|
|
120 |
# echo " --> test failed" >> $out
|
|
121 |
# fi
|
|
122 |
#fi
|
130
|
123 |
|
|
124 |
|
|
125 |
### yield_tests, investment_test
|
|
126 |
|
199
|
127 |
#if [ $tsts -eq 0 ]
|
|
128 |
#then
|
|
129 |
# echo " yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
|
|
130 |
# echo "" >> $out
|
|
131 |
# echo " investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
|
|
132 |
# echo " investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
|
|
133 |
#
|
|
134 |
# if (scala_assert "drumb.scala" "drumb_test3.scala")
|
|
135 |
# then
|
|
136 |
# echo " --> success" >> $out
|
|
137 |
# else
|
|
138 |
# echo " --> test failed" >> $out
|
|
139 |
# fi
|
|
140 |
#fi
|
130
|
141 |
|