248
|
1 |
#!/bin/bash
|
|
2 |
set -e
|
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
|
6 |
echo -e "" > $out
|
|
7 |
|
|
8 |
echo -e "Below is the feedback for your submission advanced part of drumb.scala:" >> $out
|
|
9 |
echo -e "" >> $out
|
|
10 |
|
|
11 |
# compilation tests
|
|
12 |
|
|
13 |
function scala_compile {
|
|
14 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out)
|
|
15 |
}
|
|
16 |
|
|
17 |
# functional tests
|
|
18 |
|
|
19 |
function scala_assert {
|
249
|
20 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
248
|
21 |
}
|
|
22 |
|
|
23 |
# purity test
|
|
24 |
|
|
25 |
function scala_vars {
|
|
26 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
|
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
# var, .par return, ListBuffer test
|
|
31 |
#
|
|
32 |
echo -e "drumb.scala does not contain vars, returns etc?" >> $out
|
|
33 |
|
|
34 |
if (scala_vars drumb.scala)
|
|
35 |
then
|
|
36 |
echo -e " --> fail (make triple-sure your program conforms to the required format)" >> $out
|
|
37 |
tsts0=$(( 0 ))
|
|
38 |
else
|
|
39 |
echo -e " --> success" >> $out
|
|
40 |
tsts0=$(( 0 ))
|
|
41 |
fi
|
|
42 |
|
|
43 |
|
|
44 |
# compilation test
|
|
45 |
if [ $tsts0 -eq 0 ]
|
|
46 |
then
|
|
47 |
echo -e "drumb.scala runs?" >> $out
|
|
48 |
|
|
49 |
if (scala_compile drumb.scala)
|
|
50 |
then
|
|
51 |
echo -e " --> success" >> $out
|
|
52 |
tsts=$(( 0 ))
|
|
53 |
else
|
|
54 |
echo -e " --> SCALA DID NOT RUN DRUMB.SCALA\n" >> $out
|
|
55 |
tsts=$(( 1 ))
|
|
56 |
fi
|
|
57 |
else
|
|
58 |
tsts=$(( 1 ))
|
|
59 |
fi
|
|
60 |
|
|
61 |
### get_deltas_test
|
|
62 |
|
|
63 |
if [ $tsts -eq 0 ]
|
|
64 |
then
|
|
65 |
echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
|
|
66 |
echo -e " List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " >> $out
|
|
67 |
echo -e " List(Some(0.10103412653643493), Some(0.24777709700099845)))" >> $out
|
|
68 |
echo -e "" >> $out
|
|
69 |
echo -e " get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " >> $out
|
|
70 |
echo -e " List(List(None), List(None), " >> $out
|
|
71 |
echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " >> $out
|
|
72 |
|
|
73 |
if (scala_assert "drumb.scala" "drumb_test5.scala")
|
|
74 |
then
|
|
75 |
echo -e " --> success" >> $out
|
|
76 |
else
|
|
77 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
78 |
fi
|
|
79 |
fi
|
|
80 |
|
|
81 |
|
|
82 |
### yield_tests
|
|
83 |
|
|
84 |
if [ $tsts -eq 0 ]
|
|
85 |
then
|
|
86 |
echo -e " val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" >> $out
|
|
87 |
echo -e " yearly_yield(get_deltas(de, 100, 0) == 125" >> $out
|
|
88 |
echo -e " yearly_yield(get_deltas(de, 100, 1) == 117" >> $out
|
|
89 |
|
|
90 |
if (scala_assert "drumb.scala" "drumb_test6.scala")
|
|
91 |
then
|
|
92 |
echo -e " --> success" >> $out
|
|
93 |
else
|
|
94 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
95 |
fi
|
|
96 |
fi
|
|
97 |
|
|
98 |
### investment_test
|
|
99 |
|
|
100 |
if [ $tsts -eq 0 ]
|
|
101 |
then
|
|
102 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" >> $out
|
|
103 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " >> $out
|
|
104 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " >> $out
|
|
105 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " >> $out
|
|
106 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " >> $out
|
|
107 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" >> $out
|
|
108 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" >> $out
|
|
109 |
echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" >> $out
|
|
110 |
|
|
111 |
if (scala_assert "drumb.scala" "drumb_test7.scala")
|
|
112 |
then
|
|
113 |
echo -e " --> success" >> $out
|
|
114 |
else
|
|
115 |
echo -e " --> \n ONE TEST FAILED\n" >> $out
|
|
116 |
fi
|
|
117 |
fi
|
|
118 |
|