MCPcopy Create free account
hub / github.com/RealTimeGenomics/rtg-tools / QuickSortTest

Class QuickSortTest

src/test/java/com/rtg/util/QuickSortTest.java:39–86  ·  view source on GitHub ↗

Test Class

Source from the content-addressed store, hash-verified

37 * Test Class
38 */
39public class QuickSortTest extends TestCase {
40
41
42 public void testSort() {
43 final PortableRandom pr = new PortableRandom();
44 final long seed = pr.getSeed();
45 try {
46 final int[] unsorted = new int[100000];
47 for (int i = 0; i < unsorted.length; ++i) {
48 unsorted[i] = Math.abs(pr.nextInt());
49 }
50 final int[] unsorted2 = Arrays.copyOf(unsorted, unsorted.length);
51 final QuickSort.SortProxy proxy = new QuickSort.SortProxy() {
52
53 @Override
54 public int compare(long index1, long index2) {
55 return Integer.compare(unsorted[(int) index1], unsorted[(int) index2]);
56 }
57
58 @Override
59 public void swap(long index1, long index2) {
60 final int temp = unsorted[(int) index1];
61 unsorted[(int) index1] = unsorted[(int) index2];
62 unsorted[(int) index2] = temp;
63 }
64
65 @Override
66 public long length() {
67 return unsorted.length;
68 }
69
70 @Override
71 public String toString() {
72 return Arrays.toString(unsorted);
73
74 }
75
76 };
77 QuickSort.sort(proxy);
78 Arrays.sort(unsorted2);
79 assertTrue(Arrays.equals(unsorted2, unsorted));
80 assertTrue(QuickSort.isSorted(proxy));
81 } catch (RuntimeException e) {
82 throw new RuntimeException("Seed: " + seed + " has discovered an error", e);
83 }
84 }
85
86}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected