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