Repository navigation
Expand file tree
/
Copy pathBinaryTreeLevelOrderTraversal102Test.java
More file actions
61 lines (47 loc) · 1.77 KB
/
Copy pathBinaryTreeLevelOrderTraversal102Test.java
File metadata and controls
61 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.leetcode.medium;
import com.leetcode.datastructure.TreeNode;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
public class BinaryTreeLevelOrderTraversal102Test {
private BinaryTreeLevelOrderTraversal102 solution;
@BeforeEach
void setUp() {
solution = new BinaryTreeLevelOrderTraversal102();
}
@Test
void testLevelOrder_Example1() {
TreeNode root = new TreeNode(3);
root.left = new TreeNode(9);
root.right = new TreeNode(20);
root.right.left = new TreeNode(15);
root.right.right = new TreeNode(7);
List<List<Integer>> expected = Arrays.asList(
List.of(3),
Arrays.asList(9, 20),
Arrays.asList(15, 7)
);
List<List<Integer>> result = assertTimeoutPreemptively(Duration.ofMillis(100), () -> solution.levelOrder(root));
assertEquals(expected, result);
}
@Test
void testLevelOrder_Example2() {
TreeNode root = new TreeNode(1);
List<List<Integer>> expected = List.of(
List.of(1)
);
List<List<Integer>> result = assertTimeoutPreemptively(Duration.ofMillis(100), () -> solution.levelOrder(root));
assertEquals(expected, result);
}
@Test
void testLevelOrder_Example3() {
List<List<Integer>> expected = new ArrayList<>();
List<List<Integer>> result = assertTimeoutPreemptively(Duration.ofMillis(100), () -> solution.levelOrder(null));
assertEquals(expected, result);
}
}