|
27 | 27 | import static org.junit.Assert.assertThrows; |
28 | 28 |
|
29 | 29 | import com.google.common.collect.ImmutableSet; |
| 30 | +import java.util.Set; |
30 | 31 | import org.jspecify.annotations.NullUnmarked; |
31 | 32 | import org.junit.Test; |
32 | 33 | import org.junit.runner.RunWith; |
@@ -383,6 +384,36 @@ public void transpose_directedGraph() { |
383 | 384 | AbstractGraphTest.validateGraph(transpose); |
384 | 385 | } |
385 | 386 |
|
| 387 | + @Test |
| 388 | + public void transpose_directedGraph_incidentEdges_invalidatedByNodeRemoval() { |
| 389 | + MutableGraph<Integer> directedGraph = GraphBuilder.directed().build(); |
| 390 | + directedGraph.putEdge(N1, N2); |
| 391 | + Graph<Integer> transpose = transpose(directedGraph); |
| 392 | + assertThrows(IllegalArgumentException.class, () -> transpose.incidentEdges(N3)); |
| 393 | + assertThrows(NullPointerException.class, () -> transpose.incidentEdges(null)); |
| 394 | + |
| 395 | + Set<EndpointPair<Integer>> incidentEdges = transpose.incidentEdges(N1); |
| 396 | + assertThat(incidentEdges).containsExactly(EndpointPair.ordered(N2, N1)); |
| 397 | + directedGraph.removeNode(N1); |
| 398 | + assertThrows(IllegalStateException.class, incidentEdges::size); |
| 399 | + assertThrows(IllegalStateException.class, incidentEdges::iterator); |
| 400 | + assertThrows( |
| 401 | + IllegalStateException.class, () -> incidentEdges.contains(EndpointPair.ordered(N2, N1))); |
| 402 | + int unused = incidentEdges.hashCode(); // doesn't throw |
| 403 | + } |
| 404 | + |
| 405 | + @Test |
| 406 | + public void transpose_directedGraph_incidentEdges_stableIncidentEdgeOrder() { |
| 407 | + MutableGraph<Integer> directedGraph = |
| 408 | + GraphBuilder.directed().incidentEdgeOrder(ElementOrder.stable()).build(); |
| 409 | + directedGraph.putEdge(N2, N1); |
| 410 | + directedGraph.putEdge(N1, N3); |
| 411 | + |
| 412 | + assertThat(transpose(directedGraph).incidentEdges(N1)) |
| 413 | + .containsExactly(EndpointPair.ordered(N1, N2), EndpointPair.ordered(N3, N1)) |
| 414 | + .inOrder(); |
| 415 | + } |
| 416 | + |
386 | 417 | @Test |
387 | 418 | public void transpose_undirectedValueGraph() { |
388 | 419 | MutableValueGraph<Integer, String> undirectedGraph = ValueGraphBuilder.undirected().build(); |
|
0 commit comments