Skip to content

Commit 7e6d4aa

Browse files
fix tests
1 parent ef100d4 commit 7e6d4aa

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

Advanced.Algorithms.Tests/DataStructures/Tree/TestHelpers/BinarySearchTreeTester.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,24 @@ public class BinarySearchTreeTester<T> where T:IComparable
1111
{
1212

1313
public static bool VerifyIsBinarySearchTree(IBSTNode<T> node)
14+
{
15+
return VerifyIsBinarySearchTree(node, int.MinValue, int.MaxValue);
16+
}
17+
18+
public static bool VerifyIsBinarySearchTree(IBSTNode<T> node, int lowerBound, int upperBound)
1419
{
1520
if (node == null)
1621
{
1722
return true;
1823
}
1924

20-
if (node.Left != null)
21-
{
22-
if (node.Left.Value.CompareTo(node.Value) > 0)
23-
{
24-
return false;
25-
}
26-
}
27-
28-
if (node.Right != null)
25+
if (node.Value >= upperBound || node.Value <= lowerBound)
2926
{
30-
if (node.Right.Value.CompareTo(node.Value) < 0)
31-
{
32-
return false;
33-
}
27+
return false;
3428
}
35-
return VerifyIsBinarySearchTree(node.Left) &&
36-
VerifyIsBinarySearchTree(node.Right);
29+
30+
return VerifyIsBinarySearchTree(node.Left, lowerBound, node.Value) &&
31+
VerifyIsBinarySearchTree(node.Right, node.Value, upperBound);
3732
}
3833
}
3934
}

0 commit comments

Comments
 (0)