DirectedGraph { public Map<V, Integer> inDegree() { Map<V, Integer> result = new HashMap<>(); for (V vertex : neighbors.keySet()) { result.put(vertex, 0); } for (V from : neighbors.keySet()) { for (V to : neighbors.get(from)) { result.put(to, result.get(to) + 1); } } return result; }  void addVertex(V vertex); boolean containsVertex(V vertex); void removeVertex(V vertex); void addEdge(V from, V to); void removeEdge(V from, V to); List<V> getNeighbors(V vertex); Map<V, Integer> outDegree(); Map<V, Integer> inDegree(); List<V> topologicalSort(); List<V> reverseTopologicalSort(); boolean isDag(); @Override String toString();  }
@Test public void inDegree() { Map<Character, Integer> result = graph.inDegree(); Map<Character, Integer> expected = new HashMap<>(7); expected.put('A', 0); expected.put('B', 1); expected.put('C', 1); expected.put('D', 0); expected.put('E', 1); expected.put('F', 1); expected.put('G', 1); assertEquals(expected, result); }