forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleElementTest.java
More file actions
33 lines (28 loc) · 1.14 KB
/
SingleElementTest.java
File metadata and controls
33 lines (28 loc) · 1.14 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
package com.thealgorithms.bitmanipulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
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 final class SingleElementTest {
/**
* 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")
void testFindSingleElement(int[] arr, int expected) {
assertEquals(expected, SingleElement.findSingleElement(arr));
}
/**
* Provides test cases for the parameterized test.
*
* @return Stream of arguments consisting of arrays and expected results
*/
private static Stream<Arguments> provideTestCases() {
return Stream.of(Arguments.of(new int[] {1, 1, 2, 2, 4, 4, 3}, 3), Arguments.of(new int[] {1, 2, 2, 3, 3}, 1), Arguments.of(new int[] {10}, 10));
}
}