@Test
 public void testRandom() {
   List<String> data = Tests.generateData(10000, 100);
   String[] arr = data.toArray(new String[data.size()]);
   DualPivotQuicksort.sort(arr);
   assertTrue(Tests.isSorted(arr));
 }
  @Test
  public void testInsertionSort() throws Exception {
    long[] array = new long[] {5, 4, 3, 2, 1};
    DualPivotQuicksort.sort(array);

    assertSorted(array);
  }
 @Test
 public void testRepeated() {
   String[] arr = new String[10000];
   final String STR =
       "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
           + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
   Arrays.fill(arr, STR);
   DualPivotQuicksort.sort(arr);
   assertTrue(Tests.isRepeated(arr, STR));
 }
  @Test
  public void testDPQuicksort() throws Exception {
    long[] array = new long[154];
    for (int i = 0; i < 154; i++) {
      array[i] = 154 - i;
    }
    DualPivotQuicksort.sort(array);

    assertSorted(array);
  }
 @Test
 public void testDictCalls() {
   try {
     List<String> data = Tests.loadData("dictcalls.gz", true);
     String[] arr = data.toArray(new String[data.size()]);
     DualPivotQuicksort.sort(arr);
     assertTrue(Tests.isSorted(arr));
   } catch (IOException ioe) {
     fail(ioe.toString());
   }
 }
 @Test
 public void testSorted() {
   try {
     List<String> data = Tests.loadData();
     Collections.sort(data);
     String[] arr = data.toArray(new String[data.size()]);
     DualPivotQuicksort.sort(arr);
     assertTrue(Tests.isSorted(arr));
   } catch (IOException ioe) {
     fail(ioe.toString());
   }
 }
 @Test
 public void testRandomArrays() throws Exception {
   Random random = new Random();
   for (int i = 0; i < 1000; i++) {
     long[] a = new long[1000];
     for (int j = 0; j < a.length; j++) {
       a[j] = random.nextLong();
     }
     DualPivotQuicksort.sort(a);
     assertSorted(a);
   }
 }
  @Test
  public void testCaseWithManyEqualPivots() throws Exception {
    long[] array = new long[154];
    for (int i = 0; i < 154; i++) {
      array[i] = 154;
    }
    array[152] = 152;
    array[31] = 31;
    array[54] = 54;
    array[12] = 12;
    DualPivotQuicksort.sort(array);

    assertSorted(array);
  }
 @Test
 public void testRepeatedCycle() {
   String[] strs = new String[100];
   String seed =
       "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
           + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
   for (int i = 0, l = 1; i < strs.length; i++, l++) {
     strs[i] = seed.substring(0, l);
   }
   List<String> list = new ArrayList<String>();
   for (int c = 10000, i = 0; c > 0; i++, c--) {
     list.add(strs[i % strs.length]);
   }
   String[] arr = list.toArray(new String[list.size()]);
   DualPivotQuicksort.sort(arr);
   assertTrue(Tests.isSorted(arr));
 }
 @Test
 public void testArguments() {
   DualPivotQuicksort.sort((String[]) null);
   DualPivotQuicksort.sort(new String[0]);
   String[] arr = new String[] {"a"};
   DualPivotQuicksort.sort(arr);
   arr = new String[] {"b", "a"};
   DualPivotQuicksort.sort(arr);
   assertTrue(Tests.isSorted(arr));
   arr = new String[] {"c", "b", "a"};
   DualPivotQuicksort.sort(arr);
   assertTrue(Tests.isSorted(arr));
   // test with all empty input
   arr = new String[] {"", "", "", "", "", "", "", "", "", ""};
   DualPivotQuicksort.sort(arr);
   for (String s : arr) {
     assertEquals("", s);
   }
   // test with peculiar input
   arr = new String[] {"z", "m", "", "a", "d", "tt", "tt", "tt", "foo", "bar"};
   DualPivotQuicksort.sort(arr);
   assertTrue("peculiar input not sorted", Tests.isSorted(arr));
 }