Skip to content

Commit 3474233

Browse files
committed
feat: junit test for radixsort
1 parent 694b75e commit 3474233

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package algorithms.sorting.radixSort;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import org.junit.Test;
5+
import java.util.Arrays;
6+
public class RadixSortTest {
7+
@Test
8+
public void test_radixSort_shouldReturnSortedArray() {
9+
int[] firstArray =
10+
new int[] {2, 3, 4, 1, 2, 5, 6, 7, 10, 15, 20, 13, 15, 1, 2,
11+
15, 12, 20, 21, 120, 11, 5, 7, 85, 30};
12+
int[] firstResult = Arrays.copyOf(firstArray, firstArray.length);
13+
RadixSort.radixSort(firstResult);
14+
15+
int[] secondArray
16+
= new int[] {9, 1, 2, 8, 7, 3, 4, 6, 5, 5, 9, 8, 7, 6, 5, 4,
17+
3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
18+
int[] secondResult =Arrays.copyOf(secondArray, secondArray.length);
19+
RadixSort.radixSort(secondResult);
20+
21+
int[] thirdArray = new int[] {};
22+
int[] thirdResult = Arrays.copyOf(thirdArray, thirdArray.length);
23+
RadixSort.radixSort(thirdResult);
24+
25+
int[] fourthArray = new int[] {1};
26+
int[] fourthResult = Arrays.copyOf(fourthArray, fourthArray.length);
27+
RadixSort.radixSort(fourthResult);
28+
29+
Arrays.sort(firstArray);
30+
Arrays.sort(secondArray);
31+
Arrays.sort(thirdArray);
32+
Arrays.sort(fourthArray);
33+
34+
assertArrayEquals(firstResult, firstArray);
35+
assertArrayEquals(secondResult, secondArray);
36+
assertArrayEquals(thirdResult, thirdArray);
37+
assertArrayEquals(fourthResult, fourthArray);
38+
}
39+
}

0 commit comments

Comments
 (0)