|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 |
|
5 |
| -import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.Arguments; |
| 7 | +import org.junit.jupiter.params.provider.MethodSource; |
6 | 8 |
|
7 | 9 | /**
|
8 | 10 | * Test case for Non Repeating Number Finder
|
| 11 | + * This test class validates the functionality of the |
| 12 | + * NonRepeatingNumberFinder by checking various scenarios. |
| 13 | + * |
9 | 14 | * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
10 | 15 | */
|
11 |
| - |
12 | 16 | class NonRepeatingNumberFinderTest {
|
13 | 17 |
|
14 |
| - @Test |
15 |
| - void testNonRepeatingNumberFinder() { |
16 |
| - int[] arr = {1, 2, 1, 2, 6}; |
17 |
| - assertEquals(6, NonRepeatingNumberFinder.findNonRepeatingNumber(arr)); |
18 |
| - int[] arr1 = {1, 2, 1, 2}; |
19 |
| - assertEquals(0, NonRepeatingNumberFinder.findNonRepeatingNumber(arr1)); |
20 |
| - int[] arr2 = {12}; |
21 |
| - assertEquals(12, NonRepeatingNumberFinder.findNonRepeatingNumber(arr2)); |
| 18 | + @ParameterizedTest |
| 19 | + @MethodSource("testCases") |
| 20 | + void testNonRepeatingNumberFinder(int[] arr, int expected) { |
| 21 | + assertEquals(expected, NonRepeatingNumberFinder.findNonRepeatingNumber(arr)); |
| 22 | + } |
| 23 | + |
| 24 | + private static Arguments[] testCases() { |
| 25 | + return new Arguments[] { |
| 26 | + Arguments.of(new int[] {1, 2, 1, 2, 6}, 6), Arguments.of(new int[] {1, 2, 1, 2}, 0), // All numbers repeat |
| 27 | + Arguments.of(new int[] {12}, 12), // Single non-repeating number |
| 28 | + Arguments.of(new int[] {3, 5, 3, 4, 4}, 5), // More complex case |
| 29 | + Arguments.of(new int[] {7, 8, 7, 9, 8, 10, 10}, 9), // Non-repeating in the middle |
| 30 | + Arguments.of(new int[] {0, -1, 0, -1, 2}, 2), // Testing with negative numbers |
| 31 | + Arguments.of(new int[] {Integer.MAX_VALUE, 1, 1}, Integer.MAX_VALUE), // Edge case with max int |
| 32 | + Arguments.of(new int[] {2, 2, 3, 3, 4, 5, 4}, 5), // Mixed duplicates |
| 33 | + Arguments.of(new int[] {}, 0) // Edge case: empty array (should be handled as per design) |
| 34 | + }; |
22 | 35 | }
|
23 | 36 | }
|
0 commit comments