Skip to content

Commit 840a1a9

Browse files
Add: BinaryTreePathsTest.java for unit testing
1 parent fc45db5 commit 840a1a9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.thealgorithms.backtracking;
2+
3+
import org.junit.jupiter.api.Test;
4+
import java.util.List;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
public class BinaryTreePathsTest {
8+
9+
@Test
10+
void testBinaryTreePathsBasic() {
11+
BinaryTreePaths.TreeNode root = new BinaryTreePaths.TreeNode(1);
12+
root.left = new BinaryTreePaths.TreeNode(2);
13+
root.right = new BinaryTreePaths.TreeNode(3);
14+
root.left.right = new BinaryTreePaths.TreeNode(5);
15+
16+
BinaryTreePaths solver = new BinaryTreePaths();
17+
List<String> result = solver.binaryTreePaths(root);
18+
19+
assertEquals(2, result.size());
20+
assertTrue(result.contains("1->2->5"));
21+
assertTrue(result.contains("1->3"));
22+
}
23+
24+
@Test
25+
void testSingleNodeTree() {
26+
BinaryTreePaths.TreeNode root = new BinaryTreePaths.TreeNode(42);
27+
28+
BinaryTreePaths solver = new BinaryTreePaths();
29+
List<String> result = solver.binaryTreePaths(root);
30+
31+
assertEquals(List.of("42"), result);
32+
}
33+
34+
@Test
35+
void testEmptyTree() {
36+
BinaryTreePaths solver = new BinaryTreePaths();
37+
List<String> result = solver.binaryTreePaths(null);
38+
39+
assertTrue(result.isEmpty());
40+
}
41+
}

0 commit comments

Comments
 (0)