示例#1
0
        public void PathSumTestCase3()
        {
            var tree = new MyBinaryTree(1);

            tree.Left = new MyBinaryTree(2);

            PathSum.HasPathSum(tree, 1).Should().Be(false);
        }
示例#2
0
        public void PathSumTestCase1()
        {
            var tree = new MyBinaryTree(5);

            tree.Left            = new MyBinaryTree(4);
            tree.Left.Left       = new MyBinaryTree(11);
            tree.Left.Left.Left  = new MyBinaryTree(7);
            tree.Left.Left.Right = new MyBinaryTree(2);
            tree.Right           = new MyBinaryTree(8);
            tree.Right.Left      = new MyBinaryTree(4);
            tree.Right.Left.Left = new MyBinaryTree(1);
            tree.Right.Right     = new MyBinaryTree(13);

            PathSum.HasPathSum(tree, 22).Should().Be(true);
        }
示例#3
0
        public void TestMethod2()
        {
            // Arrange
            PathSum  question = new PathSum();
            TreeNode root     = new TreeNode(-2);

            root.right = new TreeNode(-3);
            bool expected = true;

            // Act
            bool actual = question.HasPathSum(root, -5);

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void TestPath1()
        {
            var root = new TreeNode(5);

            root.Left  = new TreeNode(4);
            root.Right = new TreeNode(8);

            root.Left.Left       = new TreeNode(11);
            root.Left.Left.Left  = new TreeNode(7);
            root.Left.Left.Right = new TreeNode(2);

            root.Right.Left        = new TreeNode(13);
            root.Right.Right       = new TreeNode(4);
            root.Right.Right.Right = new TreeNode(1);

            var r = PathSum.HasPathSum(root, 22);

            Assert.AreEqual(r, true);

            r = PathSum.HasPathSum(root, 13);
            Assert.AreEqual(r, false);
        }
示例#5
0
        public void TestMethod1()
        {
            // Arrange
            PathSum  question = new PathSum();
            TreeNode root     = new TreeNode(5);

            root.left              = new TreeNode(4);
            root.left.left         = new TreeNode(11);
            root.left.left.left    = new TreeNode(7);
            root.left.left.right   = new TreeNode(2);
            root.right             = new TreeNode(8);
            root.right.left        = new TreeNode(13);
            root.right.right       = new TreeNode(4);
            root.right.right.right = new TreeNode(1);
            bool expected = true;

            // Act
            bool actual = question.HasPathSum(root, 22);

            // Assert
            Assert.AreEqual(expected, actual);
        }