Пример #1
0
        public void When_RootHasOneChild_Then_HeightIsOne()
        {
            Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
            binaryTree.Insert(2);

            Assert.AreEqual(1, Chapter10._01_GetNodeHeight(binaryTree.Root));
        }
Пример #2
0
        public void When_TreeIsUnbalanced_Then_HeightIsMaxOfLeftAndRight()
        {
            Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
            binaryTree.Insert(2);
            binaryTree.Insert(7);
            binaryTree.Insert(8);
            binaryTree.Insert(9);

            Assert.AreEqual(3, Chapter10._01_GetNodeHeight(binaryTree.Root));
        }
Пример #3
0
 public void When_LeftAndRightSubTreeHeightDiffersByMoreThanOne_Then_TreeIsNotBalanced()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(10);
     binaryTree.Insert(5, 4, 3, 2, 1, 15, 12, 17);
     Assert.IsFalse(Chapter10._01_IsBalancedTree(binaryTree));
 }
Пример #4
0
 public void When_LeftAndRightSubTreeHeightDiffersByOne_Then_TreeIsBalanced()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(10);
     binaryTree.Insert(5, 7, 3, 15, 12);
     Assert.IsTrue(Chapter10._01_IsBalancedTree(binaryTree));
 }
Пример #5
0
 public void When_LeftAndRightSubtreesHaveSameHeight_Then_TreeIsBalanced()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(10);
     binaryTree.Insert(5, 7, 3, 15, 12, 17);
     Assert.IsTrue(Chapter10._01_IsBalancedTree(binaryTree));
 }
Пример #6
0
 public void When_TreeOnlyHasRoot_Then_BalancedIsTrue()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
     Assert.IsTrue(Chapter10._01_IsBalancedTree(binaryTree));
 }
Пример #7
0
 public void When_TreeOnlyHasRoot_Then_HeightIsZero()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
     Assert.AreEqual(0, Chapter10._01_GetNodeHeight(binaryTree.Root));
 }