forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvertBinaryTreeTest.java
More file actions
42 lines (32 loc) · 1.21 KB
/
InvertBinaryTreeTest.java
File metadata and controls
42 lines (32 loc) · 1.21 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
package com.thealgorithms.datastructures.trees;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
class InvertBinaryTreeTest {
@Test
void testInvertTreeNormalCase() {
BinaryTree.Node root = new BinaryTree.Node(4);
root.left = new BinaryTree.Node(2);
root.right = new BinaryTree.Node(7);
root.left.left = new BinaryTree.Node(1);
root.left.right = new BinaryTree.Node(3);
BinaryTree.Node inverted = InvertBinaryTree.invertTree(root);
assertEquals(7, inverted.left.data);
assertEquals(2, inverted.right.data);
assertEquals(3, inverted.right.left.data);
assertEquals(1, inverted.right.right.data);
}
@Test
void testInvertTreeSingleNode() {
BinaryTree.Node root = new BinaryTree.Node(1);
BinaryTree.Node inverted = InvertBinaryTree.invertTree(root);
assertEquals(1, inverted.data);
assertNull(inverted.left);
assertNull(inverted.right);
}
@Test
void testInvertTreeNull() {
BinaryTree.Node inverted = InvertBinaryTree.invertTree(null);
assertNull(inverted);
}
}