File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
src/test/java/com/thealgorithms/backtracking Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments