Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  void testSpeed(AbstractPriorityQueue<Integer>... qs) {
    final int ITER = 1000, LENGTH = qs.length;
    final Random rand = new Random(0);

    StringBuilder build = new StringBuilder();
    long[][] times = new long[LENGTH][2];
    int[] keys;

    for (int size = 100; size <= 1000; size += 100) {
      for (int j = 0; j < ITER; j++) {
        keys = DSUtils.getRandomIntArray(rand, size);

        for (int k = 0; k < LENGTH; k++) addRuntime(qs[k], times[k], keys);
      }

      build.append(size);

      for (long[] time : times) {
        build.append("\t");
        build.append(StringUtils.join(time, "\t"));
      }

      build.append("\n");
    }

    System.out.println(build.toString());
  }
Ejemplo n.º 2
0
  void testAccuracy(AbstractPriorityQueue<Integer> q) {
    List<Integer> keys = DSUtils.toIntegerList(4, 1, 3, 2, 5, 6, 8, 3, 4, 7, 5, 9, 7);

    for (Integer key : keys) q.add(key);

    Collections.sort(keys, Collections.reverseOrder());

    for (Integer key : keys) assertEquals(q.removeMax(), key);
  }