Пример #1
0
        public void TestCreateFromArray()
        {
            var arr = new int[] { 10, 12, 8, 14, 7, 6, 15, 13, 11, 1, 9, 2, 3, 4, 5 };
            var bst = new myBalancedBST();

            bst.CreateFromArray(arr);
            Assert.AreEqual(arr.Length, bst.BSTArray.Length);
            for (var i = 0; i < bst.BSTArray.Length; i++)
            {
                Assert.AreEqual(i + 1, bst.BSTArray[i]);
            }
        }
Пример #2
0
        public void TestIsBalanced()
        {
            var arr = new int[] { 10, 12, 8, 14, 7, 6, 15, 13, 11, 1, 9, 2, 3, 4, 5 };
            var bst = new myBalancedBST();

            bst.CreateFromArray(arr);
            Assert.AreEqual(arr.Length, bst.BSTArray.Length);
            for (var i = 0; i < bst.BSTArray.Length; i++)
            {
                Assert.AreEqual(i + 1, bst.BSTArray[i]);
            }
            bst.GenerateTree();
            CheckNodes(bst.Root);
            Assert.IsTrue(bst.IsBalanced(bst.Root));
        }