Beispiel #1
0
        private void Validate <T>(int size, BinaryTreeNode <int> expected)
            where T : IEquatable <T>
        {
            var result = Question_4_2.CreateMinimalBinaryTree(Enumerable.Range(0, size).ToArray());

            TreeHelpers.AssertBinaryTreesEqual <int>(expected, result);
        }
Beispiel #2
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.");
            }
        }
Beispiel #3
0
 public void Question_4_2_InvalidCases()
 {
     TestHelpers.AssertExceptionThrown(() => Question_4_2.CreateMinimalBinaryTree(null), typeof(ArgumentNullException));
     TestHelpers.AssertExceptionThrown(() => Question_4_2.CreateMinimalBinaryTree(new int[0]), typeof(ArgumentOutOfRangeException));
 }