|
| 1 | +package com.thealgorithms.sorts; |
| 2 | +// author: Vraj Prajapati @Rosander0 |
| 3 | + |
| 4 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +public class LibrarySortTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + public void testBasicSort() { |
| 13 | + assertArrayEquals(new int[] {1, 2, 3, 4, 5}, LibrarySort.sort(new int[] {5, 3, 1, 4, 2})); |
| 14 | + } |
| 15 | + |
| 16 | + @Test |
| 17 | + public void testAlreadySorted() { |
| 18 | + assertArrayEquals(new int[] {1, 2, 3, 4, 5}, LibrarySort.sort(new int[] {1, 2, 3, 4, 5})); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testReverseSorted() { |
| 23 | + assertArrayEquals(new int[] {1, 2, 3, 4, 5}, LibrarySort.sort(new int[] {5, 4, 3, 2, 1})); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testDuplicates() { |
| 28 | + assertArrayEquals(new int[] {1, 2, 2, 3, 3}, LibrarySort.sort(new int[] {3, 2, 1, 3, 2})); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testSingleElement() { |
| 33 | + assertArrayEquals(new int[] {1}, LibrarySort.sort(new int[] {1})); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testEmptyArray() { |
| 38 | + assertArrayEquals(new int[] {}, LibrarySort.sort(new int[] {})); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testNullArray() { |
| 43 | + assertThrows(IllegalArgumentException.class, () -> LibrarySort.sort(null)); |
| 44 | + } |
| 45 | +} |
0 commit comments