public EllipseClustersIntoAsymmetricGrid() { sorter = new QuickSortComparator<>(new Comparator<Edge>() { @Override public int compare(Edge o1, Edge o2) { if (o1.angle < o2.angle) return -1; else if (o1.angle > o2.angle) return 1; else return 0; } }); }
@Test public void testSortingRandom() { Double[] ret = createRandom(rand, 200); double preTotal = sum(ret); QuickSortComparator<Double> sorter = new QuickSortComparator<Double>(comparator); 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-8); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }
@Test public void testSortingRandom_indexes() { for( int a = 0; a < 20; a++ ) { Double[] normal = createRandom(rand,20); Double[] original = normal.clone(); Double[] withIndexes = normal.clone(); int[] indexes = new int[ normal.length ]; QuickSortComparator<Double> sorter = new QuickSortComparator<Double>(comparator); 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],withIndexes[i],1e-8); // see if it produced the same results as the normal one assertEquals(normal[i],withIndexes[indexes[i]],1e-8); } } }