Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathCheckBinaryTreeIsValidBSTTest.java
More file actions
Latest commit
61 lines (54 loc) · 1.6 KB
/
Copy pathCheckBinaryTreeIsValidBSTTest.java
File metadata and controls
61 lines (54 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
packagecom.thealgorithms.datastructures.trees;
importstaticorg.junit.jupiter.api.Assertions.assertFalse;
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
importorg.junit.jupiter.api.Test;
/**
* @author Albina Gimaletdinova on 17/02/2023
*/
publicclassCheckBinaryTreeIsValidBSTTest {
@Test
publicvoidtestRootNull() {
assertTrue(CheckBinaryTreeIsValidBST.isBST(null));
}
@Test
publicvoidtestOneNode() {
finalBinaryTree.Noderoot = TreeTestUtils.createTree(newInteger[] {Integer.MIN_VALUE});
assertTrue(CheckBinaryTreeIsValidBST.isBST(root));
}
/*
9
/ \
7 13
/\ / \
3 8 10 20
*/
@Test
publicvoidtestBinaryTreeIsBST() {
finalBinaryTree.Noderoot = TreeTestUtils.createTree(newInteger[] {9, 7, 13, 3, 8, 10, 20});
assertTrue(CheckBinaryTreeIsValidBST.isBST(root));
}
/*
9
/ \
7 13
/\ / \
3 8 10 13 <--- duplicated node
*/
@Test
publicvoidtestBinaryTreeWithDuplicatedNodesIsNotBST() {
finalBinaryTree.Noderoot = TreeTestUtils.createTree(newInteger[] {9, 7, 13, 3, 8, 10, 13});
assertFalse(CheckBinaryTreeIsValidBST.isBST(root));
}
/*
9
/ \
7 13
/\ / \
3 8 10 12 <---- violates BST rule, needs to be more than 13 (parent node)
*/
@Test
publicvoidtestBinaryTreeIsNotBST() {
finalBinaryTree.Noderoot = TreeTestUtils.createTree(newInteger[] {9, 7, 13, 3, 8, 10, 12});
assertFalse(CheckBinaryTreeIsValidBST.isBST(root));
}
}