### Question:
DirectedAcyclicGraph extends SimpleDirectedGraph<V, E> implements Iterable<V> { public Iterator<V> iterator() { return new TopoIterator(); } DirectedAcyclicGraph(Class<? extends E> edgeClass);  DirectedAcyclicGraph(Class<? extends E> edgeClass, boolean weighted);  DirectedAcyclicGraph(EdgeFactory<V, E> ef);  DirectedAcyclicGraph(EdgeFactory<V, E> ef, boolean weighted); protected  DirectedAcyclicGraph(
        EdgeFactory<V, E> ef, VisitedStrategyFactory visitedStrategyFactory,
        TopoOrderMap<V> topoOrderMap, boolean weighted); static GraphBuilder<V, E, ? extends DirectedAcyclicGraph<V, E>> createBuilder(
        Class<? extends E> edgeClass); static GraphBuilder<V, E, ? extends DirectedAcyclicGraph<V, E>> createBuilder(
        EdgeFactory<V, E> ef); @Override GraphType getType(); @Override boolean addVertex(V v); @Override boolean removeVertex(V v); @Override E addEdge(V sourceVertex, V targetVertex); @Override boolean addEdge(V sourceVertex, V targetVertex, E e); Set<V> getAncestors(V vertex); Set<V> getDescendants(V vertex); Iterator<V> iterator();  }### Answer:
@Test public void testTopoIterationOrderLinearGraph() { DirectedAcyclicGraph<Long, DefaultEdge> dag = new DirectedAcyclicGraph<>(DefaultEdge.class); LinearGraphGenerator<Long, DefaultEdge> graphGen = new LinearGraphGenerator<>(100); graphGen.generateGraph(dag, new LongVertexFactory(), null); Iterator<Long> internalTopoIter = dag.iterator(); TopologicalOrderIterator<Long, DefaultEdge> comparTopoIter = new TopologicalOrderIterator<>(dag); while (comparTopoIter.hasNext()) { Long compareNext = comparTopoIter.next(); Long myNext = null; if (internalTopoIter.hasNext()) { myNext = internalTopoIter.next(); } assertSame(compareNext, myNext); assertEquals(comparTopoIter.hasNext(), internalTopoIter.hasNext()); } }
@Test public void testTopoIterationOrderComplexGraph() { for (int seed = 0; seed < 20; seed++) { DirectedAcyclicGraph<Long, DefaultEdge> dag = new DirectedAcyclicGraph<>(DefaultEdge.class); RepeatableRandomGraphGenerator<Long, DefaultEdge> graphGen = new RepeatableRandomGraphGenerator<>(100, 500, seed); graphGen.generateGraph(dag, new LongVertexFactory(), null); ConnectivityInspector<Long, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(dag); Iterator<Long> internalTopoIter = dag.iterator(); List<Long> previousVertices = new ArrayList<>(); while (internalTopoIter.hasNext()) { Long vertex = internalTopoIter.next(); for (Long previousVertex : previousVertices) { connectivityInspector.pathExists(vertex, previousVertex); } previousVertices.add(vertex); } } }