@Override public boolean hasEdgeConnecting(N nodeU, N nodeV) { return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose }
@Override public boolean hasEdgeConnecting(N nodeU, N nodeV) { return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose } }
@Override public boolean hasEdgeConnecting(EndpointPair<N> endpoints) { return delegate().hasEdgeConnecting(transpose(endpoints)); } }
@Override public boolean hasEdgeConnecting(N nodeU, N nodeV) { return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose } }
assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue(); assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, predecessor, node)); allEndpointPairs.add(EndpointPair.of(graph, node, successor)); assertThat(graph.predecessors(successor)).contains(node); assertThat(graph.hasEdgeConnecting(node, successor)).isTrue(); assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, node, successor)); assertThat(graph.hasEdgeConnecting(endpoints.source(), endpoints.target())).isTrue(); } else { assertThat(graph.hasEdgeConnecting(endpoints.nodeU(), endpoints.nodeV())).isTrue();
@After public void validateGraphState() { assertStronglyEquivalent(graph, Graphs.copyOf(graph)); assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph)); Graph<Integer> asGraph = graph.asGraph(); AbstractGraphTest.validateGraph(asGraph); assertThat(graph.nodes()).isEqualTo(asGraph.nodes()); assertThat(graph.edges()).isEqualTo(asGraph.edges()); assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected()); assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops()); for (Integer node : graph.nodes()) { assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node)); assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node)); assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node)); assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node)); assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node)); assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node)); for (Integer otherNode : graph.nodes()) { boolean hasEdge = graph.hasEdgeConnecting(node, otherNode); assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode)); assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge); assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT)) .isEqualTo(hasEdge); } } }
@Override public boolean hasEdgeConnecting(N nodeU, N nodeV) { return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose } }
@Override public boolean hasEdgeConnecting(N nodeU, N nodeV) { return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose } }
@Override public EndpointPair<V> getEdge(V sourceVertex, V targetVertex) { if (sourceVertex == null || targetVertex == null) { return null; } else if (!graph.hasEdgeConnecting(sourceVertex, targetVertex)) { return null; } else { return createEdge(sourceVertex, targetVertex); } }
@Override public double getEdgeWeight(EndpointPair<V> e) { if (e == null) { throw new NullPointerException(); } else if (!graph.hasEdgeConnecting(e.nodeU(), e.nodeV())) { throw new IllegalArgumentException("no such edge in graph: " + e.toString()); } else { return Graph.DEFAULT_EDGE_WEIGHT; } }
@Override public Set<EndpointPair<V>> getAllEdges(V sourceVertex, V targetVertex) { if (sourceVertex == null || targetVertex == null || !graph.nodes().contains(sourceVertex) || !graph.nodes().contains(targetVertex)) { return null; } else if (!graph.hasEdgeConnecting(sourceVertex, targetVertex)) { return Collections.emptySet(); } else { return Collections.singleton(createEdge(sourceVertex, targetVertex)); } }
assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue(); allEndpointPairs.add(EndpointPair.of(graph, node, successor)); assertThat(graph.predecessors(successor)).contains(node); assertThat(graph.hasEdgeConnecting(node, successor)).isTrue();
@After public void validateGraphState() { assertStronglyEquivalent(graph, Graphs.copyOf(graph)); assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph)); Graph<Integer> asGraph = graph.asGraph(); AbstractGraphTest.validateGraph(asGraph); assertThat(graph.nodes()).isEqualTo(asGraph.nodes()); assertThat(graph.edges()).isEqualTo(asGraph.edges()); assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected()); assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops()); for (Integer node : graph.nodes()) { assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node)); assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node)); assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node)); assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node)); assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node)); assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node)); for (Integer otherNode : graph.nodes()) { boolean hasEdge = graph.hasEdgeConnecting(node, otherNode); assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode)); assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge); assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT)) .isEqualTo(hasEdge); } } }