Пример #1
0
        public void UnionFindNode_MergeTwo()
        {
            UnionFindNode <string> nodeA = CreateStringNode("A");
            UnionFindNode <string> nodeB = CreateStringNode("B");

            UnionFindNode <string> .Merge(nodeA, nodeB);

            Assert.AreEqual(nodeB.Label, nodeA.FindSet());
        }
Пример #2
0
        public void UnionFindNode_MergeThree_Chained()
        {
            UnionFindNode <string> nodeA = CreateStringNode("A");
            UnionFindNode <string> nodeB = CreateStringNode("B");
            UnionFindNode <string> nodeC = CreateStringNode("C");

            UnionFindNode <string> .Merge(nodeA, nodeB);

            UnionFindNode <string> .Merge(nodeB, nodeC);

            Assert.AreEqual(nodeC.Label, nodeA.FindSet());
            Assert.AreEqual(nodeC.Label, nodeB.FindSet());
            Assert.AreEqual(nodeC.Label, nodeC.FindSet());
        }
Пример #3
0
        public void UnionFindNode_MergeFour_TwoSets()
        {
            UnionFindNode <string> nodeA = CreateStringNode("A");
            UnionFindNode <string> nodeB = CreateStringNode("B");
            UnionFindNode <string> nodeC = CreateStringNode("C");
            UnionFindNode <string> nodeD = CreateStringNode("D");

            UnionFindNode <string> .Merge(nodeA, nodeB);

            UnionFindNode <string> .Merge(nodeC, nodeD);

            UnionFindNode <string> .Merge(nodeB, nodeD);

            Assert.AreEqual(nodeD.Label, nodeA.FindSet());
            Assert.AreEqual(nodeD.Label, nodeB.FindSet());
            Assert.AreEqual(nodeD.Label, nodeC.FindSet());
            Assert.AreEqual(nodeD.Label, nodeD.FindSet());
        }