Exemplo n.º 1
0
  // @Test
  public void graphBubbleSort() {

    System.out.println("size, time");

    for (int i = 0; i < 255; i++) {
      int size = Sort.randBoundInt(r, 100, 10000);

      Random pop = new Random(42);

      ArrayList<Integer> arr = new ArrayList<Integer>(size);
      for (int j = 0; j < size; j++) {
        arr.add(pop.nextInt());
      }

      Integer[] a = arr.toArray(new Integer[0]);

      long startTime = System.nanoTime();

      Sort.<Integer>bubblesort(a);

      long stopTime = System.nanoTime();
      long elapsedTime = stopTime - startTime;
      System.out.println(size + ", " + elapsedTime);
    }
  }
Exemplo n.º 2
0
  @Before
  public void setUp() throws Exception {
    sort = SrtTextReader.sortForCodepage(65001);

    Collator collator = sort.getCollator();
    collator.setStrength(Collator.TERTIARY);
  }
Exemplo n.º 3
0
  private int keyCompare(String s1, String s2) {
    SortKey<Object> k1 = sort.createSortKey(null, s1);
    SortKey<Object> k2 = sort.createSortKey(null, s2);
    System.out.println("K1: " + k1);
    System.out.println("K2: " + k2);

    return k1.compareTo(k2);
  }
Exemplo n.º 4
0
  @Test
  public void testEquals() {
    String abc = "ABC\u0234\u1023";
    SortKey<Object> key1 = sort.createSortKey(null, abc);
    SortKey<Object> key2 = sort.createSortKey(null, abc);

    assertEquals(0, key1.compareTo(key2));
  }
Exemplo n.º 5
0
  @Test(timeout = 24)
  public void testMergesort() {
    Integer[] a = {10, 4, 6, 45, 68, 30, 61, 5, 21, 11};
    Integer[] b = Sort.<Integer>mergesort(a);

    // System.out.println(Arrays.asList(a));
    // System.out.println(Arrays.asList(b));

    assertTrue(isAsc(b));
  }
Exemplo n.º 6
0
  @Test(timeout = 24)
  public void testQuicksort() {
    // Integer[] a = {10,4,6,45,68,30,61,5,21,11};
    Integer[] b = {10, 4, 6, 45, 68, 30, 61, 5, 21, 11};

    Sort.<Integer>quicksort(b, new Random());

    // System.out.println(Arrays.asList(a));
    // System.out.println(Arrays.asList(b));

    assertTrue(isAsc(b));
  }
Exemplo n.º 7
0
  @Test(timeout = 110)
  public void testInsertionSort() {
    // Integer[] a = {10,4,6,45,68,30,61,5,21,11};
    Integer[] b = {10, 4, 6, 45, 68, 30, 61, 5, 21, 11, -3};

    // System.out.println(Arrays.asList(a));
    // System.out.println(Arrays.asList(b));

    Sort.<Integer>insertionsort(b);

    assertTrue(isAsc(b));
  }
Exemplo n.º 8
0
 @Test
 public void testInsertionSort() {
   try {
     for (int i = 0; i < 1000; i++) {
       RandomArray array1000 = new RandomArray(1000, -1000, 1000);
       Sort.insertionSort(array1000.get());
       assertTrue(verify(array1000.get()));
     }
   } catch (RandomArrayException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 9
0
  @Test
  public void testSorted() {
    final Random r = new Random(0);
    final Integer[] test = new Integer[1024];
    final Integer[] expected;

    for (int i = 0; i < test.length; i++) {
      test[i] = r.nextInt(100);
    }

    expected = Arrays.copyOf(test, test.length);

    sort.sort(test, Comparator.naturalOrder());
    Arrays.sort(test);

    assertArrayEquals(expected, test);
  }
Exemplo n.º 10
0
  @Test // (timeout=24)
  public void testRadixsort() {
    int[] a = {10, 4, 6, 45, 68, -99, 30, 61, 5, 21, -11, -22, -33};
    int[] b = Sort.radixsort(a);

    System.out.print("[");
    for (int i = 0; i < a.length; i++) {
      System.out.print(a[i]);
      if (i != a.length - 1) System.out.print(", ");
    }
    System.out.print("]\n");

    System.out.print("[");
    for (int i = 0; i < b.length; i++) {
      System.out.print(b[i]);
      if (i != b.length - 1) System.out.print(", ");
    }
    System.out.print("]\n");

    assertTrue(isAscInt(b));
  }
Exemplo n.º 11
0
 @Test
 public void testUnicodePresent() {
   String description = sort.getDescription();
   assertTrue(description.contains("Unicode"));
   assertFalse(description.contains("Default"));
 }