Esempio n. 1
0
        public void InOrderTraverseTest()
        {
            List <int> list = new List <int>();
            ThreadedBinaryTree <int> threadedTree = BuildTestBinaryTree().BuildThreadedTree();

            threadedTree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 4, 2, 1, 6, 3, 7 }, list);
        }
Esempio n. 2
0
        public void BigThreadedBinaryTreeSimpleTest()
        {
            List <int> list = new List <int>();
            ThreadedBinaryTree <int> tree = BuildBigTestBinaryTree().BuildThreadedTree();

            tree.PreOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 1, 2, 4, 8, 9, 5, 10, 3, 6, 7, 11, 12 }, list);
            list.Clear();
            tree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 8, 4, 9, 2, 5, 10, 1, 6, 3, 11, 7, 12 }, list);
        }
Esempio n. 3
0
        public void ThreadedBinaryTreeNodeInsertLeftSimpleTest()
        {
            ThreadedBinaryTree <int> threadedTree = BuildTestBinaryTree().BuildThreadedTree();
            var n2     = threadedTree.Root.Left;
            var n4     = n2.Left;
            var result = n2.InsertLeft(11);

            Assert.AreEqual(11, result.Value);
            Assert.AreSame(n2.Left, result);
            Assert.IsFalse(result.IsLeftThreaded);
            Assert.IsTrue(result.IsRightThreaded);
            Assert.AreSame(result.Left, n4);
            Assert.AreSame(result.Right, n2);
            Assert.AreSame(n4.Right, result);
            List <int> list = new List <int>();

            threadedTree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 4, 11, 2, 1, 6, 3, 7 }, list);
        }
Esempio n. 4
0
        public void BigThreadedBinaryTreeRemoveTest()
        {
            List <int> list = new List <int>();
            ThreadedBinaryTree <int> tree = BuildBigTestBinaryTree().BuildThreadedTree();
            var n3    = tree.Root.Right;
            var n12   = n3.Right.Right;
            var dummy = n12.Right;

            Assert.IsFalse(n3.IsLeftThreaded);
            Assert.IsFalse(n3.IsRightThreaded);
            n3.RemoveRight();
            Assert.IsFalse(n3.IsLeftThreaded);
            Assert.IsTrue(n3.IsRightThreaded);
            Assert.AreSame(n3.Right, dummy);
            tree.PreOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 1, 2, 4, 8, 9, 5, 10, 3, 6 }, list);
            list.Clear();
            tree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 8, 4, 9, 2, 5, 10, 1, 6, 3 }, list);
        }
Esempio n. 5
0
        public void ThreadedBinaryTreeNodeInsertRightTest()
        {
            ThreadedBinaryTree <int> threadedTree = BuildTestBinaryTree().BuildThreadedTree();
            var n7     = threadedTree.Root.Right.Right;
            var dummy  = n7.Right;
            var result = n7.InsertRight(11);

            Assert.AreEqual(11, result.Value);
            Assert.IsTrue(n7.IsLeftThreaded);
            Assert.IsFalse(n7.IsRightThreaded);
            Assert.AreSame(n7.Right, result);
            Assert.IsTrue(result.IsLeftThreaded);
            Assert.IsTrue(result.IsRightThreaded);
            Assert.AreSame(result.Left, n7);
            Assert.AreSame(result.Right, dummy);
            List <int> list = new List <int>();

            threadedTree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 4, 2, 1, 6, 3, 7, 11 }, list);
        }
Esempio n. 6
0
        public void BigThreadedBinaryTreeInsertTest()
        {
            List <int> list = new List <int>();
            ThreadedBinaryTree <int> tree = BuildBigTestBinaryTree().BuildThreadedTree();
            var n3  = tree.Root.Right;
            var n11 = n3.Right.Left;

            Assert.IsTrue(n11.IsLeftThreaded);
            Assert.IsTrue(n11.IsRightThreaded);
            Assert.AreEqual(3, n11.Left.Value);
            Assert.AreEqual(7, n11.Right.Value);
            n3.InsertRight(15);
            Assert.IsTrue(n11.IsLeftThreaded);
            Assert.IsTrue(n11.IsRightThreaded);
            Assert.AreEqual(15, n11.Left.Value);
            Assert.AreEqual(7, n11.Right.Value);
            tree.PreOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 1, 2, 4, 8, 9, 5, 10, 3, 6, 15, 7, 11, 12 }, list);
            list.Clear();
            tree.InOrderTraverse(x => list.Add(x.Value));
            CollectionAssert.AreEqual(new int[] { 8, 4, 9, 2, 5, 10, 1, 6, 3, 15, 11, 7, 12 }, list);
        }