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