@Test public void addGraph_overlap() { DirectedGraph<Integer, String> graph = Graphs.createDirected(directedGraph.config()); populateInputGraph(graph); // Add an edge that is in 'graph' (overlap) builder.addEdge(E12, N1, N2); builder.addGraph(graph); assertThat(builder.build()).isEqualTo(graph); }
@Test public void addGraph_incompatibleMultigraphConfig() { try { DirectedGraph multigraph = Graphs.createDirected(Graphs.MULTIGRAPH); ImmutableDirectedGraph.Builder immutableGraphBuilder = ImmutableDirectedGraph.builder(); immutableGraphBuilder.addGraph(multigraph); fail("Should have rejected a graph with an incompatible multigraph configuration"); } catch (IllegalArgumentException expected) { } }
@Test public void addGraph_incompatibleSelfLoopConfig() { try { DirectedGraph graph = Graphs.createDirected(Graphs.config().noSelfLoops()); ImmutableDirectedGraph.Builder immutableGraphBuilder = ImmutableDirectedGraph.builder(); immutableGraphBuilder.addGraph(graph); fail("Should have rejected a graph with an incompatible self-loop configuration"); } catch (IllegalArgumentException expected) { } }
@Test public void addGraph_inconsistentEdges() { DirectedGraph<Integer, String> graph = Graphs.createDirected(directedGraph.config()); populateInputGraph(graph); builder.addEdge(E21, N3, N1); try { builder.addGraph(graph); fail( "Should have rejected a graph whose edge definitions were inconsistent with existing" + "builder state"); } catch (IllegalArgumentException expected) { } }
@Override @CanIgnoreReturnValue final boolean addEdge(String e, Integer n1, Integer n2) { DirectedGraph<Integer, String> oldGraph = Graphs.copyOf(directedGraph); graph = directedGraph = builder.addEdge(e, n1, n2).build(); return !graph.equals(oldGraph); }
@Override @CanIgnoreReturnValue final boolean addNode(Integer n) { DirectedGraph<Integer, String> oldGraph = Graphs.copyOf(directedGraph); graph = directedGraph = builder.addNode(n).build(); return !graph.equals(oldGraph); }
@Override public ImmutableDirectedGraph<Integer, String> createGraph() { builder = ImmutableDirectedGraph.builder(Graphs.config().noSelfLoops()); return builder.build(); }
@Test public void addGraph() { DirectedGraph<Integer, String> graph = Graphs.createDirected(directedGraph.config()); populateInputGraph(graph); assertThat(builder.addGraph(graph).build()).isEqualTo(graph); }