コード例 #1
0
 @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);
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 @Test
 public void copyOf_nullArgument() {
   try {
     ImmutableUndirectedGraph<Object, Object> unused = ImmutableUndirectedGraph.copyOf(null);
     fail("Should have rejected a null graph");
   } catch (NullPointerException expected) {
   }
 }
コード例 #4
0
 @Test
 public void addGraph_overlap() {
   UndirectedGraph<Integer, String> graph = Graphs.createUndirected(immutableGraph.config());
   populateInputGraph(graph);
   // Add an edge that is in 'graph' (overlap)
   builder.addEdge(E12, N1, N2);
   builder.addGraph(graph);
   assertThat(builder.build()).isEqualTo(graph);
 }
コード例 #5
0
 @Test
 public void addGraph_incompatibleSelfLoopConfig() {
   try {
     UndirectedGraph graph = Graphs.createUndirected(Graphs.config().noSelfLoops());
     ImmutableUndirectedGraph.Builder immutableGraphBuilder = ImmutableUndirectedGraph.builder();
     immutableGraphBuilder.addGraph(graph);
     fail("Should have rejected a graph with an incompatible self-loop configuration");
   } catch (IllegalArgumentException expected) {
   }
 }
コード例 #6
0
 @Test
 public void addGraph_incompatibleMultigraphConfig() {
   try {
     UndirectedGraph multigraph = Graphs.createUndirected(Graphs.MULTIGRAPH);
     ImmutableUndirectedGraph.Builder immutableGraphBuilder = ImmutableUndirectedGraph.builder();
     immutableGraphBuilder.addGraph(multigraph);
     fail("Should have rejected a graph with an incompatible multigraph configuration");
   } catch (IllegalArgumentException expected) {
   }
 }
コード例 #7
0
 @Test
 public void addGraph_inconsistentEdges() {
   UndirectedGraph<Integer, String> graph = Graphs.createUndirected(immutableGraph.config());
   populateInputGraph(graph);
   builder.addEdge(E12, N5, N1);
   try {
     builder.addGraph(graph);
     fail(
         "Should have rejected a graph whose edge definitions were inconsistent with existing"
             + "builder state");
   } catch (IllegalArgumentException expected) {
   }
 }
コード例 #8
0
 @Test
 public void inDegree_oneEdge() {
   addEdge(E12, N1, N2);
   assertEquals(1, immutableGraph.inDegree(N2));
   assertEquals(1, immutableGraph.inDegree(N1));
 }
コード例 #9
0
 @Test
 public void successors_oneEdge() {
   addEdge(E12, N1, N2);
   assertThat(immutableGraph.successors(N1)).containsExactly(N2);
   assertThat(immutableGraph.successors(N2)).containsExactly(N1);
 }
コード例 #10
0
 @Test
 public void outEdges_oneEdge() {
   addEdge(E12, N1, N2);
   assertThat(immutableGraph.outEdges(N2)).containsExactly(E12);
   assertThat(immutableGraph.outEdges(N1)).containsExactly(E12);
 }
コード例 #11
0
 @Test
 public void edgesConnecting_oneEdge() {
   addEdge(E12, N1, N2);
   assertThat(immutableGraph.edgesConnecting(N1, N2)).containsExactly(E12);
   assertThat(immutableGraph.edgesConnecting(N2, N1)).containsExactly(E12);
 }
コード例 #12
0
 @Override
 public ImmutableUndirectedGraph<Integer, String> createGraph() {
   builder = ImmutableUndirectedGraph.builder(Graphs.config().noSelfLoops());
   return builder.build();
 }
コード例 #13
0
 @Test
 public void addGraph() {
   UndirectedGraph<Integer, String> graph = Graphs.createUndirected(immutableGraph.config());
   populateInputGraph(graph);
   assertThat(builder.addGraph(graph).build()).isEqualTo(graph);
 }
コード例 #14
0
 @Test
 public void copyOf() {
   UndirectedGraph<Integer, String> graph = Graphs.createUndirected(immutableGraph.config());
   populateInputGraph(graph);
   assertThat(ImmutableUndirectedGraph.copyOf(graph)).isEqualTo(graph);
 }