Search in sources :

Example 41 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class TreeGraphTest method testPostorderBreadthFirstReturnsDeeperNodesFirst.

@Test
public void testPostorderBreadthFirstReturnsDeeperNodesFirst() {
    Traverser traverser = getGraphDb().traversalDescription().order(POSTORDER_BREADTH_FIRST).traverse(node("1"));
    Stack<Set<String>> levels = new Stack<>();
    levels.push(new HashSet<>(asList("1")));
    levels.push(new HashSet<>(asList("2", "3", "4")));
    levels.push(new HashSet<>(asList("5", "6", "7", "8", "9", "A", "B", "C", "D")));
    try (Transaction tx = beginTx()) {
        assertLevels(traverser, levels);
        tx.success();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Transaction(org.neo4j.graphdb.Transaction) Traverser(org.neo4j.graphdb.traversal.Traverser) Stack(java.util.Stack) Test(org.junit.Test)

Example 42 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testAllUniqueNodePathsAreReturned.

private void testAllUniqueNodePathsAreReturned(TraversalDescription description) throws Exception {
    Traverser traverser = description.uniqueness(Uniqueness.NODE_PATH).traverse(node("1"));
    expectPaths(traverser, NODE_UNIQUE_PATHS);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 43 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testAllRelationshipsAreReturnedOnce.

private void testAllRelationshipsAreReturnedOnce(TraversalDescription description) throws Exception {
    Traverser traverser = getGraphDb().traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL).traverse(node("1"));
    expectRelationships(traverser, THE_WORLD_AS_WE_KNOW_IT);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 44 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class PagedTraverserTest method shouldPageThroughResultsForWhollyDivisiblePageSize.

@Test
public void shouldPageThroughResultsForWhollyDivisiblePageSize() {
    Traverser myTraverser = simpleListTraverser();
    PagedTraverser traversalPager = new PagedTraverser(myTraverser, LIST_LENGTH / 10);
    int iterations = iterateThroughPagedTraverser(traversalPager);
    assertEquals(10, iterations);
    assertNull(traversalPager.next());
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser) Test(org.junit.Test)

Aggregations

Traverser (org.neo4j.graphdb.traversal.Traverser)44 Test (org.junit.Test)19 Path (org.neo4j.graphdb.Path)15 Transaction (org.neo4j.graphdb.Transaction)10 HashSet (java.util.HashSet)6 Node (org.neo4j.graphdb.Node)6 Predicate (org.neo4j.helpers.Predicate)6 Set (java.util.Set)4 Stack (java.util.Stack)4 WeightedPath (org.neo4j.graphalgo.WeightedPath)4 BestFirstSelectorFactory (org.neo4j.graphalgo.impl.util.BestFirstSelectorFactory)4 StopAfterWeightIterator (org.neo4j.graphalgo.impl.util.StopAfterWeightIterator)4 Relationship (org.neo4j.graphdb.Relationship)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)2 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)2 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)2