Skip to content

Commit 647a5a0

Browse files
Add test case for null input in DarkSortTest
1 parent 1826719 commit 647a5a0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/com/thealgorithms/sorts/DarkSort.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DarkSort implements SortAlgorithm {
1919
* @return sorted array
2020
*/
2121
@Override
22+
2223
public <T extends Comparable<T>> T[] sort(T[] unsorted) {
2324
if (unsorted == null || unsorted.length <= 1) {
2425
return unsorted;

src/test/java/com/thealgorithms/sorts/DarkSortTest.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import org.junit.jupiter.api.Test;
44

5-
import static org.junit.jupiter.api.Assertions.*;
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
6+
import static org.junit.jupiter.api.Assertions.assertNull;
67

78
class DarkSortTest {
89

@@ -60,4 +61,15 @@ void testAlreadySortedArray() {
6061

6162
assertArrayEquals(expected, sorted);
6263
}
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+
6375
}

0 commit comments

Comments
 (0)