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
|
84
|
9 |
echo "for CW 7. Please note all marks are provisional until" >> $out
|
82
|
10 |
echo "ratified by the assessment board -- this is not an official" >> $out
|
|
11 |
echo "results transcript." >> $out
|
|
12 |
echo "" >> $out
|
|
13 |
|
84
|
14 |
function scala_vars {
|
|
15 |
(egrep 'var|return|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
|
|
16 |
}
|
82
|
17 |
|
|
18 |
|
|
19 |
# compilation tests
|
|
20 |
|
|
21 |
function scala_compile {
|
85
|
22 |
(scala "$1" 2> /dev/null 1> /dev/null)
|
82
|
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 |
|
84
|
33 |
# marks for CW2
|
82
|
34 |
marks=$(( 0 ))
|
|
35 |
|
84
|
36 |
# var, comments test
|
|
37 |
echo "knight1.scala contains any vars, returns etc?" | tee -a $out
|
82
|
38 |
|
84
|
39 |
if (scala_vars knight1.scala)
|
82
|
40 |
then
|
84
|
41 |
echo " --> fail" | tee -a $out
|
85
|
42 |
tsts0=$(( 1 ))
|
82
|
43 |
else
|
84
|
44 |
echo " --> success" | tee -a $out
|
85
|
45 |
tsts0=$(( 0 ))
|
82
|
46 |
fi
|
|
47 |
|
|
48 |
|
84
|
49 |
# compilation test
|
85
|
50 |
if [ $tsts0 -eq 0 ]
|
|
51 |
then
|
|
52 |
echo "knight1.scala runs?" | tee -a $out
|
|
53 |
|
|
54 |
if (scala_compile knight1.scala.bak)
|
|
55 |
then
|
|
56 |
echo " --> success" | tee -a $out
|
|
57 |
tsts1=$(( 0 ))
|
|
58 |
else
|
|
59 |
echo " --> scala did not run knight1.scala" | tee -a $out
|
|
60 |
tsts1=$(( 1 ))
|
|
61 |
fi
|
|
62 |
fi
|
|
63 |
|
|
64 |
### knight1a test
|
82
|
65 |
|
85
|
66 |
if [ $tsts1 -eq 0 ]
|
|
67 |
then
|
|
68 |
echo " legal_moves(8, Nil, (2,2)) = (3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)" | tee -a $out
|
|
69 |
echo " legal_moves(8, Nil, (7,7)) = (6,5), (5,6)" | tee -a $out
|
|
70 |
echo " legal_moves(8, (4,1), (1,0), (2,2)) = (3,4), (4,3), (3,0), (0,1), (0,3), (1,4)" | tee -a $out
|
|
71 |
echo " legal_moves(8, (6,6), (7,7)) = (6,5), (5,6)" | tee -a $out
|
|
72 |
echo " legal_moves(1, Nil, (0,0)) = Nil" | tee -a $out
|
|
73 |
echo " legal_moves(2, Nil, (0,0)) = Nil" | tee -a $out
|
|
74 |
echo " legal_moves(3, Nil, (0,0)) = (1,2), (2,1)" | tee -a $out
|
|
75 |
|
|
76 |
if (scala_assert "knight1.scala" "../../../marking/knight1_test.scala")
|
|
77 |
then
|
|
78 |
echo " --> success" | tee -a $out
|
|
79 |
marks=$(( marks + 1 ))
|
|
80 |
else
|
|
81 |
echo " --> test failed" | tee -a $out
|
|
82 |
fi
|
|
83 |
fi
|
82
|
84 |
|
84
|
85 |
### knight2 test
|
82
|
86 |
|
84
|
87 |
#if [ $tsts -eq 0 ]
|
|
88 |
#then
|
85
|
89 |
# echo " legal_moves(8, Nil, (2,2) = (3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)" | tee -a $out
|
84
|
90 |
# echo " List(List(Some(0.07596697626574789), None), " | tee -a $out
|
|
91 |
# echo " List(Some(-0.152620823795232), None)," | tee -a $out
|
|
92 |
# echo " List(Some(0.20126676681483952), Some(0.9277165354330709))," | tee -a $out
|
|
93 |
# echo " List(Some(0.09141762603007778), Some(2.119679764725104)))" | tee -a $out
|
|
94 |
#
|
|
95 |
# if (scala_assert "drumb.scala" "../drumb_test2.scala")
|
|
96 |
# then
|
|
97 |
# echo " --> success" | tee -a $out
|
|
98 |
# marks=$(( marks + 1 ))
|
|
99 |
# else
|
|
100 |
# echo " --> test failed" | tee -a $out
|
|
101 |
# fi
|
|
102 |
#fi
|
82
|
103 |
|
84
|
104 |
### knight3 test
|
82
|
105 |
|
84
|
106 |
#if [ $tsts -eq 0 ]
|
|
107 |
#then
|
|
108 |
# echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 0) - 107).abs <= 2 " | tee -a $out
|
|
109 |
# echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 1) - 85).abs <= 2 " | tee -a $out
|
|
110 |
# echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 2) - 156).abs <= 2 " | tee -a $out
|
|
111 |
# echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 3) - 210).abs <= 2 " | tee -a $out
|
|
112 |
# echo " investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100) - 298).abs <= 10" | tee -a $out
|
|
113 |
#
|
|
114 |
# if (scala_assert "drumb.scala" "../drumb_test3.scala")
|
|
115 |
# then
|
|
116 |
# echo " --> success" | tee -a $out
|
|
117 |
# marks=$(( marks + 1 ))
|
|
118 |
# else
|
|
119 |
# echo " --> test failed" | tee -a $out
|
|
120 |
# fi
|
|
121 |
#fi
|
82
|
122 |
|
|
123 |
## final marks
|
84
|
124 |
echo "Overall mark for CW 2" | tee -a $out
|
82
|
125 |
echo "$marks" | tee -a $out
|