Skip to content

Commit f727cb0

Browse files
refactor 145
1 parent 2a37bb0 commit f727cb0

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder;
22

33
import com.fishercoder.common.classes.TreeNode;
4+
import com.fishercoder.common.utils.CommonUtils;
5+
import com.fishercoder.common.utils.TreeUtils;
46
import com.fishercoder.solutions._145;
57
import org.junit.BeforeClass;
68
import org.junit.Test;
@@ -12,24 +14,25 @@
1214
import static org.junit.Assert.assertEquals;
1315

1416
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;
1921

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+
}
2527

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+
}
3538
}

0 commit comments

Comments
 (0)