- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathSingleElementTest.java
33 lines (28 loc) · 1.14 KB
/
SingleElementTest.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
packagecom.thealgorithms.bitmanipulation;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicfinalclassSingleElementTest {
/**
* Parameterized test to find the single non-duplicate element
* in the given arrays.
*
* @param arr the input array where every element appears twice except one
* @param expected the expected single element result
*/
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestFindSingleElement(int[] arr, intexpected) {
assertEquals(expected, SingleElement.findSingleElement(arr));
}
/**
* Provides test cases for the parameterized test.
*
* @return Stream of arguments consisting of arrays and expected results
*/
privatestaticStream<Arguments> provideTestCases() {
returnStream.of(Arguments.of(newint[] {1, 1, 2, 2, 4, 4, 3}, 3), Arguments.of(newint[] {1, 2, 2, 3, 3}, 1), Arguments.of(newint[] {10}, 10));
}
}