@Test
public void testCompact() {

  FoldedTreeSet<Holder> set = new FoldedTreeSet<>();
  long[] longs = new long[24553];
  for (int i = 0; i < longs.length; i++) {
    Holder val = new Holder(srand.nextLong());
    while (set.contains(val)) {
      val = new Holder(srand.nextLong());
    }
    longs[i] = val.getId();
    set.add(val);
  }
  assertEquals(longs.length, set.size());
  long[] longs2 = new long[longs.length];
  for (int i = 0; i < longs2.length; i++) {
    Holder val = new Holder(srand.nextLong());
    while (set.contains(val)) {
      val = new Holder(srand.nextLong());
    }
    longs2[i] = val.getId();
    set.add(val);
  }
  assertEquals(longs.length + longs2.length, set.size());
  // Create fragementation
  for (long val : longs) {
    assertTrue(set.remove(new Holder(val)));
  }
  assertEquals(longs2.length, set.size());
  assertFalse(set.compact(0));
  assertTrue(set.compact(Long.MAX_VALUE));
  assertEquals(longs2.length, set.size());
  for (long val : longs) {
    assertFalse(set.remove(new Holder(val)));
  }
  for (long val : longs2) {
    assertEquals(val, set.get(new Holder(val)).getId());
  }
}