|
1 #!/bin/bash |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 |
|
7 out=${1:-output} |
|
8 |
|
9 echo "" > $out |
|
10 |
|
11 |
|
12 echo "Below is the feedback and provisional marks for your submission" >> $out |
|
13 echo "for assignment 8 Part 2. Please note all marks are provisional until" >> $out |
|
14 echo "ratified by the assessment board -- this is not an official" >> $out |
|
15 echo "results transcript." >> $out |
|
16 echo "" >> $out |
|
17 |
|
18 # marks for CW8 part 2 |
|
19 marks=$(( 0 )) |
|
20 |
|
21 # compilation tests |
|
22 |
|
23 function scala_compile { |
|
24 (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) |
|
25 } |
|
26 |
|
27 # functional tests |
|
28 |
|
29 function scala_assert { |
|
30 (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) |
|
31 } |
|
32 |
|
33 |
|
34 # purity test |
|
35 |
|
36 function scala_vars { |
|
37 (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
38 } |
|
39 |
|
40 |
|
41 |
|
42 # var, return, ListBuffer test |
|
43 # |
|
44 echo "bf.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out |
|
45 |
|
46 if (scala_vars bf.scala) |
|
47 then |
|
48 echo " --> test failed" | tee -a $out |
|
49 tsts0=$(( 1 )) |
|
50 else |
|
51 echo " --> success" | tee -a $out |
|
52 tsts0=$(( 0 )) |
|
53 fi |
|
54 |
|
55 |
|
56 # compilation test |
|
57 if [ $tsts0 -eq 0 ] |
|
58 then |
|
59 echo "bf.scala runs?" | tee -a $out |
|
60 |
|
61 if (scala_compile bf.scala) |
|
62 then |
|
63 echo " --> success" | tee -a $out |
|
64 tsts1=$(( 0 )) |
|
65 else |
|
66 echo " --> scala bf.scala did not run successfully" | tee -a $out |
|
67 tsts1=$(( 1 )) |
|
68 fi |
|
69 else |
|
70 tsts1=$(( 1 )) |
|
71 fi |
|
72 |
|
73 |
|
74 |
|
75 if [ $tsts1 -eq 0 ] |
|
76 then |
|
77 echo " sread(Map(), 2) == 0" | tee -a $out |
|
78 echo " sread(Map(2 -> 1), 2) == 1" | tee -a $out |
|
79 echo " write(Map(), 1, 2) == Map(1 -> 2)" | tee -a $out |
|
80 echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out |
|
81 |
|
82 if (scala_assert "bf.scala" "bf1a_test.scala") |
|
83 then |
|
84 echo " --> success" | tee -a $out |
|
85 marks=$(( marks + 1 )) |
|
86 else |
|
87 echo " --> test failed" | tee -a $out |
|
88 fi |
|
89 fi |
|
90 |
|
91 |
|
92 |
|
93 if [ $tsts1 -eq 0 ] |
|
94 then |
|
95 echo " jumpRight(\"[******]***\", 1, 0) == 8" | tee -a $out |
|
96 echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" | tee -a $out |
|
97 echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" | tee -a $out |
|
98 echo " jumpRight(\"[**[***]***\", 1, 0) == 11" | tee -a $out |
|
99 echo " jumpRight(\"[*[][]*]***\", 1, 0) == 8" | tee -a $out |
|
100 echo " jumpLeft(\"[******]***\", 6, 0) == 1" | tee -a $out |
|
101 echo " jumpLeft(\"[******]***\", 7, 0) == -1" | tee -a $out |
|
102 echo " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" | tee -a $out |
|
103 |
|
104 if (scala_assert "bf.scala" "bf1b_test.scala") |
|
105 then |
|
106 echo " --> success" | tee -a $out |
|
107 marks=$(( marks + 1 )) |
|
108 else |
|
109 echo " --> test failed" | tee -a $out |
|
110 fi |
|
111 fi |
|
112 |
|
113 |
|
114 |
|
115 if [ $tsts1 -eq 0 ] |
|
116 then |
|
117 echo " start(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out |
|
118 echo " start(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out |
|
119 echo " start(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out |
|
120 echo " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out |
|
121 echo " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out |
|
122 echo " start(hello, Map()) == " | tee -a $out |
|
123 echo " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out |
|
124 echo " start(\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\", Map()) == " | tee -a $out |
|
125 echo " Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out |
|
126 |
|
127 if (scala_assert "bf.scala" "bf1c_test.scala") |
|
128 then |
|
129 echo " --> success" | tee -a $out |
|
130 marks=$(( marks + 2 )) |
|
131 else |
|
132 echo " --> test failed" | tee -a $out |
|
133 fi |
|
134 fi |
|
135 |
|
136 |
|
137 ## final marks |
|
138 echo "Overall mark for CW 8, Part 2" | tee -a $out |
|
139 echo "$marks" | tee -a $out |
|
140 |