### Question:
DepthFirstSearch extends XFirstSearch { @Override public void start( EdgeExplorer explorer, int startNode ) { TIntArrayStack stack = new TIntArrayStack(); GHBitSet explored = createBitSet(); stack.push(startNode); int current; while (stack.size() > 0) { current = stack.pop(); if (!explored.contains(current) && goFurther(current)) { EdgeIterator iter = explorer.setBaseNode(current); while (iter.next()) { int connectedId = iter.getAdjNode(); if (checkAdjacent(iter)) { stack.push(connectedId); } } explored.add(current); } } }  @Override void start( EdgeExplorer explorer, int startNode );  }### Answer:
@Test public void testDFS1() { DepthFirstSearch dfs = new DepthFirstSearch() { @Override public boolean goFurther( int v ) { counter++; assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v)); set.add(v); list.add(v); return super.goFurther(v); } }; EncodingManager em = new EncodingManager("CAR"); FlagEncoder fe = em.getEncoder("CAR"); Graph g = new GraphBuilder(em).create(); g.edge(1, 2, 1, false); g.edge(1, 5, 1, false); g.edge(1, 4, 1, false); g.edge(2, 3, 1, false); g.edge(3, 4, 1, false); g.edge(5, 6, 1, false); g.edge(6, 4, 1, false); dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1); assertTrue(counter > 0); assertEquals("{1, 2, 3, 4, 5, 6}", list.toString()); }
@Test public void testDFS2() { DepthFirstSearch dfs = new DepthFirstSearch() { @Override public boolean goFurther( int v ) { counter++; assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v)); set.add(v); list.add(v); return super.goFurther(v); } }; EncodingManager em = new EncodingManager("CAR"); FlagEncoder fe = em.getEncoder("CAR"); Graph g = new GraphBuilder(em).create(); g.edge(1, 2, 1, false); g.edge(1, 4, 1, true); g.edge(1, 3, 1, false); g.edge(2, 3, 1, false); g.edge(4, 3, 1, true); dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1); assertTrue(counter > 0); assertEquals("{1, 2, 3, 4}", list.toString()); }