Search in sources :

Example 61 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodes.

@Test
public void shouldHandleNeighbouringNodes() {
    // (a) - (b)
    graph.makeEdgeChain("a,b");
    Node a = graph.getNode("a");
    Node b = graph.getNode("b");
    ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
    Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 62 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesMultiplePaths.

@Test
public void shouldHandleNeighbouringNodesMultiplePaths() {
    // (a) = (b)
    //  |
    // (c)
    graph.makeEdgeChain("a,b");
    graph.makeEdgeChain("a,b");
    graph.makeEdgeChain("a,c");
    Node a = graph.getNode("a");
    Node b = graph.getNode("b");
    ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
    Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 63 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class Neo4jAlgoTestCase method assertPathsWithPaths.

public void assertPathsWithPaths(Iterable<? extends Path> actualPaths, Path... expectedPaths) {
    List<String> pathDefs = new ArrayList<>();
    for (Path path : expectedPaths) {
        pathDefs.add(getPathDef(path));
    }
    assertPaths(actualPaths, pathDefs);
}
Also used : Path(org.neo4j.graphdb.Path) ArrayList(java.util.ArrayList)

Example 64 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class PathImplTest method pathsWithTheSameContentsShouldBeEqual.

@Test
public void pathsWithTheSameContentsShouldBeEqual() throws Exception {
    Node node = createNode(1337L);
    Relationship relationship = createRelationship(1337L, 7331L);
    // Given
    Path firstPath = new PathImpl.Builder(node).push(relationship).build();
    Path secondPath = new PathImpl.Builder(node).push(relationship).build();
    // When Then
    assertEquals(firstPath, secondPath);
    assertEquals(secondPath, firstPath);
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 65 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class PathImplTest method testPathReverseNodes.

@Test
public void testPathReverseNodes() {
    when(relationshipActions.newNodeProxy(Mockito.anyLong())).thenAnswer(new NodeProxyAnswer());
    Path path = new PathImpl.Builder(createNodeProxy(1)).push(createRelationshipProxy(1, 2)).push(createRelationshipProxy(2, 3)).build(new PathImpl.Builder(createNodeProxy(3)));
    Iterable<Node> nodes = path.reverseNodes();
    List<Node> nodeList = Iterables.asList(nodes);
    Assert.assertEquals(3, nodeList.size());
    Assert.assertEquals(3, nodeList.get(0).getId());
    Assert.assertEquals(2, nodeList.get(1).getId());
    Assert.assertEquals(1, nodeList.get(2).getId());
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Aggregations

Path (org.neo4j.graphdb.Path)112 Test (org.junit.Test)66 Node (org.neo4j.graphdb.Node)49 Relationship (org.neo4j.graphdb.Relationship)30 WeightedPath (org.neo4j.graphalgo.WeightedPath)20 Transaction (org.neo4j.graphdb.Transaction)18 ArrayList (java.util.ArrayList)15 Traverser (org.neo4j.graphdb.traversal.Traverser)15 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)12 HashSet (java.util.HashSet)9 Evaluator (org.neo4j.graphdb.traversal.Evaluator)9 LinkedList (java.util.LinkedList)6 RelationshipType (org.neo4j.graphdb.RelationshipType)6 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)6 Predicate (org.neo4j.helpers.Predicate)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 PathFinder (org.neo4j.graphalgo.PathFinder)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 ExactDepthPathFinder (org.neo4j.graphalgo.impl.path.ExactDepthPathFinder)3