File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
main/java/com/thealgorithms/sorts
test/java/com/thealgorithms/sorts Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 22
33import 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
78class 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}
You can’t perform that action at this time.
0 commit comments