示例#1
0
        private static void Validate <T>(bool expected, BinaryTreeNode <T> root)
            where T : IEquatable <T>
        {
            var result = Question_4_4.IsBalanced(root);

            Assert.AreEqual(expected, result);
        }
        public void IsBalancedTest_ReturnFalse()
        {
            // Arrange
            var testRoot = new BinaryTreeNode <int>(1)
            {
                Left = new BinaryTreeNode <int>(2)
                {
                    Left  = new BinaryTreeNode <int>(4),
                    Right = new BinaryTreeNode <int>(5)
                    {
                        Left  = new BinaryTreeNode <int>(6),
                        Right = new BinaryTreeNode <int>(7)
                    }
                },
                Right = new BinaryTreeNode <int>(3)
            };

            Console.WriteLine("Input:");
            TestHelper.PrintBinaryTree(testRoot);

            // Act
            bool result = Question_4_4.IsBalanced(testRoot);

            // Assert
            Assert.IsFalse(result, "IsBalanced returned True.");
        }
示例#3
0
 public void Question_4_4_InvalidCases()
 {
     TestHelpers.AssertExceptionThrown(() => Question_4_4.IsBalanced((BinaryTreeNode <int>)null), typeof(ArgumentNullException));
 }