/** * This test checks an implementation dependent feature. It tests that the method {@code addEdge} * will silently add the missing nodes to the builder, 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_builder_nodesNotInGraph() { addNode(N1); assertTrue(addEdge(E15, N1, N5)); assertTrue(addEdge(E41, N4, N1)); assertTrue(addEdge(E23, N2, N3)); assertThat(immutableGraph.nodes()).containsExactly(N1, N5, N4, N2, N3).inOrder(); assertThat(immutableGraph.edges()).containsExactly(E15, E41, E23).inOrder(); assertThat(immutableGraph.edgesConnecting(N1, N5)).containsExactly(E15); assertThat(immutableGraph.edgesConnecting(N4, N1)).containsExactly(E41); assertThat(immutableGraph.edgesConnecting(N2, N3)).containsExactly(E23); assertThat(immutableGraph.edgesConnecting(N3, N2)).containsExactly(E23); }
@Test public void addEdge_builder_existingNodes() { // Adding nodes initially for safety (insulating from possible future // modifications to proxy methods) addNode(N1); addNode(N2); assertTrue(addEdge(E12, N1, N2)); assertThat(immutableGraph.edges()).contains(E12); assertThat(immutableGraph.edgesConnecting(N1, N2)).containsExactly(E12); assertThat(immutableGraph.edgesConnecting(N2, N1)).containsExactly(E12); }
@Test public void edgesConnecting_oneEdge() { addEdge(E12, N1, N2); assertThat(immutableGraph.edgesConnecting(N1, N2)).containsExactly(E12); assertThat(immutableGraph.edgesConnecting(N2, N1)).containsExactly(E12); }