-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathSlidingWindowMaximumTest.java
50 lines (36 loc) · 1.94 KB
/
SlidingWindowMaximumTest.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
package com.thealgorithms.datastructures.queues;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class SlidingWindowMaximumTest {
@ParameterizedTest
@MethodSource("provideTestCases")
public void testMaxSlidingWindow(int[] nums, int k, int[] expected) {
assertArrayEquals(expected, SlidingWindowMaximum.maxSlidingWindow(nums, k));
}
private static Stream<Arguments> provideTestCases() {
return Stream.of(
// Test case 1: Example from the problem statement
Arguments.of(new int[] {1, 3, -1, -3, 5, 3, 6, 7}, 3, new int[] {3, 3, 5, 5, 6, 7}),
// Test case 2: All elements are the same
Arguments.of(new int[] {4, 4, 4, 4, 4}, 2, new int[] {4, 4, 4, 4}),
// Test case 3: Window size equals the array length
Arguments.of(new int[] {2, 1, 5, 3, 6}, 5, new int[] {6}),
// Test case 4: Single element array with window size 1
Arguments.of(new int[] {7}, 1, new int[] {7}),
// Test case 5: Window size larger than the array length
Arguments.of(new int[] {1, 2, 3}, 4, new int[] {}),
// Test case 6: Decreasing sequence
Arguments.of(new int[] {9, 8, 7, 6, 5, 4}, 3, new int[] {9, 8, 7, 6}),
// Test case 7: Increasing sequence
Arguments.of(new int[] {1, 2, 3, 4, 5}, 2, new int[] {2, 3, 4, 5}),
// Test case 8: k is zero
Arguments.of(new int[] {1, 3, -1, -3, 5, 3, 6, 7}, 0, new int[] {}),
// Test case 9: Array with negative numbers
Arguments.of(new int[] {-4, -2, -5, -1, -3}, 3, new int[] {-2, -1, -1}),
// Test case 10: Empty array
Arguments.of(new int[] {}, 3, new int[] {}));
}
}