### Question:
AnanasGraph { public AnanasGraph subDag(Set<String> leaves) { Map<String, Iterable<Step>> m = DFSBranch(leaves); Set<Step> set = new HashSet<>(); for (Map.Entry<String, Iterable<Step>> e : m.entrySet()) { for (Step s : e.getValue()) { set.add(s); } } Set<DagEdge> connections = new HashSet(); for (Step s : set) { for (Step successor : this.graph.successors(s)) { connections.add(new DagEdge(s.id, successor.id)); } } Dag subDag = new Dag(connections, set); return new AnanasGraph(subDag, leaves); } AnanasGraph(Dag dag, Set<String> goals); AnanasGraph reverse(); Map<String, Iterable<Step>> DFSBranch(Set<String> leaves); Iterable<Step> DFSBranch(String stepId); Map<String, Iterable<Step>> DFSBranch(); AnanasGraph subDag(Set<String> leaves); Set<Step> topologicalSort(); Set<Step> successors(Step step); boolean isStartNode(Step step); Set<Step> predecessors(Step step); @Override String toString();  }### Answer:
@Test public void subDag() { DagRequest dag = wikiDag(); AnanasGraph subdagGraphBuilder = new AnanasGraph(dag.dag, dag.goals).reverse().subDag(dag.goals); Assert.assertEquals(7, subdagGraphBuilder.dag.connections.size()); Assert.assertEquals(7, subdagGraphBuilder.dag.steps.size()); }