82
|
1 |
#!/bin/bash
|
|
2 |
set -e
|
|
3 |
|
|
4 |
out=${1:-output}
|
|
5 |
|
|
6 |
echo "" > $out
|
|
7 |
|
|
8 |
echo "Below is the feedback and provisional mark for your submission" >> $out
|
|
9 |
echo "for assignment 6 (Part 3). Please note all marks are provisional until" >> $out
|
|
10 |
echo "ratified by the assessment board -- this is not an official" >> $out
|
|
11 |
echo "results transcript." >> $out
|
|
12 |
echo "" >> $out
|
|
13 |
|
|
14 |
|
|
15 |
#alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }
|
|
16 |
#alarm 20 foo arg1
|
|
17 |
|
|
18 |
# compilation tests
|
|
19 |
|
|
20 |
function scala_compile {
|
|
21 |
(scala "$1" 2> /dev/null 1> /dev/null)
|
|
22 |
}
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
# functional tests
|
|
27 |
|
|
28 |
function scala_assert {
|
|
29 |
(scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
|
|
30 |
}
|
|
31 |
|
|
32 |
|
|
33 |
# marks for CW1 part 3
|
|
34 |
marks=$(( 0 ))
|
|
35 |
|
|
36 |
|
|
37 |
# compilation test
|
|
38 |
echo "drumb.scala runs?" | tee -a $out
|
|
39 |
|
|
40 |
if (scala_compile drumb.scala)
|
|
41 |
then
|
|
42 |
echo " --> success" | tee -a $out
|
|
43 |
tsts=$(( 0 ))
|
|
44 |
else
|
|
45 |
echo " --> scala did not run drumb.scala" | tee -a $out
|
|
46 |
tsts=$(( 1 ))
|
|
47 |
fi
|
|
48 |
|
|
49 |
|
|
50 |
### get price tests
|
|
51 |
|
|
52 |
if [ $tsts -eq 0 ]
|
|
53 |
then
|
|
54 |
echo " get_prices(List(\"BIDU\"), 2004 to 2008) =" | tee -a $out
|
|
55 |
echo " List(List(None), List(None), List(Some(6.35))," | tee -a $out
|
|
56 |
echo " List(Some(12.241)), List(Some(38.188)))" | tee -a $out
|
|
57 |
|
|
58 |
if (scala_assert "drumb.scala" "../drumb_test1.scala")
|
|
59 |
then
|
|
60 |
echo " --> success" | tee -a $out
|
|
61 |
marks=$(( marks + 1 ))
|
|
62 |
else
|
|
63 |
echo " --> test failed" | tee -a $out
|
|
64 |
fi
|
|
65 |
fi
|
|
66 |
|
|
67 |
### get_deltas_test
|
|
68 |
|
|
69 |
if [ $tsts -eq 0 ]
|
|
70 |
then
|
|
71 |
echo " get_deltas(get_prices(List(\"IBM\", \"BIDU\"), 2004 to 2008)) = " | tee -a $out
|
|
72 |
echo " List(List(Some(0.07596697626574789), None), " | tee -a $out
|
|
73 |
echo " List(Some(-0.152620823795232), None)," | tee -a $out
|
|
74 |
echo " List(Some(0.20126676681483952), Some(0.9277165354330709))," | tee -a $out
|
|
75 |
echo " List(Some(0.09141762603007778), Some(2.119679764725104)))" | tee -a $out
|
|
76 |
|
|
77 |
if (scala_assert "drumb.scala" "../drumb_test2.scala")
|
|
78 |
then
|
|
79 |
echo " --> success" | tee -a $out
|
|
80 |
marks=$(( marks + 1 ))
|
|
81 |
else
|
|
82 |
echo " --> test failed" | tee -a $out
|
|
83 |
fi
|
|
84 |
fi
|
|
85 |
|
|
86 |
### yield_tests, investmetn_test
|
|
87 |
|
|
88 |
if [ $tsts -eq 0 ]
|
|
89 |
then
|
|
90 |
echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 0) - 107).abs <= 2 " | tee -a $out
|
|
91 |
echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 1) - 85).abs <= 2 " | tee -a $out
|
|
92 |
echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 2) - 156).abs <= 2 " | tee -a $out
|
|
93 |
echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 3) - 210).abs <= 2 " | tee -a $out
|
|
94 |
echo " investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100) - 298).abs <= 10" | tee -a $out
|
|
95 |
|
|
96 |
if (scala_assert "drumb.scala" "../drumb_test3.scala")
|
|
97 |
then
|
|
98 |
echo " --> success" | tee -a $out
|
|
99 |
marks=$(( marks + 1 ))
|
|
100 |
else
|
|
101 |
echo " --> test failed" | tee -a $out
|
|
102 |
fi
|
|
103 |
fi
|
|
104 |
|
|
105 |
## final marks
|
|
106 |
echo "Overall mark for CW 1, Part 3:" | tee -a $out
|
|
107 |
echo "$marks" | tee -a $out
|