@Test public void testUnionFind() { int SIZE = 10000; IntegerUnionFind uf = new IntegerUnionFind(SIZE); int count = countEquivalenceClasses(uf); Assert.assertTrue("Got count " + count, count == SIZE); uf.union(3, 7); Assert.assertTrue(uf.find(3) == uf.find(7)); Assert.assertTrue("Got uf.find(3)=" + uf.find(3), uf.find(3) == 3 || uf.find(3) == 7); uf.union(7, SIZE - 1); Assert.assertTrue(uf.find(3) == uf.find(SIZE - 1)); Assert.assertTrue("Got uf.find(3)=" + uf.find(3), uf.find(3) == 3 || uf.find(3) == 7 || uf.find(3) == SIZE - 1); for (int i = 0; i < SIZE - 1; i++) { uf.union(i, i + 1); } count = countEquivalenceClasses(uf); Assert.assertTrue("Got count " + count, count == 1); uf = new IntegerUnionFind(SIZE); for (int i = 0; i < SIZE; i++) { if ((i % 2) == 0) { uf.union(i, 0); } else { uf.union(i, 1); } } count = countEquivalenceClasses(uf); Assert.assertTrue("Got count " + count, count == 2); }
throw new IllegalArgumentException("No PointsToSetVariable for j: " + j); uf.union(repI, repJ); int rep = uf.find(repI); PointsToSetVariable p = (PointsToSetVariable) pointsToSets.get(rep);
throw new IllegalArgumentException("No PointsToSetVariable for j: " + j); uf.union(repI, repJ); int rep = uf.find(repI); PointsToSetVariable p = (PointsToSetVariable) pointsToSets.get(rep);