use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.
the class TreeGraphTest method nodesIteratorReturnAllNodes.
@Test
public void nodesIteratorReturnAllNodes() throws Exception {
try (Transaction transaction = beginTx()) {
Traverser traverser = getGraphDb().traversalDescription().traverse(node("1"));
int count = 0;
for (Node node : traverser.nodes()) {
assertNotNull("returned nodes should not be null. node #" + count, node);
count++;
}
assertEquals(13, count);
}
}
use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.
the class TreeGraphTest method relationshipsIteratorReturnAllNodes.
@Test
public void relationshipsIteratorReturnAllNodes() throws Exception {
try (Transaction transaction = beginTx()) {
Traverser traverser = getGraphDb().traversalDescription().traverse(node("1"));
int count = 0;
for (Relationship relationship : traverser.relationships()) {
assertNotNull("returned relationships should not be. relationship #" + count, relationship);
count++;
}
assertEquals(12, count);
}
}
use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.
the class TreeGraphTest method testBreadthFirst.
@Test
public void testBreadthFirst() throws Exception {
Traverser traverser = getGraphDb().traversalDescription().breadthFirst().traverse(node("1"));
Stack<Set<String>> levels = new Stack<>();
levels.push(new HashSet<>(asList("5", "6", "7", "8", "9", "A", "B", "C", "D")));
levels.push(new HashSet<>(asList("2", "3", "4")));
levels.push(new HashSet<>(asList("1")));
try (Transaction tx = beginTx()) {
assertLevels(traverser, levels);
tx.success();
}
}
use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.
the class TreeGraphTest method testPostorderDepthFirstReturnsDeeperNodesFirst.
@Test
public void testPostorderDepthFirstReturnsDeeperNodesFirst() {
Traverser traverser = getGraphDb().traversalDescription().order(POSTORDER_DEPTH_FIRST).traverse(node("1"));
int i = 0;
List<String> encounteredNodes = new ArrayList<>();
try (Transaction tx = beginTx()) {
for (Path pos : traverser) {
encounteredNodes.add((String) pos.endNode().getProperty("name"));
assertEquals(expectedDepth(12 - i++), pos.length());
}
tx.success();
}
assertEquals(13, i);
assertTrue(encounteredNodes.indexOf("5") < encounteredNodes.indexOf("2"));
assertTrue(encounteredNodes.indexOf("6") < encounteredNodes.indexOf("2"));
assertTrue(encounteredNodes.indexOf("7") < encounteredNodes.indexOf("2"));
assertTrue(encounteredNodes.indexOf("8") < encounteredNodes.indexOf("3"));
assertTrue(encounteredNodes.indexOf("9") < encounteredNodes.indexOf("3"));
assertTrue(encounteredNodes.indexOf("A") < encounteredNodes.indexOf("3"));
assertTrue(encounteredNodes.indexOf("B") < encounteredNodes.indexOf("4"));
assertTrue(encounteredNodes.indexOf("C") < encounteredNodes.indexOf("4"));
assertTrue(encounteredNodes.indexOf("D") < encounteredNodes.indexOf("4"));
assertTrue(encounteredNodes.indexOf("2") < encounteredNodes.indexOf("1"));
assertTrue(encounteredNodes.indexOf("3") < encounteredNodes.indexOf("1"));
assertTrue(encounteredNodes.indexOf("4") < encounteredNodes.indexOf("1"));
}
use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.
the class TreeGraphTest method testDepthFirstTraversalReturnsNodesOnCorrectDepths.
@Test
public void testDepthFirstTraversalReturnsNodesOnCorrectDepths() throws Exception {
try (Transaction transaction = beginTx()) {
Traverser traverser = getGraphDb().traversalDescription().depthFirst().traverse(node("1"));
int i = 0;
for (Path pos : traverser) {
assertEquals(expectedDepth(i++), pos.length());
}
assertEquals(13, i);
}
}
Aggregations