Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6a871e

Browse files
testing: improve test coverageRangeInSortedArrayTest (#6395)
* testing: improve test coverage RangeInSortedArrayTest* style: fix formatting checkstyle---------Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parentfc477ee commitd6a871e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎src/test/java/com/thealgorithms/misc/RangeInSortedArrayTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,26 @@ private static Stream<Arguments> provideGetCountLessThanTestCases() {
3232
returnStream.of(Arguments.of(newint[] {1,2,3,3,4,5},3,4,"Count of elements less than existing key"),Arguments.of(newint[] {1,2,3,3,4,5},4,5,"Count of elements less than non-existing key"),Arguments.of(newint[] {1,2,2,3},5,4,"Count with all smaller elements"),
3333
Arguments.of(newint[] {2,3,4,5},1,0,"Count with no smaller elements"),Arguments.of(newint[] {},1,0,"Count in empty array"));
3434
}
35+
36+
@ParameterizedTest(name ="Edge case {index}: {3}")
37+
@MethodSource("provideEdgeCasesForSortedRange")
38+
voidtestSortedRangeEdgeCases(int[]nums,intkey,int[]expectedRange,Stringdescription) {
39+
assertArrayEquals(expectedRange,RangeInSortedArray.sortedRange(nums,key),description);
40+
}
41+
42+
privatestaticStream<Arguments>provideEdgeCasesForSortedRange() {
43+
returnStream.of(Arguments.of(newint[] {5,5,5,5,5},5,newint[] {0,4},"All elements same as key"),Arguments.of(newint[] {1,2,3,4,5},1,newint[] {0,0},"Key is first element"),Arguments.of(newint[] {1,2,3,4,5},5,newint[] {4,4},"Key is last element"),
44+
Arguments.of(newint[] {1,2,3,4,5},0,newint[] {-1, -1},"Key less than all elements"),Arguments.of(newint[] {1,2,3,4,5},6,newint[] {-1, -1},"Key greater than all elements"),
45+
Arguments.of(newint[] {1,2,2,2,3,3,3,4},3,newint[] {4,6},"Multiple occurrences spread"),Arguments.of(newint[] {2},2,newint[] {0,0},"Single element array key exists"),Arguments.of(newint[] {2},3,newint[] {-1, -1},"Single element array key missing"));
46+
}
47+
48+
@ParameterizedTest(name ="Edge case {index}: {3}")
49+
@MethodSource("provideEdgeCasesForGetCountLessThan")
50+
voidtestGetCountLessThanEdgeCases(int[]nums,intkey,intexpectedCount,Stringdescription) {
51+
assertEquals(expectedCount,RangeInSortedArray.getCountLessThan(nums,key),description);
52+
}
53+
54+
privatestaticStream<Arguments>provideEdgeCasesForGetCountLessThan() {
55+
returnStream.of(Arguments.of(newint[] {1,2,3,4,5},0,0,"Key less than all elements"),Arguments.of(newint[] {1,2,3,4,5},6,5,"Key greater than all elements"),Arguments.of(newint[] {1},0,0,"Single element greater than key"));
56+
}
3557
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp