Beispiel #1
0
        public void CreateMinimalHeightBSTTest(int[] testArray, int expectedRootNode, int expectedHeight)
        {
            // Act
            BinaryTreeNode <int> resultTree = Question_4_2.CreateMinimalHeightBST(testArray);

            TestHelper.PrintBinaryTree(resultTree);
            List <int> resultTreeInOrder = resultTree.ToListInOrder();

            // Assert
            Assert.AreEqual(expectedRootNode, resultTree.Data, "Incorrect root node returned.");
            Assert.AreEqual(expectedHeight, resultTree.GetHeight(), "Incorrect height returned.");
            Assert.AreEqual(testArray.Length, resultTreeInOrder.Count, "Incorrect number of nodes returned.");
            for (int i = 0; i < testArray.Length; i++)
            {
                Assert.AreEqual(testArray[i], resultTreeInOrder[i], $"Element at index {i} does not match.");
            }
        }