### Question:
ComplementGraphGenerator implements GraphGenerator<V, E, V> { public void generateGraph(Graph<V, E> target) { this.generateGraph(target, null, null); } ComplementGraphGenerator(Graph<V, E> graph);  ComplementGraphGenerator(Graph<V, E> graph, boolean generateSelfLoops); void generateGraph(Graph<V, E> target); @Override void generateGraph(
        Graph<V, E> target, VertexFactory<V> vertexFactory, Map<String, V> resultMap);  }### Answer:
@Test public void testEmptyGraph() { Graph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class); Graphs.addAllVertices(g, Arrays.asList(0, 1, 2, 3)); ComplementGraphGenerator<Integer, DefaultEdge> cgg = new ComplementGraphGenerator<>(g); Graph<Integer, DefaultEdge> target = new SimpleWeightedGraph<>(DefaultEdge.class); cgg.generateGraph(target); assertTrue(GraphTests.isComplete(target)); ComplementGraphGenerator<Integer, DefaultEdge> cgg2 = new ComplementGraphGenerator<>(target); Graph<Integer, DefaultEdge> target2 = new SimpleWeightedGraph<>(DefaultEdge.class); cgg2.generateGraph(target2); assertTrue(target2.edgeSet().isEmpty()); assertTrue(target2.vertexSet().equals(g.vertexSet())); }
@Test public void testUndirectedGraph() { Graph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class); Graphs.addAllVertices(g, Arrays.asList(0, 1, 2, 3)); g.addEdge(0, 1); g.addEdge(1, 2); g.addEdge(0, 2); ComplementGraphGenerator<Integer, DefaultEdge> cgg = new ComplementGraphGenerator<>(g); Graph<Integer, DefaultEdge> target = new SimpleWeightedGraph<>(DefaultEdge.class); cgg.generateGraph(target); assertTrue(target.vertexSet().equals(new HashSet<>(Arrays.asList(0, 1, 2, 3)))); assertEquals(3, target.edgeSet().size()); assertTrue(target.containsEdge(0, 3)); assertTrue(target.containsEdge(2, 3)); assertTrue(target.containsEdge(1, 3)); }
@Test public void testDirectedGraph() { Graph<Integer, DefaultEdge> g = new SimpleDirectedGraph<>(DefaultEdge.class); Graphs.addAllVertices(g, Arrays.asList(0, 1, 2)); g.addEdge(0, 1); g.addEdge(1, 2); g.addEdge(0, 2); ComplementGraphGenerator<Integer, DefaultEdge> cgg = new ComplementGraphGenerator<>(g); Graph<Integer, DefaultEdge> target = new SimpleWeightedGraph<>(DefaultEdge.class); cgg.generateGraph(target); assertTrue(target.vertexSet().equals(new HashSet<>(Arrays.asList(0, 1, 2)))); assertEquals(3, target.edgeSet().size()); assertTrue(target.containsEdge(1, 0)); assertTrue(target.containsEdge(2, 1)); assertTrue(target.containsEdge(2, 0)); }
@Test public void testGraphWithSelfLoops() { Graph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class); Graphs.addAllVertices(g, Arrays.asList(0, 1, 2)); g.addEdge(0, 1); g.addEdge(1, 2); g.addEdge(0, 2); ComplementGraphGenerator<Integer, DefaultEdge> cgg = new ComplementGraphGenerator<>(g, true); Graph<Integer, DefaultEdge> target = new Pseudograph<>(DefaultEdge.class); cgg.generateGraph(target); assertTrue(target.vertexSet().equals(new HashSet<>(Arrays.asList(0, 1, 2)))); assertEquals(3, target.edgeSet().size()); for (Integer v : target.vertexSet()) assertTrue(target.containsEdge(v, v)); }