-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidateBinarySearchTreeTest.java
More file actions
executable file
·39 lines (31 loc) · 1.17 KB
/
Copy pathValidateBinarySearchTreeTest.java
File metadata and controls
executable file
·39 lines (31 loc) · 1.17 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
package algorithm.graph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ValidateBinarySearchTreeTest {
@Test
void validateBST_TestA() {
BinaryTreeNode root = null;
int[] values = {5, 7, 8, 3, 2, 90, 12, 15, 4, 95};
for (int value : values) {
root = TreeOperation.insert(root, value);
}
Assertions.assertTrue(ValidateBinarySearchTree.validate(root));
}
@Test
void validateBST_TestB() {
BinaryTreeNode leftRight = new BinaryTreeNode(11, null, null);
BinaryTreeNode left = new BinaryTreeNode(5, null, leftRight);
BinaryTreeNode right = new BinaryTreeNode(15, null, null);
BinaryTreeNode root = new BinaryTreeNode(10, left, right);
Assertions.assertFalse(ValidateBinarySearchTree.validate(root));
}
@Test
void validateBST_TestC() {
Assertions.assertTrue(ValidateBinarySearchTree.validate(null));
}
@Test
void validateBST_TestD() {
BinaryTreeNode root = new BinaryTreeNode(10, null, null);
Assertions.assertTrue(ValidateBinarySearchTree.validate(root));
}
}