static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) { // Properties not covered by equals() assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops()); assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder()); assertThat(graphA).isEqualTo(graphB); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops()); if (!graph.allowsSelfLoops()) { assertThat(node).isNotEqualTo(adjacentNode);
@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); } } }
assertThat(network.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(network.isDirected()).isEqualTo(asGraph.isDirected()); assertThat(network.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
static void assertStronglyEquivalent(Graph<?> treeA, Graph<?> treeB) { // Properties not covered by equals() assertThat(treeA.allowsSelfLoops()).isEqualTo(treeB.allowsSelfLoops()); assertThat(treeA.nodeOrder()).isEqualTo(treeB.nodeOrder()); assertThat(treeA).isEqualTo(treeB); }
checkArgument(!graph.allowsSelfLoops(), "the graph cannot allow self loops");
static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) { // Properties not covered by equals() assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops()); assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder()); assertThat(graphA).isEqualTo(graphB); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
@Override public GraphType getType() { return (graph.isDirected() ? new DefaultGraphType.Builder().directed() : new DefaultGraphType.Builder().undirected()) .weighted(false).allowMultipleEdges(false).allowSelfLoops(graph.allowsSelfLoops()) .build(); }
assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops()); if (!graph.allowsSelfLoops()) { assertThat(node).isNotEqualTo(adjacentNode);
@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); } } }
assertThat(network.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(network.isDirected()).isEqualTo(asGraph.isDirected()); assertThat(network.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());