forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreePathsTest.java
More file actions
43 lines (32 loc) · 1.26 KB
/
BinaryTreePathsTest.java
File metadata and controls
43 lines (32 loc) · 1.26 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
package com.thealgorithms.backtracking;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.jupiter.api.Test;
public class BinaryTreePathsTest {
@Test
void testBinaryTreePathsBasic() {
BinaryTreePaths.TreeNode root = new BinaryTreePaths.TreeNode(1);
root.left = new BinaryTreePaths.TreeNode(2);
root.right = new BinaryTreePaths.TreeNode(3);
root.left.right = new BinaryTreePaths.TreeNode(5);
BinaryTreePaths solver = new BinaryTreePaths();
List<String> result = solver.binaryTreePaths(root);
assertEquals(2, result.size());
assertTrue(result.contains("1->2->5"));
assertTrue(result.contains("1->3"));
}
@Test
void testSingleNodeTree() {
BinaryTreePaths.TreeNode root = new BinaryTreePaths.TreeNode(42);
BinaryTreePaths solver = new BinaryTreePaths();
List<String> result = solver.binaryTreePaths(root);
assertEquals(List.of("42"), result);
}
@Test
void testEmptyTree() {
BinaryTreePaths solver = new BinaryTreePaths();
List<String> result = solver.binaryTreePaths(null);
assertTrue(result.isEmpty());
}
}