-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiameterOfBinaryTreeTest.java
55 lines (53 loc) · 1.77 KB
/
DiameterOfBinaryTreeTest.java
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
import org.example.helpers.TreeNode;
import org.example.problems.diameter_of_binary_tree.Solution;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
public class DiameterOfBinaryTreeTest {
private static Stream<Arguments> provideCases() {
return Stream.of(
Arguments.of(
new TreeNode(1, new TreeNode(2, new TreeNode(4), new TreeNode(5)), new TreeNode(3)),
3
),
Arguments.of(
new TreeNode(1, new TreeNode(2), null),
1
),
Arguments.of(
new TreeNode(
1,
new TreeNode(
2,
new TreeNode(
3,
new TreeNode(
4,
new TreeNode(5),
null
),
null),
new TreeNode(
6,
null,
new TreeNode(
7,
new TreeNode(8),
null
)
)
),
null),
6
)
);
}
@ParameterizedTest
@MethodSource("provideCases")
public void test(TreeNode root, int diameter) {
Solution s = new Solution();
Assertions.assertSame(diameter, s.diameterOfBinaryTree(root));
}
}