public CountingSort(int minValue, int maxValue) { setRange(minValue,maxValue); }
@Test public void sort_inplace() { int a[] = new int[]{66,4,2,9,5,4,5,72,20,4,56,94,53,2,55,5,5,5,5,5,7,89,4,3,2}; int copy[] = a.clone(); Arrays.sort(copy); CountingSort alg = new CountingSort(0,100); alg.sort(a,0,a.length); for( int i = 0; i < a.length; i++ ) { assertEquals(copy[i], a[i]); } }
@Test public void sortIndex() { int a[] = new int[]{123,66,4,2,9,5,4,5,72,20,4,56,94,53,2,55,5,5,5,5,5,7,89,4,3,2}; int indexes[] = new int[a.length-1]; int copy[] = a.clone(); Arrays.sort(copy,1,a.length); CountingSort alg = new CountingSort(0,100); alg.sortIndex(a, 1, indexes.length, indexes); for( int i = 0; i < indexes.length; i++ ) { assertEquals(copy[i+1], a[indexes[i]]); } } }
@Test public void sort_in_out() { int a[] = new int[]{66,4,2,9,5,4,5,72,20,4,56,94,53,2,55,5,5,5,5,5,7,89,4,3,2}; int b[] = new int[a.length]; int copy[] = a.clone(); Arrays.sort(copy); CountingSort alg = new CountingSort(0,100); alg.sort(a,0,b,0,a.length); for( int i = 0; i < a.length; i++ ) { assertEquals(copy[i], b[i]); } }
public CountingSort(int minValue, int maxValue) { setRange(minValue,maxValue); }