@Test public void incidentEdges_oneEdge() { putEdge(N1, N2); EndpointPair<Integer> expectedEndpoints = EndpointPair.unordered(N1, N2); assertThat(graph.incidentEdges(N1)).containsExactly(expectedEndpoints); assertThat(graph.incidentEdges(N2)).containsExactly(expectedEndpoints); }
@Test public void incidentEdges_oneEdge() { putEdge(N1, N2); EndpointPair<Integer> expectedEndpoints = EndpointPair.ordered(N1, N2); assertThat(graph.incidentEdges(N1)).containsExactly(expectedEndpoints); assertThat(graph.incidentEdges(N2)).containsExactly(expectedEndpoints); }
@Test public void incidentEdges_noIncidentEdges() { addNode(N1); assertThat(graph.incidentEdges(N1)).isEmpty(); }
@Override @Test public void incidentEdges_checkReturnedSetMutability() { addNode(N1); Set<EndpointPair<Integer>> incidentEdges = graph.incidentEdges(N1); try { incidentEdges.add(EndpointPair.ordered(N1, N2)); fail(ERROR_MODIFIABLE_SET); } catch (UnsupportedOperationException e) { putEdge(N1, N2); assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1)); } }
@Override @Test public void incidentEdges_checkReturnedSetMutability() { addNode(N1); Set<EndpointPair<Integer>> incidentEdges = graph.incidentEdges(N1); try { incidentEdges.add(EndpointPair.unordered(N1, N2)); fail(ERROR_MODIFIABLE_SET); } catch (UnsupportedOperationException e) { putEdge(N1, N2); assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1)); } }
@Test public void incidentEdges_selfLoop() { putEdge(N1, N1); assertThat(graph.incidentEdges(N1)).containsExactly(EndpointPair.ordered(N1, N1)); putEdge(N1, N2); assertThat(graph.incidentEdges(N1)).containsExactly( EndpointPair.ordered(N1, N1), EndpointPair.ordered(N1, N2)); }
@Test public void incidentEdges_selfLoop() { putEdge(N1, N1); assertThat(graph.incidentEdges(N1)).containsExactly(EndpointPair.unordered(N1, N1)); putEdge(N1, N2); assertThat(graph.incidentEdges(N1)).containsExactly( EndpointPair.unordered(N1, N1), EndpointPair.unordered(N1, N2)); }
@Test public void incidentEdges_nodeNotInGraph() { try { graph.incidentEdges(NODE_NOT_IN_GRAPH); fail(ERROR_NODE_NOT_IN_GRAPH); } catch (IllegalArgumentException e) { assertNodeNotInGraphErrorMessage(e); } }
@Override public Set<EndpointPair<N>> incidentEdges(N node) { checkNotNull(node, "node"); checkArgument(delegate.nodes().contains(node), NODE_NOT_IN_TREE, node); return delegate.incidentEdges(node); }