|
1 | 1 | package com.fishercoder;
|
2 | 2 |
|
3 | 3 | import com.fishercoder.common.classes.TreeNode;
|
| 4 | +import com.fishercoder.common.utils.CommonUtils; |
| 5 | +import com.fishercoder.common.utils.TreeUtils; |
4 | 6 | import com.fishercoder.solutions._145;
|
5 | 7 | import org.junit.BeforeClass;
|
6 | 8 | import org.junit.Test;
|
|
12 | 14 | import static org.junit.Assert.assertEquals;
|
13 | 15 |
|
14 | 16 | public class _145Test {
|
15 |
| - private static _145.Solution1 solution1; |
16 |
| - private static _145.Solution2 solution2; |
17 |
| - private static TreeNode root; |
18 |
| - private static List<Integer> expected; |
| 17 | + private static _145.Solution1 solution1; |
| 18 | + private static _145.Solution2 solution2; |
| 19 | + private static TreeNode root; |
| 20 | + private static List<Integer> expected; |
19 | 21 |
|
20 |
| - @BeforeClass |
21 |
| - public static void setup() { |
22 |
| - solution1 = new _145.Solution1(); |
23 |
| - solution2 = new _145.Solution2(); |
24 |
| - } |
| 22 | + @BeforeClass |
| 23 | + public static void setup() { |
| 24 | + solution1 = new _145.Solution1(); |
| 25 | + solution2 = new _145.Solution2(); |
| 26 | + } |
25 | 27 |
|
26 |
| - @Test |
27 |
| - public void test1() { |
28 |
| - root = new TreeNode(1); |
29 |
| - root.left = new TreeNode(2); |
30 |
| - root.right = new TreeNode(3); |
31 |
| - expected = new ArrayList<>(Arrays.asList(2, 3, 1)); |
32 |
| - assertEquals(expected, solution1.postorderTraversal(root)); |
33 |
| - assertEquals(expected, solution2.postorderTraversal(root)); |
34 |
| - } |
| 28 | + @Test |
| 29 | + public void test1() { |
| 30 | + root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3, 4, null, 5, 6, null, 7, null, null, null, null, 8, 9)); |
| 31 | + TreeUtils.printBinaryTree(root); |
| 32 | + CommonUtils.printList(solution1.postorderTraversal(root)); |
| 33 | + CommonUtils.printList(solution2.postorderTraversal(root)); |
| 34 | + expected = new ArrayList<>(Arrays.asList(8, 9, 7, 4, 2, 5, 6, 3, 1)); |
| 35 | + assertEquals(expected, solution1.postorderTraversal(root)); |
| 36 | + assertEquals(expected, solution2.postorderTraversal(root)); |
| 37 | + } |
35 | 38 | }
|
0 commit comments