Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //Quick-find
            QuickFindUF grid = new QuickFindUF(10);

            grid.Union(2, 3);
            grid.Union(3, 6);
            grid.Union(6, 5);
            Console.WriteLine($"Does 2 and 5 connect? {grid.Connected(2, 5)}");
            Console.WriteLine($"Does 6 and 1 connect? {grid.Connected(1, 6)}");

            //Quick-union
            QuickUnionUF quuf = new QuickUnionUF(10);

            quuf.Union(2, 3);
            quuf.Union(3, 6);
            quuf.Union(6, 5);
            Console.WriteLine($"Does 2 and 5 connect? {quuf.Connected(2, 5)}");
            Console.WriteLine($"Does 6 and 1 connect? {quuf.Connected(1, 6)}");

            Console.WriteLine(GreatestCommonDenominator.GetGCD(9, 0));
        }
    public static void Main()
    {
        QuickUnionUF uf = new QuickUnionUF(10);

        Console.WriteLine("Connected (1,2): " + ((uf.Connected(1, 2) == false) ? "Passed":"Failed"));
        uf.Union(2, 3);
        Console.WriteLine("Connected (2,3): " + ((uf.Connected(2, 3) == true) ? "Passed":"Failed"));
        uf.Union(4, 7);
        uf.Union(1, 8);
        uf.Union(1, 7);
        uf.Union(2, 4);
        Console.WriteLine("Connected (1,4): " + ((uf.Connected(1, 4) == true) ? "Passed":"Failed"));
        Console.WriteLine("Connected (8,9): " + ((uf.Connected(8, 9) == false) ? "Passed":"Failed"));
        Console.WriteLine("Connected (3,8): " + ((uf.Connected(3, 8) == true) ? "Passed":"Failed"));
        Console.WriteLine("Connected (5,9): " + ((uf.Connected(5, 9) == false) ? "Passed":"Failed"));
        Console.WriteLine("Connected (10,9): " + ((uf.Connected(10, 9) == false) ? "Passed":"Failed"));
    }
Esempio n. 5
0
        public void testConnected_ParameterValidation_QLessThan0()
        {
            QuickUnionUF quickUnionUF = new QuickUnionUF(10);

            quickUnionUF.Connected(4, -1);
        }
Esempio n. 6
0
        public void testConnected_ParameterValidation_PLargerThanN()
        {
            QuickUnionUF quickUnionUF = new QuickUnionUF(10);

            quickUnionUF.Connected(11, 4);
        }
Esempio n. 7
0
        public void testConnected_ParameterValidation_PEqualN()
        {
            QuickUnionUF quickUnionUF = new QuickUnionUF(10);

            quickUnionUF.Connected(10, 4);
        }