|
| 1 | +package com.thealgorithms.sorts; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.MethodSource; |
| 7 | +import java.util.stream.Stream; |
| 8 | + |
| 9 | +public class CountingSortTest { |
| 10 | + |
| 11 | + record TestCase(int[] inputArray, int[] expectedArray) { |
| 12 | + } |
| 13 | + |
| 14 | + static Stream<TestCase> provideTestCases() { |
| 15 | + return Stream.of(new TestCase(new int[] {}, new int[] {}), new TestCase(new int[] {4}, new int[] {4}), new TestCase(new int[] {6, 1, 99, 27, 15, 23, 36}, new int[] {1, 6, 15, 23, 27, 36, 99}), new TestCase(new int[] {6, 1, 27, 15, 23, 27, 36, 23}, new int[] {1, 6, 15, 23, 23, 27, 27, 36}), new TestCase(new int[] {5, 5, 5, 5, 5}, |
| 16 | + new int[] {5, 5, 5, 5, 5}), new TestCase(new int[] {1, 2, 3, 4, 5}, new int[] {1, 2, 3, 4, 5}), new TestCase(new int[] {5, 4, 3, 2, 1}, new int[] {1, 2, 3, 4, 5}), new TestCase(new int[] {3, -1, 4, 1, 5, -9}, new int[] {-9, -1, 1, 3, 4, 5}), new TestCase(new int[] {0, 0, 0, 0}, new int[] {0, 0, 0, 0}), |
| 17 | + new TestCase(new int[] {3, 3, -1, -1, 2, 2, 0, 0}, new int[] {-1, -1, 0, 0, 2, 2, 3, 3}), new TestCase(new int[] {-3, -2, -1, -5, -4}, new int[] {-5, -4, -3, -2, -1}), new TestCase(new int[] {1000, 500, 100, 50, 10, 5, 1}, new int[] {1, 5, 10, 50, 100, 500, 1000})); |
| 18 | + } |
| 19 | + |
| 20 | + @ParameterizedTest |
| 21 | + @MethodSource("provideTestCases") |
| 22 | + public void testCountingSort(TestCase testCase) { |
| 23 | + int[] outputArray = CountingSort.sort(testCase.inputArray); |
| 24 | + assertArrayEquals(testCase.expectedArray, outputArray); |
| 25 | + } |
| 26 | +} |
0 commit comments