- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathThreeSumProblemTest.java
52 lines (41 loc) · 2.09 KB
/
ThreeSumProblemTest.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
packagecom.thealgorithms.misc;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.List;
importjava.util.stream.Stream;
importorg.junit.jupiter.api.BeforeEach;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassThreeSumProblemTest {
privateThreeSumProblemtsp;
@BeforeEach
publicvoidsetup() {
tsp = newThreeSumProblem();
}
@ParameterizedTest
@MethodSource("bruteForceTestProvider")
publicvoidtestBruteForce(int[] nums, inttarget, List<List<Integer>> expected) {
assertEquals(expected, tsp.bruteForce(nums, target));
}
@ParameterizedTest
@MethodSource("twoPointerTestProvider")
publicvoidtestTwoPointer(int[] nums, inttarget, List<List<Integer>> expected) {
assertEquals(expected, tsp.twoPointer(nums, target));
}
@ParameterizedTest
@MethodSource("hashMapTestProvider")
publicvoidtestHashMap(int[] nums, inttarget, List<List<Integer>> expected) {
assertEquals(expected, tsp.hashMap(nums, target));
}
privatestaticStream<Arguments> bruteForceTestProvider() {
returnStream.of(Arguments.of(newint[] {1, 2, -3, 4, -2, -1}, 0, Arrays.asList(Arrays.asList(-3, 1, 2), Arrays.asList(-3, -1, 4))), Arguments.of(newint[] {1, 2, 3, 4, 5}, 50, newArrayList<>()));
}
privatestaticStream<Arguments> twoPointerTestProvider() {
returnStream.of(Arguments.of(newint[] {0, -1, 2, -3, 1}, 0, Arrays.asList(Arrays.asList(-3, 1, 2), Arrays.asList(-1, 0, 1))), Arguments.of(newint[] {-5, -4, -3, -2, -1}, -10, Arrays.asList(Arrays.asList(-5, -4, -1), Arrays.asList(-5, -3, -2))));
}
privatestaticStream<Arguments> hashMapTestProvider() {
returnStream.of(Arguments.of(newint[] {1, 2, -1, -4, 3, 0}, 2, Arrays.asList(Arrays.asList(-1, 0, 3), Arrays.asList(-1, 1, 2))), Arguments.of(newint[] {5, 7, 9, 11}, 10, newArrayList<>()), Arguments.of(newint[] {}, 0, newArrayList<>()));
}
}