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 echo -e "Below is the feedback and provisional marks for your submission" >> $out |
|
12 echo -e "for the Preliminary Part of Assignemnt 7. Please note all marks are provisional until" >> $out |
|
13 echo -e "ratified by the assessment board -- this is not an official" >> $out |
|
14 echo -e "results transcript." >> $out |
|
15 echo -e "" >> $out |
|
16 |
|
17 echo -e "Below is the feedback for your submission docdiff.scala" >> $out |
|
18 echo -e "" >> $out |
|
19 |
|
20 # marks for CW7 parts 1 + 2 |
|
21 marks=$(( 0 )) |
|
22 |
|
23 |
|
24 # compilation tests |
|
25 |
|
26 function scala_compile { |
|
27 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) |
|
28 } |
|
29 |
|
30 # functional tests |
|
31 |
|
32 function scala_assert { |
|
33 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null) |
|
34 } |
|
35 |
|
36 # purity test |
|
37 |
|
38 function scala_vars { |
|
39 (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) |
|
40 } |
|
41 |
|
42 |
|
43 # var, .par return, ListBuffer test |
|
44 # |
|
45 echo -e "docdiff.scala does not contain vars, returns etc?" | tee -a $out |
|
46 |
|
47 if (scala_vars docdiff.scala) |
|
48 then |
|
49 echo -e " --> FAIL (make triple-sure your program conforms to the required format)\n" | tee -a $out |
|
50 tsts0=$(( 1 )) |
|
51 else |
|
52 echo -e " --> success" | tee -a $out |
|
53 tsts0=$(( 0 )) |
|
54 fi |
|
55 |
|
56 ### compilation test |
|
57 |
|
58 |
|
59 if [ $tsts0 -eq 0 ] |
|
60 then |
|
61 echo -e "docdiff.scala runs?" | tee -a $out |
|
62 |
|
63 if (scala_compile docdiff.scala) |
|
64 then |
|
65 echo -e " --> success" | tee -a $out |
|
66 tsts=$(( 0 )) |
|
67 else |
|
68 echo -e " --> scala did not run docdiff.scala" | tee -a $out |
|
69 tsts=$(( 1 )) |
|
70 fi |
|
71 else |
|
72 tsts=$(( 1 )) |
|
73 fi |
|
74 |
|
75 ### docdiff clean tests |
|
76 |
|
77 if [ $tsts -eq 0 ] |
|
78 then |
|
79 echo -e "docdiff.scala tests:" | tee -a $out |
|
80 echo -e " clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" | tee -a $out |
|
81 echo -e " clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" | tee -a $out |
|
82 |
|
83 if (scala_assert "docdiff.scala" "docdiff_test1.scala") |
|
84 then |
|
85 echo -e " --> success" | tee -a $out |
|
86 marks=$(( marks + 1 )) |
|
87 else |
|
88 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
89 fi |
|
90 fi |
|
91 |
|
92 ### docdiff occurrences tests |
|
93 |
|
94 if [ $tsts -eq 0 ] |
|
95 then |
|
96 echo -e " occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " | tee -a $out |
|
97 echo -e " Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" | tee -a $out |
|
98 echo -e " " | tee -a $out |
|
99 echo -e " occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " | tee -a $out |
|
100 echo -e " Map(\"d\" -> 3, \"b\" -> 2)" | tee -a $out |
|
101 echo -e " " | tee -a $out |
|
102 echo -e " occurrences(Nil) == Map() " | tee -a $out |
|
103 echo -e " " | tee -a $out |
|
104 echo -e " occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" | tee -a $out |
|
105 |
|
106 if (scala_assert "docdiff.scala" "docdiff_test2.scala") |
|
107 then |
|
108 echo -e " --> success" | tee -a $out |
|
109 marks=$(( marks + 1 )) |
|
110 else |
|
111 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
112 fi |
|
113 fi |
|
114 |
|
115 ### docdiff prod tests |
|
116 |
|
117 if [ $tsts -eq 0 ] |
|
118 then |
|
119 echo -e " val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" | tee -a $out |
|
120 echo -e " val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" | tee -a $out |
|
121 echo -e " " | tee -a $out |
|
122 echo -e " prod(l1, l2) == 7 " | tee -a $out |
|
123 echo -e " prod(l1, l1) == 7 " | tee -a $out |
|
124 echo -e " prod(l2, l2) == 13 " | tee -a $out |
|
125 echo -e " " | tee -a $out |
|
126 echo -e " val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" | tee -a $out |
|
127 echo -e " prod(l1, l3) == 0 " | tee -a $out |
|
128 |
|
129 if (scala_assert "docdiff.scala" "docdiff_test3.scala") |
|
130 then |
|
131 echo -e " --> success" | tee -a $out |
|
132 marks=$(( marks + 1 )) |
|
133 else |
|
134 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
135 fi |
|
136 fi |
|
137 |
|
138 ### docdiff overlap tests |
|
139 |
|
140 if [ $tsts -eq 0 ] |
|
141 then |
|
142 echo -e " val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" | tee -a $out |
|
143 echo -e " val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" | tee -a $out |
|
144 echo -e " " | tee -a $out |
|
145 echo -e " overlap(l1, l2) == 0.5384615384615384 " | tee -a $out |
|
146 echo -e " overlap(l1, l1) == 1.0 " | tee -a $out |
|
147 echo -e " overlap(l2, l2) == 1.0 " | tee -a $out |
|
148 |
|
149 if (scala_assert "docdiff.scala" "docdiff_test4.scala") |
|
150 then |
|
151 echo -e " --> success" | tee -a $out |
|
152 marks=$(( marks + 1 )) |
|
153 else |
|
154 echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out |
|
155 fi |
|
156 fi |
|
157 |
|
158 |
|
159 ## final marks |
|
160 echo -e "Overall mark for the Preliminary Part" | tee -a $out |
|
161 echo -e " $marks" | tee -a $out |
|
162 |
|