public void SearchBSTTests()
        {
            SearchInABinarySearchTree obj = new SearchInABinarySearchTree();

            TreeNode node = new TreeNode(4)
            {
                left = new TreeNode(2)
                {
                    left  = new TreeNode(1),
                    right = new TreeNode(3)
                },
                right = new TreeNode(7)
            };

            var x = obj.SearchBST(node, 2);

            //            [18,2,22,null,null,null,63,null,84,null,null]
            //
            node = new TreeNode(18)
            {
                left  = new TreeNode(2),
                right = new TreeNode(22)
                {
                    right = new TreeNode(63)
                    {
                        right = new TreeNode(84)
                    }
                }
            };

            x = obj.SearchBST(node, 63);
        }
        public void SearchBSTTest1()
        {
            TreeNode root = null;

            int      targetValue = 2;
            TreeNode expected    = null;
            TreeNode result      = new SearchInABinarySearchTree().SearchBST(root, targetValue);

            Assert.AreSame(expected, result);
        }
Exemple #3
0
        public void SearchInBinarySearchTreeTestCase2()
        {
            var tree = new MyBinaryTree(4);

            tree.Left       = new MyBinaryTree(2);
            tree.Left.Left  = new MyBinaryTree(1);
            tree.Left.Right = new MyBinaryTree(3);
            tree.Right      = new MyBinaryTree(7);

            var result = SearchInABinarySearchTree.SearchBST(tree, 5);

            result.Should().BeNull();
        }
        public void SearchBSTTest2()
        {
            TreeNode root = new TreeNode(4);

            root.left       = new TreeNode(2);
            root.left.left  = new TreeNode(1);
            root.left.right = new TreeNode(3);
            root.right      = new TreeNode(7);

            int      targetValue = 8;
            TreeNode expected    = null;
            TreeNode result      = new SearchInABinarySearchTree().SearchBST(root, targetValue);

            Assert.AreSame(expected, result);
        }
 public void SearchInABinarySearchTreeTestMethod()
 {
     SearchInABinarySearchTree searchInABinarySearchTree = new SearchInABinarySearchTree();
     // need a helper class to compare trees
 }