示例#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_Inserted_Then_ChildNodesCorrect()
        {
            Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(10);
            binaryTree.Insert(5);
            binaryTree.Insert(11);

            Assert.IsNotNull(binaryTree.Root);
            Assert.AreEqual(10, binaryTree.Root.Value);
            Assert.IsNotNull(binaryTree.Root.Left);
            Assert.IsNotNull(binaryTree.Root.Right);
            Assert.AreEqual(5, binaryTree.Root.Left.Value);
            Assert.AreEqual(11, binaryTree.Root.Right.Value);
        }
示例#4
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));
 }
示例#5
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));
 }
示例#6
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));
 }
示例#7
0
 public void When_TreeOnlyHasRoot_Then_BalancedIsTrue()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
     Assert.IsTrue(Chapter10._01_IsBalancedTree(binaryTree));
 }
示例#8
0
 public void When_TreeOnlyHasRoot_Then_HeightIsZero()
 {
     Chapter10.BinaryTree binaryTree = new Chapter10.BinaryTree(5);
     Assert.AreEqual(0, Chapter10._01_GetNodeHeight(binaryTree.Root));
 }