use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleSimpleChainOddDepth.
@Test
void shouldHandleSimpleChainOddDepth() {
// (a) - (b) - (c) - (d)
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d");
Node a = graph.getNode(transaction, "a");
Node d = graph.getNode(transaction, "d");
var context = new BasicEvaluationContext(transaction, graphDb);
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, d), "a,b,c,d");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, d), "a,b,c,d");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method testSingle.
@Test
void testSingle() {
try (Transaction transaction = graphDb.beginTx()) {
final Set<String> possiblePaths = new HashSet<>();
possiblePaths.add("SOURCE,z,9,0,TARGET");
possiblePaths.add("SOURCE,SUPER,r,SPIDER,TARGET");
createGraph(transaction);
var context = new BasicEvaluationContext(transaction, graphDb);
PathFinder<Path> finder = newFinder(context);
Path path = finder.findSinglePath(graph.getNode(transaction, "SOURCE"), graph.getNode(transaction, "TARGET"));
assertNotNull(path);
assertThat(getPathDef(path)).isIn(possiblePaths);
assertTrue(possiblePaths.contains(getPathDef(path)));
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesWhenNotAlone.
@Test
void shouldHandleNeighbouringNodesWhenNotAlone() {
// (c)
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdge(transaction, "a", "b");
graph.makeEdge(transaction, "a", "c");
Node a = graph.getNode(transaction, "a");
Node b = graph.getNode(transaction, "b");
var context = new BasicEvaluationContext(transaction, graphDb);
ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesMultiplePaths.
@Test
void shouldHandleNeighbouringNodesMultiplePaths() {
// (c)
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b");
graph.makeEdgeChain(transaction, "a,b");
graph.makeEdgeChain(transaction, "a,c");
Node a = graph.getNode(transaction, "a");
Node b = graph.getNode(transaction, "b");
var context = new BasicEvaluationContext(transaction, graphDb);
ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleNondirectedGraph.
@Test
void shouldHandleNondirectedGraph() {
// (d) - (e) ------------ (f) length 4
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,g");
graph.makeEdgeChain(transaction, "a,d,e,f,g");
graph.makeEdgeChain(transaction, "a,h,i,j,k,g");
Node a = graph.getNode(transaction, "a");
Node g = graph.getNode(transaction, "g");
var context = new BasicEvaluationContext(transaction, graphDb);
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,b,c,g");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 4, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,d,e,f,g");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 5, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,h,i,j,k,g");
transaction.commit();
}
}
Aggregations