- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInRotatedSortedArrayTest.java
More file actions
Latest commit
48 lines (41 loc) · 1.72 KB
/
Copy pathSearchInRotatedSortedArrayTest.java
File metadata and controls
48 lines (41 loc) · 1.72 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
37
38
39
40
41
42
43
44
45
46
47
48
importorg.example.problems.search_in_rotated_sorted_array.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.stream.Stream;
publicclassSearchInRotatedSortedArrayTest {
privatestaticStream<Arguments> provideCases() {
returnStream.of(
Arguments.of(newint[]{5, 1, 3}, 1, 1),
Arguments.of(newint[]{1, 3, 5}, 3, 1),
Arguments.of(newint[]{1, 3}, 0, -1),
Arguments.of(newint[]{4, 5, 6, 7, 8, 1, 2, 3}, 8, 4),
Arguments.of(newint[]{4, 5, 6, 7, 0, 1, 2}, 0, 4),
Arguments.of(newint[]{4, 5, 6, 7, 0, 1, 2}, 2, 6),
Arguments.of(newint[]{4, 5, 6, 7, 0, 1, 2}, 4, 0),
Arguments.of(newint[]{4, 5, 6, 7, 0, 1, 2}, 3, -1),
Arguments.of(newint[]{1}, 0, -1)
);
}
@ParameterizedTest
@MethodSource("provideCases")
publicvoidtest(int[] nums, inttarget, intexpected) {
Solutions = newSolution();
Assertions.assertSame(expected, s.search(nums, target));
}
privatestaticStream<Arguments> provideCasesForShiftSearch() {
returnStream.of(
Arguments.of(newint[]{4, 5, 6, 7, 8, 1, 2, 3}, 4),
Arguments.of(newint[]{4, 5, 6, 7, 0, 1, 2}, 3),
Arguments.of(newint[]{5, 1, 3}, 0),
Arguments.of(newint[]{1, 3, 5}, -1)
);
}
@ParameterizedTest
@MethodSource("provideCasesForShiftSearch")
publicvoidtestShift(int[] nums, intexpected) {
Solutions = newSolution();
Assertions.assertSame(expected, s.getShiftKey(nums));
}
}