Node currentNode = nodesToExamine.remove(0); for (Node adjacentNode : graph.successors(currentNode)) { int updatedInDegree = inDegreeMap.get(adjacentNode) - 1; inDegreeMap.put(adjacentNode, updatedInDegree);
@Test public void successors_oneEdge() { putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactly(N2); // Edge direction handled correctly assertThat(graph.successors(N2)).isEmpty(); }
@Test public void successors_oneEdge() { putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactly(N2); assertThat(graph.successors(N2)).containsExactly(N1); }
@Test public void successors_selfLoop() { putEdge(N1, N1); assertThat(graph.successors(N1)).containsExactly(N1); putEdge(N2, N1); assertThat(graph.successors(N1)).containsExactly(N1, N2); }
@Test public void successors_selfLoop() { putEdge(N1, N1); assertThat(graph.successors(N1)).containsExactly(N1); putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactly(N1, N2); }
@Override @Test public void successors_checkReturnedSetMutability() { addNode(N1); Set<Integer> successors = graph.successors(N1); try { successors.add(N2); fail(ERROR_MODIFIABLE_SET); } catch (UnsupportedOperationException e) { putEdge(N1, N2); assertThat(successors).containsExactlyElementsIn(graph.successors(N1)); } }
@Override @Test public void successors_checkReturnedSetMutability() { addNode(N1); Set<Integer> successors = graph.successors(N1); try { successors.add(N2); fail(ERROR_MODIFIABLE_SET); } catch (UnsupportedOperationException e) { putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactlyElementsIn(successors); } }
@Test public void successors_noSuccessors() { addNode(N1); assertThat(graph.successors(N1)).isEmpty(); }
for (T m : graphCopy.successors(n))
@Test public void successors_nodeNotInGraph() { try { graph.successors(NODE_NOT_IN_GRAPH); fail(ERROR_NODE_NOT_IN_GRAPH); } catch (IllegalArgumentException e) { assertNodeNotInGraphErrorMessage(e); } }
@Test public void removeEdge_nodeNotPresent() { putEdge(N1, N2); assertThat(graph.removeEdge(N1, NODE_NOT_IN_GRAPH)).isFalse(); assertThat(graph.successors(N1)).contains(N2); }
@Override @Test public void addEdge_selfLoop() { assertThat(putEdge(N1, N1)).isTrue(); assertThat(graph.successors(N1)).containsExactly(N1); assertThat(graph.predecessors(N1)).containsExactly(N1); }
@Test public void removeEdge_existingEdge() { putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactly(N2); assertThat(graph.predecessors(N2)).containsExactly(N1); assertThat(graph.removeEdge(N1, N2)).isTrue(); assertThat(graph.removeEdge(N1, N2)).isFalse(); assertThat(graph.successors(N1)).isEmpty(); assertThat(graph.predecessors(N2)).isEmpty(); }
/** * This test checks an implementation dependent feature. It tests that the method {@code addEdge} * will silently add the missing nodes to the graph, then add the edge connecting them. We are not * using the proxy methods here as we want to test {@code addEdge} when the end-points are not * elements of the graph. */ @Test public void addEdge_nodesNotInGraph() { graph.addNode(N1); assertTrue(graph.putEdge(N1, N5)); assertTrue(graph.putEdge(N4, N1)); assertTrue(graph.putEdge(N2, N3)); assertThat(graph.nodes()).containsExactly(N1, N5, N4, N2, N3).inOrder(); assertThat(graph.successors(N1)).containsExactly(N5); assertThat(graph.successors(N2)).containsExactly(N3); assertThat(graph.successors(N3)).isEmpty(); assertThat(graph.successors(N4)).containsExactly(N1); assertThat(graph.successors(N5)).isEmpty(); } }
public void removeEdge_antiparallelEdges() { putEdge(N1, N2); putEdge(N2, N1); assertThat(graph.removeEdge(N1, N2)).isTrue(); assertThat(graph.successors(N1)).isEmpty(); assertThat(graph.predecessors(N1)).containsExactly(N2); assertThat(graph.edges()).hasSize(1); assertThat(graph.removeEdge(N2, N1)).isTrue(); assertThat(graph.successors(N1)).isEmpty(); assertThat(graph.predecessors(N1)).isEmpty(); assertThat(graph.edges()).isEmpty(); }
@Test public void removeEdge_existingSelfLoopEdge() { putEdge(N1, N1); assertThat(graph.removeEdge(N1, N1)).isTrue(); assertThat(graph.nodes()).containsExactly(N1); assertThat(graph.successors(N1)).isEmpty(); } }
@Test public void removeEdge_edgeNotPresent() { putEdge(N1, N2); addNode(N3); assertThat(graph.removeEdge(N1, N3)).isFalse(); assertThat(graph.successors(N1)).contains(N2); } }
@After public void validateUndirectedEdges() { for (Integer node : graph.nodes()) { new EqualsTester() .addEqualityGroup( graph.predecessors(node), graph.successors(node), graph.adjacentNodes(node)) .testEquals(); } }
@Override public Set<N> successors(N node) { checkNotNull(node, "node"); checkArgument(delegate.nodes().contains(node), NODE_NOT_IN_TREE, node); return delegate.successors(node); }
@Test public void successors_oneEdge() { putEdge(N1, N2); assertThat(graph.successors(N1)).containsExactly(N2); assertThat(graph.successors(N2)).containsExactly(N1); }