public void FalseSmallerRight() { var tree = new BinarySearchTree { Root = new TreeNode<int> { Value = 5, Right = new TreeNode<int> { Value = 2 } } }; Assert.IsFalse(tree.IsValidBST()); }
public void FalseLargerLeft() { var tree = new BinarySearchTree { Root = new TreeNode<int> { Value = 5, Left = new TreeNode<int> { Value = 7 } } }; Assert.IsFalse(tree.IsValidBST()); }
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()); }
public void TrueSmallerLeft() { var tree = new BinarySearchTree { Root = new TreeNode<int> { Value = 5, Left = new TreeNode<int> { Value = 2 } } }; Assert.IsTrue(tree.IsValidBST()); }
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()); }
public void TrueLargerRight() { var tree = new BinarySearchTree { Root = new TreeNode<int> { Value = 5, Right = new TreeNode<int> { Value = 7 } } }; Assert.IsTrue(tree.IsValidBST()); }
public void TrueIfRootOnly() { var tree = new BinarySearchTree { Root = new TreeNode<int> {Value = 1} }; Assert.IsTrue(tree.IsValidBST()); }
public void TrueIfNull() { var tree = new BinarySearchTree(); Assert.IsTrue(tree.IsValidBST()); }