package com.logntw.eva.sort; import java.util.Arrays; import java.util.Comparator; import junit.framework.Assert; import org.junit.Test; public class SortThatFirstExample { private final static Integer[] DATA = new Integer[] { 71227,98228,54930,20714,89524, 90584,60890,81227,79199,77893, 56307,87751,64345,89181,39535, 51032,20430,35697,23129,60004, 40419,98562,91508,78504,59604, 72939,86801,65671,56251,82943, 33783,38073,18636,75911,73376, 40635,80909,83294,58487,20199, 68609,38687,90465,89168,19415, 95444,64276,51914,96299,78463, 95009,94056,23396,75571,76706, 29050,34859,11851,49165,86506, 18806,27162,71554,51170,70173, 42112,44986,12791,98933,35510, 27661,22880,57217,24343,70518, 85539,78964,55031,50893,43795, 95641,88476,30036,47695,40973, 25722,17840,74927,64111,52049, 88703,35316,89837,33919,89528, 70018,48226,29540,33903,58420, 77071,45227,52765,65037,20888, 79850,53348,24363,16738,63649, 76694,29383,81690,84967,96859, 27705,84301,87945,12060,47373, 49225,42661,67741,64066,12896, 98098,34418,79970,61311,26290, 52478,76837,47091,95370,67066, 13412,31257,21760,82920,60766, 24911,79944,98189,36267,45435, 57317,13535,84409,40588,96614, 29836,83516,71748,16393,83473, 67991,88874,48432,54000,85564, 84935,73989,21322,68652,53231, 40504,57056,92368,49565,73122, 74164,16492,98090,81849,44641, 61477,71403,58254,85632,35867, 24626,24565,56121,29307,77037, 52529,71192,31294,36075,65275, 90626,73677,95255,55426,41171, 12059,92218,35684,43169,80471, 93555,45994,18085,90438,31058, 64340,98701,27892,37284,12119, 41319,93493,31675,42955,47760, 85403,55695,82609,40318,46598, 40402,25646,24047,82974,13653, 78972,67951,12579,84040,71896, 39478,69104,15240,42555,91856, 79244,62218,22231,70697,24731, 44767,33092,80286,64269,45184, 31663,60786,95072,96528,55564, 80893,94034,95921,80539,84342, 64687,81688,72152,79779,48010, }; private final static Comparator<Integer> COMPARATOR = new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }; @Test public void testSortHelper3() throws Exception { Integer[] data1 = DATA.clone(); Arrays.sort(data1, COMPARATOR); final Integer[] data2 = DATA.clone(); SortHelper.partialSort(data2, COMPARATOR, 0, 16); final Integer[] data3 = DATA.clone(); SortEventListener LISTENER = new SortEventListener() { @Override public void onRangeSorted(int sortedStart, int sortedEnd) { Assert.assertTrue(Arrays.equals(data2, data3)); } @Override public void onSortCompleted(int arrayStart, int arrayEnd) { } }; SortHelper.sort(LISTENER, data3, COMPARATOR, 0, 16); Assert.assertTrue(Arrays.equals(data1, data3)); } }