Beispiel #1
0
        public void WeightedQuickUnionTest()
        {
            //Arrange
            var weightedQuickUnion = new WeightedQuickUnion(10);

            //7-9 6-9 2-0 5-8 7-4 6-1 0-5 4-3 2-4

            //Act
            weightedQuickUnion.Union(7, 9);
            weightedQuickUnion.Union(6, 9);
            weightedQuickUnion.Union(2, 0);
            weightedQuickUnion.Union(5, 8);
            weightedQuickUnion.Union(7, 4);
            weightedQuickUnion.Union(6, 1);
            weightedQuickUnion.Union(0, 5);
            weightedQuickUnion.Union(4, 3);
            weightedQuickUnion.Union(2, 4);
            //Assert
            Assert.IsTrue(weightedQuickUnion.IsConnected(7, 9));
            Assert.IsTrue(weightedQuickUnion.IsConnected(6, 9));
            Assert.IsTrue(weightedQuickUnion.IsConnected(2, 0));
            Assert.IsTrue(weightedQuickUnion.IsConnected(5, 8));
            Assert.IsTrue(weightedQuickUnion.IsConnected(7, 4));
            Assert.IsTrue(weightedQuickUnion.IsConnected(6, 1));
            Assert.IsTrue(weightedQuickUnion.IsConnected(0, 5));
            Assert.IsTrue(weightedQuickUnion.IsConnected(4, 3));
            Assert.IsTrue(weightedQuickUnion.IsConnected(2, 4));

            foreach (var component in weightedQuickUnion.Components)
            {
                Trace.WriteLine(component);
            }
        }
Beispiel #2
0
        public void UnionTests()
        {
            var union = new WeightedQuickUnion(10);

            union.Union(5, 8);

            Assert.IsTrue(union.Connected(5, 8));
            Assert.IsFalse(union.Connected(5, 9));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int n = 10;
            WeightedQuickUnion weighted = new WeightedQuickUnion(n);

            weighted.Union(0, 1);
            weighted.Union(2, 3);
            weighted.Union(4, 5);
            weighted.Union(5, 0);
            weighted.Union(6, 7);
            weighted.Union(8, 9);
            weighted.Union(0, 8);

            bool found = weighted.Connected(9, 0);
        }