public void testUnionAndConnected_MultiConnection() { QuickUnionUF quickUnionUF = new QuickUnionUF(10); quickUnionUF.Union(0, 1); quickUnionUF.Union(2, 1); Assert.IsTrue(quickUnionUF.Connected(0, 1)); Assert.IsTrue(quickUnionUF.Connected(2, 1)); Assert.IsTrue(quickUnionUF.Connected(2, 0)); Assert.AreEqual(8, quickUnionUF.Count()); Assert.AreEqual(1, quickUnionUF.Find(1)); Assert.AreEqual(1, quickUnionUF.Find(0)); Assert.AreEqual(1, quickUnionUF.Find(2)); quickUnionUF.Union(2, 5); Assert.IsTrue(quickUnionUF.Connected(0, 1)); Assert.IsTrue(quickUnionUF.Connected(2, 1)); Assert.IsTrue(quickUnionUF.Connected(2, 0)); Assert.IsTrue(quickUnionUF.Connected(5, 0)); Assert.IsTrue(quickUnionUF.Connected(5, 1)); Assert.IsTrue(quickUnionUF.Connected(5, 2)); Assert.AreEqual(7, quickUnionUF.Count()); Assert.AreEqual(5, quickUnionUF.Find(1)); Assert.AreEqual(5, quickUnionUF.Find(0)); Assert.AreEqual(5, quickUnionUF.Find(2)); Assert.AreEqual(5, quickUnionUF.Find(5)); }
public void testUnionAndConnected_NewConnection() { QuickUnionUF quickUnionUF = new QuickUnionUF(10); Assert.IsFalse(quickUnionUF.Connected(0, 1)); Assert.AreEqual(10, quickUnionUF.Count()); quickUnionUF.Union(0, 1); Assert.IsTrue(quickUnionUF.Connected(0, 1)); Assert.AreEqual(9, quickUnionUF.Count()); Assert.AreEqual(1, quickUnionUF.Find(1)); Assert.AreEqual(1, quickUnionUF.Find(0)); }