|
3 | 3 | import com.fishercoder.common.classes.TreeNode;
|
4 | 4 | import com.fishercoder.common.utils.TreeUtils;
|
5 | 5 | import com.fishercoder.solutions._1676;
|
| 6 | +import org.junit.BeforeClass; |
6 | 7 | import org.junit.Test;
|
7 | 8 |
|
8 | 9 | import java.util.Arrays;
|
|
11 | 12 |
|
12 | 13 | public class _1676Test {
|
13 | 14 | private static _1676.Solution1 solution1;
|
| 15 | + private static _1676.Solution2 solution2; |
| 16 | + |
| 17 | + @BeforeClass |
| 18 | + public static void setup() { |
| 19 | + solution1 = new _1676.Solution1(); |
| 20 | + solution2 = new _1676.Solution2(); |
| 21 | + } |
14 | 22 |
|
15 | 23 | @Test
|
16 | 24 | public void test1() {
|
17 |
| - solution1 = new _1676.Solution1(); |
18 | 25 | TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4));
|
| 26 | + TreeUtils.printBinaryTree(root); |
19 | 27 | TreeNode node1 = TreeUtils.constructBinaryTree(Arrays.asList(4));
|
20 | 28 | TreeNode node2 = TreeUtils.constructBinaryTree(Arrays.asList(7));
|
21 | 29 | TreeNode[] nodes = new TreeNode[]{node1, node2};
|
22 |
| - TreeNode lca = TreeUtils.constructBinaryTree(Arrays.asList(2, 7, 4)); |
23 |
| - assertEquals(lca, solution1.lowestCommonAncestor(root, nodes)); |
| 30 | + TreeNode expected = TreeUtils.constructBinaryTree(Arrays.asList(2, 7, 4)); |
| 31 | + assertEquals(expected, solution1.lowestCommonAncestor(root, nodes)); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void test2() { |
| 36 | + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4)); |
| 37 | + TreeUtils.printBinaryTree(root); |
| 38 | + TreeNode node1 = TreeUtils.constructBinaryTree(Arrays.asList(1, 0, 8)); |
| 39 | + TreeNode[] nodes = new TreeNode[]{node1}; |
| 40 | + TreeNode expected = TreeUtils.constructBinaryTree(Arrays.asList(1, 0, 8)); |
| 41 | + assertEquals(expected, solution1.lowestCommonAncestor(root, nodes)); |
| 42 | + assertEquals(expected, solution2.lowestCommonAncestor(root, nodes)); |
24 | 43 | }
|
25 | 44 |
|
26 | 45 | }
|
0 commit comments