- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreeLevelOrderTraversalTest.java
More file actions
Latest commit
46 lines (43 loc) · 1.45 KB
/
Copy pathBinaryTreeLevelOrderTraversalTest.java
File metadata and controls
46 lines (43 loc) · 1.45 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
importorg.example.helpers.TreeNode;
importorg.example.problems.binary_tree_level_order_traversal.Solution;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
importjava.util.ArrayList;
importjava.util.stream.Stream;
publicclassBinaryTreeLevelOrderTraversalTest {
privatestaticStream<Arguments> provideCases() {
returnStream.of(
Arguments.of(
newTreeNode(
3,
newTreeNode(9),
newTreeNode(20, newTreeNode(15), newTreeNode(7))),
newint[][]{{3},{9,20},{15,7}}
),
Arguments.of(
newTreeNode(1),
newint[][]{{1}}
),
Arguments.of(
null,
newint[][]{}
)
);
}
@ParameterizedTest
@MethodSource("provideCases")
publicvoidtest(TreeNodenode, int[][] expected) {
Solutions = newSolution();
ArrayList<ArrayList<Integer>> expectedList = newArrayList<>();
for (int[] ar: expected) {
ArrayList<Integer> sublist = newArrayList<>();
for (inti: ar) {
sublist.add(i);
}
expectedList.add(sublist);
}
Assertions.assertEquals(expectedList, s.levelOrder(node));
}
}