- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3sumTest.java
More file actions
Latest commit
36 lines (30 loc) · 1.13 KB
/
Copy pathProblem3sumTest.java
File metadata and controls
36 lines (30 loc) · 1.13 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
importorg.example.problems._3sum.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.Arrays;
importjava.util.List;
importjava.util.stream.Stream;
publicclassProblem3sumTest {
privatestaticStream<Arguments> provideCases() {
returnStream.of(
Arguments.of(
newint[]{-1, 0, 1, 2, -1, -4},
newint[][]{{-1, -1, 2}, {-1, 0, 1}}
),
Arguments.of(newint[]{0, 1, 1}, newint[][]{}),
Arguments.of(newint[]{0, 0, 0}, newint[][]{{0, 0, 0}})
);
}
@ParameterizedTest
@MethodSource("provideCases")
publicvoidtest(int[] nums, int[][] expected) {
Solutions = newSolution();
List<List<Integer>> actual = s.threeSum(nums);
int[][] converted = actual.stream()
.map(list -> list.stream().mapToInt(i -> i).toArray())
.toArray(int[][]::new);
Assertions.assertTrue(Arrays.deepEquals(expected, converted));
}
}