public void TestInit() { Assert.AreEqual(_sut.Count(), _count); for (int i = 0; i < _count; ++i) { Assert.AreEqual(i, _sut.Find(i)); } }
private void TestFind(IUnionFind uf) { Assert.AreEqual(100, uf.Components().Count, "The given UnionFind algorithm must be defined for 100 nodes"); bool result; /* Initially, I find no path */ result = uf.Find(0, 1); Assert.AreEqual(result, false); /* Test directly connected nodes */ uf.Union(0, 1); result = uf.Find(0, 1); Assert.AreEqual(result, true); /* Test indirectly connected nodes */ uf.Union(1, 2); result = uf.Find(0, 2); Assert.AreEqual(result, true); /* Test non-connected nodes */ result = uf.Find(0, 9); Assert.AreEqual(result, false); /* Test find in an union of all nodes */ Random random = new Random(); List <int> components = uf.Components(); for (int i = 3; i < components.Count; i++) { uf.Union(i - 1, i); } components = uf.Components(); for (int i = 0; i < components.Count; i++) { int p = random.Next(0, components.Count); int q = random.Next(0, components.Count); result = uf.Find(p, q); Assert.AreEqual(result, true); } Assert.AreEqual(CountConnectedComponents(components), 1); }
public void TestFind() { Assert.AreEqual(8, sut.Find(8)); }
public int Find(int vertex) { return _unionFind.Find(vertex); }