@Test public void testSortingRandom_indexes() { int offset = 10; for( int a = 0; a < 20; a++ ) { int[] normal = BenchMarkSort.createRandom_S32(rand,20); int[] original = normal.clone(); int[] withIndexes = new int[offset+normal.length];; int[] indexes = new int[ withIndexes.length ]; System.arraycopy(normal,0,withIndexes,offset,normal.length); QuickSort_S32 sorter = new QuickSort_S32(); sorter.sort(normal,normal.length); sorter.sort(withIndexes,offset,normal.length,indexes); for( int i = 0; i < normal.length; i++ ) { // make sure the original hasn't been modified assertEquals(original[i],withIndexes[i+offset], UtilEjml.TEST_F64); // see if it produced the same results as the normal one assertEquals(normal[i],withIndexes[indexes[i]],UtilEjml.TEST_F64); } } } }
@Test public void testSortingRandom() { int[] ret = BenchMarkSort.createRandom_S32(rand,200); int preTotal = sum(ret); QuickSort_S32 sorter = new QuickSort_S32(); sorter.sort(ret,ret.length); int postTotal = sum(ret); // make sure it didn't modify the list, in an unexpected way assertEquals(preTotal,postTotal,1e-8); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }