|
3 | 3 | import com.fishercoder.common.classes.TreeNode;
|
4 | 4 | import com.fishercoder.common.utils.TreeUtils;
|
5 | 5 | import com.fishercoder.solutions._235;
|
| 6 | + |
6 | 7 | import java.util.Arrays;
|
| 8 | + |
7 | 9 | import org.junit.BeforeClass;
|
8 | 10 | import org.junit.Test;
|
9 | 11 |
|
10 | 12 | import static org.junit.Assert.assertEquals;
|
11 | 13 |
|
12 | 14 | public class _235Test {
|
13 |
| - private static _235.Solution1 solution1; |
14 |
| - private static _235.Solution2 solution2; |
15 |
| - private static TreeNode root; |
16 |
| - private static TreeNode p; |
17 |
| - private static TreeNode q; |
18 |
| - |
19 |
| - @BeforeClass |
20 |
| - public static void setup() { |
21 |
| - solution1 = new _235.Solution1(); |
22 |
| - solution2 = new _235.Solution2(); |
23 |
| - } |
24 |
| - |
25 |
| - @Test |
26 |
| - public void test1() { |
27 |
| - root = TreeUtils.constructBinaryTree(Arrays.asList(6, 2, 8, 0, 4, 7, 9, 3, 5)); |
28 |
| - TreeUtils.printBinaryTree(root); |
29 |
| - |
30 |
| - p = TreeUtils.constructBinaryTree(Arrays.asList(2, 0, 4, 3, 5)); |
31 |
| - TreeUtils.printBinaryTree(p); |
32 |
| - |
33 |
| - q = TreeUtils.constructBinaryTree(Arrays.asList(8, 7, 9)); |
34 |
| - TreeUtils.printBinaryTree(q); |
35 |
| - |
36 |
| - assertEquals(root, solution1.lowestCommonAncestor(root, p, q)); |
37 |
| - assertEquals(root, solution2.lowestCommonAncestor(root, p, q)); |
38 |
| - } |
39 |
| - |
40 |
| - @Test |
41 |
| - public void test2() { |
42 |
| - root = TreeUtils.constructBinaryTree(Arrays.asList(6, 2, 8, 0, 4, 7, 9, 3, 5)); |
43 |
| - TreeUtils.printBinaryTree(root); |
44 |
| - |
45 |
| - p = TreeUtils.constructBinaryTree(Arrays.asList(2, 0, 4, 3, 5)); |
46 |
| - TreeUtils.printBinaryTree(p); |
47 |
| - |
48 |
| - q = TreeUtils.constructBinaryTree(Arrays.asList(4)); |
49 |
| - TreeUtils.printBinaryTree(q); |
50 |
| - |
51 |
| - assertEquals(p, solution1.lowestCommonAncestor(root, p, q)); |
52 |
| - assertEquals(p, solution2.lowestCommonAncestor(root, p, q)); |
53 |
| - } |
| 15 | + private static _235.Solution1 solution1; |
| 16 | + private static TreeNode root; |
| 17 | + private static TreeNode p; |
| 18 | + private static TreeNode q; |
| 19 | + |
| 20 | + @BeforeClass |
| 21 | + public static void setup() { |
| 22 | + solution1 = new _235.Solution1(); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void test1() { |
| 27 | + root = TreeUtils.constructBinaryTree(Arrays.asList(6, 2, 8, 0, 4, 7, 9, 3, 5)); |
| 28 | + TreeUtils.printBinaryTree(root); |
| 29 | + |
| 30 | + p = TreeUtils.constructBinaryTree(Arrays.asList(2, 0, 4, 3, 5)); |
| 31 | + TreeUtils.printBinaryTree(p); |
| 32 | + |
| 33 | + q = TreeUtils.constructBinaryTree(Arrays.asList(8, 7, 9)); |
| 34 | + TreeUtils.printBinaryTree(q); |
| 35 | + |
| 36 | + assertEquals(root, solution1.lowestCommonAncestor(root, p, q)); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void test2() { |
| 41 | + root = TreeUtils.constructBinaryTree(Arrays.asList(6, 2, 8, 0, 4, 7, 9, 3, 5)); |
| 42 | + TreeUtils.printBinaryTree(root); |
| 43 | + |
| 44 | + p = TreeUtils.constructBinaryTree(Arrays.asList(2, 0, 4, 3, 5)); |
| 45 | + TreeUtils.printBinaryTree(p); |
| 46 | + |
| 47 | + q = TreeUtils.constructBinaryTree(Arrays.asList(4)); |
| 48 | + TreeUtils.printBinaryTree(q); |
| 49 | + |
| 50 | + assertEquals(p, solution1.lowestCommonAncestor(root, p, q)); |
| 51 | + } |
54 | 52 | }
|
0 commit comments