예제 #1
0
        public void FalseSmallerRight()
        {
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5, Right = new TreeNode<int> { Value = 2 } }
            };

            Assert.IsFalse(tree.IsValidBST());
        }
예제 #2
0
        public void FalseLargerLeft()
        {
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5, Left = new TreeNode<int> { Value = 7 } }
            };

            Assert.IsFalse(tree.IsValidBST());
        }
예제 #3
0
        public void FalseMultiLevelAbsoluteLimit()
        {
            /*
             *       5
             *    2
             *  1   8
             */
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5,
                    Left = new TreeNode<int> { Value = 2,
                        Left = new TreeNode<int> { Value = 1 },
                        Right = new TreeNode<int> { Value = 8 } } }
            };

            Assert.IsFalse(tree.IsValidBST());
        }
예제 #4
0
        public void TrueSmallerLeft()
        {
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5, Left = new TreeNode<int> { Value = 2 } }
            };

            Assert.IsTrue(tree.IsValidBST());
        }
예제 #5
0
        public void TrueMultiLevel()
        {
            /*
             *       5
             *    2
             *  1   3
             */
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5,
                    Left = new TreeNode<int> { Value = 2,
                        Left = new TreeNode<int> { Value = 1 },
                        Right = new TreeNode<int> { Value = 3 }
                    }
                }
            };

            Assert.IsTrue(tree.IsValidBST());
        }
예제 #6
0
        public void TrueLargerRight()
        {
            var tree = new BinarySearchTree
            {
                Root = new TreeNode<int> { Value = 5, Right = new TreeNode<int> { Value = 7 } }
            };

            Assert.IsTrue(tree.IsValidBST());
        }
예제 #7
0
        public void TrueIfRootOnly()
        {
            var tree = new BinarySearchTree
                           {
                               Root = new TreeNode<int> {Value = 1}
                           };

            Assert.IsTrue(tree.IsValidBST());
        }
예제 #8
0
        public void TrueIfNull()
        {
            var tree = new BinarySearchTree();

            Assert.IsTrue(tree.IsValidBST());
        }