@Override public EndpointPair<N> apply(N successor) { return EndpointPair.ordered(node, successor); } })));
@Override public EndpointPair<N> apply(N predecessor) { return EndpointPair.ordered(predecessor, node); } }),
static <N> EndpointPair<N> transpose(EndpointPair<N> endpoints) { if (endpoints.isOrdered()) { return EndpointPair.ordered(endpoints.target(), endpoints.source()); } return endpoints; }
@Test public void hasEdgeConnecting_backwards() { putEdge(N1, N2); assertThat(graph.hasEdgeConnecting(EndpointPair.ordered(N2, N1))).isFalse(); }
@Test public void edgeValueOrDefault_undirected_mismatch() { graph = ValueGraphBuilder.undirected().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.edgeValueOrDefault(EndpointPair.ordered(2, 1), "default")).isEqualTo("A"); assertThat(graph.edgeValueOrDefault(EndpointPair.ordered(2, 1), "default")).isEqualTo("A"); }
@Test public void putEdgeValue_undirected_orderMismatch() { graph = ValueGraphBuilder.undirected().build(); assertThat(graph.putEdgeValue(EndpointPair.ordered(1, 2), "irrelevant")).isNull(); }
@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); }
@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)); } }
@Test public void hasEdgeConnecting_directed_correct() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.hasEdgeConnecting(EndpointPair.ordered(1, 2))).isTrue(); }
@Test public void edgeValueOrDefault_directed_backwards() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.edgeValueOrDefault(EndpointPair.ordered(2, 1), "default")) .isEqualTo("default"); }
@Test public void hasEdgeConnecting_directed_backwards() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.hasEdgeConnecting(EndpointPair.ordered(2, 1))).isFalse(); }
@Test public void edgeValueOrDefault_directed_correct() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.edgeValueOrDefault(EndpointPair.ordered(1, 2), "default")).isEqualTo("A"); }
@Test public void removeEdge_undirected_orderMismatch() { graph = ValueGraphBuilder.undirected().build(); graph.putEdgeValue(1, 2, "1-2"); assertThat(graph.removeEdge(EndpointPair.ordered(1, 2))).isEqualTo("1-2"); }
public PackageSanityTests() { setDistinctValues(AbstractGraphBuilder.class, GRAPH_BUILDER_A, GRAPH_BUILDER_B); setDistinctValues(Graph.class, IMMUTABLE_GRAPH_A, IMMUTABLE_GRAPH_B); setDistinctValues(NetworkBuilder.class, NETWORK_BUILDER_A, NETWORK_BUILDER_B); setDistinctValues(Network.class, IMMUTABLE_NETWORK_A, IMMUTABLE_NETWORK_B); setDefault(EndpointPair.class, EndpointPair.ordered("A", "B")); }
@Test public void edgeValue_directed_correct() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.edgeValue(EndpointPair.ordered(1, 2))).hasValue("A"); }
@Test public void edgeValue_directed_backwards() { graph = ValueGraphBuilder.directed().build(); graph.putEdgeValue(1, 2, "A"); assertThat(graph.edgeValue(EndpointPair.ordered(2, 1))).isEmpty(); }