コード例 #1
0
 @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));
 }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @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());
   }
 }
コード例 #4
0
 @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());
   }
 }
コード例 #5
0
 @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));
 }
コード例 #6
0
 @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));
 }