@Test public void testExactDepthPathsReturnsNoLoops() { // Layout: // // (a)-->(b)==>(c)-->(e) // ^ / // \ v // (d) // graph.makeEdgeChain( "a,b,c,d,b,c,e" ); Node a = graph.getNode( "a" ); Node e = graph.getNode( "e" ); assertPaths( GraphAlgoFactory.pathsWithLength( PathExpanders.forType( MyRelTypes.R1 ), 3 ).findAllPaths( a, e ), "a,b,c,e", "a,b,c,e" ); assertPaths( GraphAlgoFactory.pathsWithLength( PathExpanders.forType( MyRelTypes.R1 ), 4 ).findAllPaths( a, e ), "a,b,d,c,e" ); assertPaths( GraphAlgoFactory.pathsWithLength( PathExpanders.forType( MyRelTypes.R1 ), 6 ).findAllPaths( a, e ) ); }
@Test public void mirroredTraversalReversesInitialState() { /* * (a)-->(b)-->(c)-->(d) */ createGraph( "a TO b", "b TO c", "c TO d" ); BranchCollisionPolicy collisionPolicy = ( evaluator, pathPredicate ) -> new StandardBranchCollisionDetector( null, null ) { @Override protected boolean includePath( Path path, TraversalBranch startPath, TraversalBranch endPath ) { assertEquals( 0, startPath.state() ); assertEquals( 10, endPath.state() ); return true; } }; Iterables.count( getGraphDb().bidirectionalTraversalDescription() // Just make up a number bigger than the path length (in this case 10) so that we can assert it in // the collision policy later .mirroredSides( getGraphDb().traversalDescription().uniqueness( NODE_PATH ).expand( PathExpanders.forType( to ), new InitialBranchState.State<>( 0, 10 ) ) ) .collisionPolicy( collisionPolicy ) .traverse( getNodeWithName( "a" ), getNodeWithName( "d" ) ) ); } }