- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathLongestIncreasingSubsequenceTests.java
49 lines (42 loc) · 1.86 KB
/
LongestIncreasingSubsequenceTests.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
packagecom.thealgorithms.dynamicprogramming;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.Arrays;
importjava.util.List;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassLongestIncreasingSubsequenceTests {
@FunctionalInterface
publicinterfaceIntArrayToInt {
intapply(int[] array);
}
@ParameterizedTest
@MethodSource("testCases")
publicvoidtestLongestIncreasingSubsequence(finalintexpected, finalint[] input, finalIntArrayToIntmethod) {
assertEquals(expected, method.apply(input));
}
privatestaticStream<Arguments> testCases() {
finalObject[][] testData = {
{0, newint[] {}},
{1, newint[] {1}},
{1, newint[] {2, 2}},
{1, newint[] {3, 3, 3}},
{1, newint[] {4, 4, 4, 4}},
{1, newint[] {5, 5, 5, 5, 5}},
{2, newint[] {1, 2}},
{2, newint[] {1, 2, 2, 2, 2}},
{2, newint[] {1, 0, 2}},
{3, newint[] {1, 10, 2, 30}},
{3, newint[] {5, 8, 3, 7, 9, 1}},
{6, newint[] {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}},
{4, newint[] {10, 9, 2, 5, 3, 7, 101, 18}},
{4, newint[] {10, 10, 9, 9, 2, 2, 5, 5, 3, 3, 7, 7, 101, 101, 18, 18}},
{4, newint[] {0, 1, 0, 3, 2, 3}},
{2, newint[] {1, 1, 2, 2, 2}},
{3, newint[] {1, 1, 2, 2, 2, 3, 3, 3, 3}},
};
finalList<IntArrayToInt> methods = Arrays.asList(LongestIncreasingSubsequence::lis, LongestIncreasingSubsequence::findLISLen);
returnStream.of(testData).flatMap(input -> methods.stream().map(method -> Arguments.of(input[0], input[1], method)));
}
}