1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.qedeq.kernel.bo.control; |
19 |
|
|
20 |
|
import java.io.ByteArrayOutputStream; |
21 |
|
import java.io.IOException; |
22 |
|
import java.util.Stack; |
23 |
|
|
24 |
|
import org.qedeq.base.io.TextOutput; |
25 |
|
import org.qedeq.base.test.QedeqTestCase; |
26 |
|
import org.qedeq.base.trace.Trace; |
27 |
|
import org.qedeq.kernel.base.list.Atom; |
28 |
|
import org.qedeq.kernel.base.list.Element; |
29 |
|
import org.qedeq.kernel.base.list.ElementList; |
30 |
|
import org.qedeq.kernel.bo.service.DefaultModuleAddress; |
31 |
|
import org.qedeq.kernel.common.ModuleAddress; |
32 |
|
import org.qedeq.kernel.dto.list.DefaultAtom; |
33 |
|
import org.qedeq.kernel.dto.list.DefaultElementList; |
34 |
|
import org.qedeq.kernel.visitor.AbstractModuleVisitor; |
35 |
|
import org.qedeq.kernel.visitor.QedeqNotNullTraverser; |
36 |
|
import org.qedeq.kernel.visitor.QedeqVisitor; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@author |
46 |
|
|
|
|
| 93,6% |
Uncovered Elements: 3 (47) |
Complexity: 16 |
Complexity Density: 0,52 |
|
47 |
|
public class QedeqNotNullTraverserTest extends QedeqTestCase { |
48 |
|
|
49 |
|
|
50 |
|
private static final Class CLASS = QedeqNotNullTraverserTest.class; |
51 |
|
|
52 |
|
private final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
53 |
|
|
54 |
|
private final TextOutput text = new TextOutput("local", out); |
55 |
|
|
56 |
|
private final Stack stack = new Stack(); |
57 |
|
|
58 |
|
private static ModuleAddress address; |
59 |
|
|
|
|
| 66,7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
|
60 |
1
|
static {... |
61 |
1
|
try { |
62 |
1
|
address = new DefaultModuleAddress("http://memory.org/sample.xml"); |
63 |
|
} catch (IOException e) { |
64 |
0
|
e.printStackTrace(); |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
|
private final QedeqVisitor visitor = new AbstractModuleVisitor() { |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
70 |
19
|
public void visitEnter(Atom atom) {... |
71 |
19
|
handleComma(); |
72 |
19
|
text.print("\""); |
73 |
19
|
text.print(atom.getString()); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
19
|
public void visitLeave(Atom atom) {... |
77 |
19
|
text.print("\""); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
80 |
21
|
public void visitEnter(ElementList list) {... |
81 |
21
|
handleComma(); |
82 |
21
|
text.print(list.getOperator() + "("); |
83 |
21
|
stack.push(Boolean.FALSE); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
86 |
21
|
public void visitLeave(ElementList list) {... |
87 |
21
|
text.print(")"); |
88 |
21
|
stack.pop(); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0,8 |
|
91 |
40
|
private void handleComma() {... |
92 |
40
|
if (!stack.isEmpty() && ((Boolean) stack.peek()).booleanValue()) { |
93 |
17
|
text.print(", "); |
94 |
|
} else { |
95 |
23
|
if (!stack.isEmpty()) { |
96 |
21
|
stack.pop(); |
97 |
21
|
stack.push(Boolean.TRUE); |
98 |
|
} |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
|
}; |
103 |
|
|
104 |
|
private final QedeqNotNullTraverser trans = new QedeqNotNullTraverser(address, |
105 |
|
visitor); |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0
|
public QedeqNotNullTraverserTest() {... |
112 |
0
|
super(); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@param |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
2
|
public QedeqNotNullTraverserTest(String name) {... |
121 |
2
|
super(name); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1
PASS
|
|
127 |
1
|
public void testVisit() throws Exception {... |
128 |
1
|
Element el = new DefaultElementList("myOperator", new Element[] { |
129 |
|
new DefaultAtom("Hello"), |
130 |
|
new DefaultAtom("Again"), |
131 |
|
new DefaultElementList("again", new Element[] { |
132 |
|
new DefaultAtom("one"), |
133 |
|
new DefaultAtom("two"), |
134 |
|
new DefaultAtom("three") |
135 |
|
}) |
136 |
|
}); |
137 |
|
|
138 |
1
|
trans.accept(el); |
139 |
1
|
Trace.trace(CLASS, this, "testVisit", out.toString("ISO-8859-1")); |
140 |
1
|
assertEquals("myOperator(\"Hello\", \"Again\", again(\"one\", \"two\", \"three\"))", |
141 |
|
out.toString("ISO-8859-1")); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
147 |
1
|
public void testGeneration() throws Exception {... |
148 |
1
|
Element el = new DefaultElementList("EQUI", new Element[] { |
149 |
|
new DefaultElementList("PREDCON", new Element[] { |
150 |
|
new DefaultAtom("equal"), |
151 |
|
new DefaultElementList("VAR", new Element[] { |
152 |
|
new DefaultAtom("y"), |
153 |
|
}), |
154 |
|
new DefaultElementList("CLASS", new Element[] { |
155 |
|
new DefaultElementList("VAR", new Element[] { |
156 |
|
new DefaultAtom("x"), |
157 |
|
}), |
158 |
|
new DefaultElementList("PREDVAR", new Element[] { |
159 |
|
new DefaultAtom("\\phi"), |
160 |
|
new DefaultElementList("VAR", new Element[] { |
161 |
|
new DefaultAtom("x"), |
162 |
|
}) |
163 |
|
}) |
164 |
|
}) |
165 |
|
}), |
166 |
|
new DefaultElementList("FORALL", new Element[] { |
167 |
|
new DefaultElementList("VAR", new Element[] { |
168 |
|
new DefaultAtom("z"), |
169 |
|
}), |
170 |
|
new DefaultElementList("EQUI", new Element[] { |
171 |
|
new DefaultElementList("PREDCON", new Element[] { |
172 |
|
new DefaultAtom("in"), |
173 |
|
new DefaultElementList("VAR", new Element[] { |
174 |
|
new DefaultAtom("z"), |
175 |
|
}), |
176 |
|
new DefaultElementList("VAR", new Element[] { |
177 |
|
new DefaultAtom("y"), |
178 |
|
}) |
179 |
|
}), |
180 |
|
new DefaultElementList("PREDCON", new Element[] { |
181 |
|
new DefaultAtom("in"), |
182 |
|
new DefaultElementList("VAR", new Element[] { |
183 |
|
new DefaultAtom("z"), |
184 |
|
}), |
185 |
|
new DefaultElementList("CLASS", new Element[] { |
186 |
|
new DefaultElementList("VAR", new Element[] { |
187 |
|
new DefaultAtom("x"), |
188 |
|
}), |
189 |
|
new DefaultElementList("PREDVAR", new Element[] { |
190 |
|
new DefaultAtom("\\phi"), |
191 |
|
new DefaultElementList("VAR", new Element[] { |
192 |
|
new DefaultAtom("x"), |
193 |
|
}) |
194 |
|
}) |
195 |
|
}) |
196 |
|
}) |
197 |
|
}) |
198 |
|
}) |
199 |
|
}); |
200 |
1
|
trans.accept(el); |
201 |
1
|
Trace.trace(CLASS, this, "testGeneration", out.toString("ISO-8859-1")); |
202 |
1
|
assertEquals("EQUI(PREDCON(\"equal\", VAR(\"y\"), CLASS(VAR(\"x\"), PREDVAR(\"\\phi\"," |
203 |
|
+ " VAR(\"x\")))), FORALL(VAR(\"z\"), EQUI(PREDCON(\"in\", VAR(\"z\"), VAR(\"y\"))," |
204 |
|
+ " PREDCON(\"in\", VAR(\"z\"), CLASS(VAR(\"x\"), PREDVAR(\"\\phi\", VAR(\"x\")))))))", |
205 |
|
out.toString("ISO-8859-1")); |
206 |
1
|
Trace.trace(CLASS, this, "testGeneration", el.toString()); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
209 |
2
|
protected void setUp() throws Exception {... |
210 |
2
|
super.setUp(); |
211 |
2
|
out.reset(); |
212 |
|
} |
213 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
214 |
2
|
protected void tearDown() throws Exception {... |
215 |
2
|
super.tearDown(); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
} |