/** Tests Subgraph. */ public void testSubgraph() { UndirectedGraph<String, DefaultEdge> g = init(false); UndirectedSubgraph<String, DefaultEdge> sub = new UndirectedSubgraph<String, DefaultEdge>(g, null, null); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); Set<String> vset = new HashSet<String>(g.vertexSet()); g.removeVertex(v1); assertEquals(vset, sub.vertexSet()); // losing track g = init(false); vset = new HashSet<String>(); vset.add(v1); sub = new UndirectedSubgraph<String, DefaultEdge>(g, vset, null); assertEquals(vset, sub.vertexSet()); assertEquals(0, sub.degreeOf(v1)); assertEquals(Collections.EMPTY_SET, sub.edgeSet()); vset.add(v2); vset.add(v3); sub = new UndirectedSubgraph<String, DefaultEdge>( g, vset, new HashSet<DefaultEdge>(g.getAllEdges(v1, v2))); assertEquals(vset, sub.vertexSet()); assertEquals(1, sub.edgeSet().size()); }
/** . */ public void testInducedSubgraphListener() { UndirectedGraph<String, DefaultEdge> g = init(true); UndirectedSubgraph<String, DefaultEdge> sub = new UndirectedSubgraph<String, DefaultEdge>(g, null, null); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); g.addEdge(v3, v4); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); }
/** . */ public void testSubgraphListener() { UndirectedGraph<String, DefaultEdge> g = init(true); UndirectedSubgraph<String, DefaultEdge> sub = new UndirectedSubgraph<String, DefaultEdge>(g, null, null); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); Set<String> vset = new HashSet<String>(g.vertexSet()); g.removeVertex(v1); vset.remove(v1); assertEquals(vset, sub.vertexSet()); // not losing track assertEquals(g.edgeSet(), sub.edgeSet()); }