public void test() { Graph g1 = new PrimaryGraph(); Node[] n1 = g1.newNodes(2); g1.newEdge(n1[0], n1[1]); Graph g2 = new PrimaryGraph(); Node[] n2 = g2.newNodes(2); g2.newEdge(n2[0], n2[1]); SecondaryGraph sg = new SecondaryGraph(); sg.adoptGraph(g1); sg.adoptGraph(g2); Clusterer cc = Clusterers.connectedComponents(sg); Collection<Object> components = cc.getClusters(); assertEquals(2, components.size()); Iterator<Object> iterator = components.iterator(); Object c1 = iterator.next(); Object c2 = iterator.next(); assertTrue(c1 != c2); assertTrue(components.contains(c1)); assertTrue(components.contains(c2)); Collection<Node> comp1 = cc.getCluster(c1); assertTrue(comp1.containsAll(Arrays.asList(n1))); Collection<Node> comp2 = cc.getCluster(c2); assertTrue(comp2.containsAll(Arrays.asList(n2))); assertTrue(cc.getCluster(c1).contains(n1[0])); assertTrue(cc.getCluster(c2).contains(n2[0])); }
public void test() { Graph g = new PrimaryGraph(); Node[] n = g.newNodes(0, 1, 2, 3, 4, 5, 6, 7, 8); g.newEdge(n[0], n[1]); g.newEdge(n[1], n[2]); g.newEdge(n[2], n[1]); g.newEdge(n[3], n[4]); g.newEdge(n[4], n[5]); g.newEdge(n[5], n[3]); g.newEdge(n[7], n[6]); g.newEdge(n[8], n[7]); Clusterer scc = Clusterers.stronglyConnectedComponents(g); assertEquals(6, scc.getClusters().size()); Set<Set<Node>> clusters = new HashSet<Set<Node>>(); for (Object c : scc.getClusters()) { clusters.add(new HashSet<Node>(scc.getCluster(c))); } assertTrue(clusters.contains(new HashSet<Node>(Arrays.asList(n[1], n[2])))); assertTrue(clusters.contains(new HashSet<Node>(Arrays.asList(n[0])))); assertTrue(clusters.contains(new HashSet<Node>(Arrays.asList(n[3], n[4], n[5])))); assertTrue(clusters.contains(new HashSet<Node>(Arrays.asList(n[6])))); assertTrue(clusters.contains(new HashSet<Node>(Arrays.asList(n[7])))); }
protected void setUp() { this.n = g.newNodes(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); this.root = n[0]; this.path = root.asPath(); }