-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeOperationTest.java
More file actions
executable file
·59 lines (47 loc) · 1.52 KB
/
Copy pathTreeOperationTest.java
File metadata and controls
executable file
·59 lines (47 loc) · 1.52 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
package algorithm.graph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class TreeOperationTest {
BinaryTreeNode root;
@BeforeEach
void init() {
int[] values = {5, 7, 8, 3, 2, 90, 12, 15, 4, 95};
for (int value : values) {
root = TreeOperation.insert(root, value);
}
// 5
// 3 7
// 2 4 8
// 90
// 12 95
// 15
}
@Test
void preOrder() {
Assertions.assertEquals("5 3 2 4 7 8 90 12 15 95", TreeOperation.preOrder(root));
}
@Test
void postOrder() {
Assertions.assertEquals("2 4 3 15 12 95 90 8 7 5", TreeOperation.postOrder(root));
}
@Test
void inOrder() {
Assertions.assertEquals("2 3 4 5 7 8 12 15 90 95", TreeOperation.inOrder(root));
}
@Test
void level() {
Assertions.assertEquals(6, TreeOperation.level(root));
}
@Test
void height() {
Assertions.assertEquals(5, TreeOperation.height(root));
}
@Test
void lowestCommonAncestor() {
BinaryTreeNode node1 = TreeOperation.lowestCommonAncestor(root, 15, 95);
Assertions.assertEquals(90, node1.data);
BinaryTreeNode node2 = TreeOperation.lowestCommonAncestor(root, 4, 12);
Assertions.assertEquals(5, node2.data);
}
}