示例#1
0
        public void NodeSplit()
        {
            // prepare data
            var rootNode = new ArneTreeNode <Char, Char>('0', 0);
            var tNode    = new ArneTreeNode <Char, Char>('T', 1);
            var rNode    = new ArneTreeNode <Char, Char>('R', 1);
            var xNode    = new ArneTreeNode <Char, Char>('X', 1);
            var aNode    = new ArneTreeNode <Char, Char>('A', 2);
            var bNode    = new ArneTreeNode <Char, Char>('B', 2);

            // initialize
            rootNode.Right = tNode;
            tNode.Left     = aNode;
            tNode.Right    = rNode;
            rNode.Left     = bNode;
            rNode.Right    = xNode;

            // perform operation
            Assert.AreEqual(xNode, xNode.Split());
            Assert.AreEqual(rNode, rNode.Split());
            Assert.AreEqual(rootNode, rootNode.Split());
            rootNode.Right = rootNode.Right.Split();

            // check results

            // references
            Assert.AreEqual(rNode, rootNode.Right);
            Assert.AreEqual(tNode, rNode.Left);
            Assert.AreEqual(xNode, rNode.Right);
            Assert.AreEqual(aNode, tNode.Left);
            Assert.AreEqual(bNode, tNode.Right);

            // levels
            Assert.AreEqual(0u, rootNode.Level);
            Assert.AreEqual(2u, rNode.Level);
            Assert.AreEqual(1u, tNode.Level);
            Assert.AreEqual(1u, xNode.Level);
            Assert.AreEqual(2u, aNode.Level);
            Assert.AreEqual(2u, bNode.Level);
        }