|
| 1 | +package com.thealgorithms.sorts; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +class DarkSortTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + void testSortWithIntegers() { |
| 12 | + Integer[] unsorted = {5, 3, 8, 6, 2, 7, 4, 1}; |
| 13 | + Integer[] expected = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 14 | + |
| 15 | + DarkSort darkSort = new DarkSort(); |
| 16 | + Integer[] sorted = darkSort.sort(unsorted); |
| 17 | + |
| 18 | + assertArrayEquals(expected, sorted); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + void testEmptyArray() { |
| 23 | + Integer[] unsorted = {}; |
| 24 | + Integer[] expected = {}; |
| 25 | + |
| 26 | + DarkSort darkSort = new DarkSort(); |
| 27 | + Integer[] sorted = darkSort.sort(unsorted); |
| 28 | + |
| 29 | + assertArrayEquals(expected, sorted); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void testSingleElementArray() { |
| 34 | + Integer[] unsorted = {42}; |
| 35 | + Integer[] expected = {42}; |
| 36 | + |
| 37 | + DarkSort darkSort = new DarkSort(); |
| 38 | + Integer[] sorted = darkSort.sort(unsorted); |
| 39 | + |
| 40 | + assertArrayEquals(expected, sorted); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void testAlreadySortedArray() { |
| 45 | + Integer[] unsorted = {1, 2, 3, 4, 5}; |
| 46 | + Integer[] expected = {1, 2, 3, 4, 5}; |
| 47 | + |
| 48 | + DarkSort darkSort = new DarkSort(); |
| 49 | + Integer[] sorted = darkSort.sort(unsorted); |
| 50 | + |
| 51 | + assertArrayEquals(expected, sorted); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testDuplicateElementsArray() { |
| 56 | + Integer[] unsorted = {4, 2, 7, 2, 1, 4}; |
| 57 | + Integer[] expected = {1, 2, 2, 4, 4, 7}; |
| 58 | + |
| 59 | + DarkSort darkSort = new DarkSort(); |
| 60 | + Integer[] sorted = darkSort.sort(unsorted); |
| 61 | + |
| 62 | + assertArrayEquals(expected, sorted); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + void testNullArray() { |
| 67 | + Integer[] unsorted = null; |
| 68 | + |
| 69 | + DarkSort darkSort = new DarkSort(); |
| 70 | + Integer[] sorted = darkSort.sort(unsorted); |
| 71 | + |
| 72 | + assertNull(sorted, "Sorting a null array should return null"); |
| 73 | + } |
| 74 | +} |
0 commit comments