@Test
public void testAdd() {

  FoldedTreeSet<String> simpleSet = new FoldedTreeSet<>();
  String entry = "apa";
  assertTrue(simpleSet.add(entry));
  assertFalse(simpleSet.add(entry));
  FoldedTreeSet<Integer> intSet = new FoldedTreeSet<>();
  for (int i = 512; i < 1024; i++) {
    assertTrue(intSet.add(i));
  }
  for (int i = -1024; i < -512; i++) {
    assertTrue(intSet.add(i));
  }
  for (int i = 0; i < 512; i++) {
    assertTrue(intSet.add(i));
  }
  for (int i = -512; i < 0; i++) {
    assertTrue(intSet.add(i));
  }
  assertEquals(2048, intSet.size());
  FoldedTreeSet<Holder> set = new FoldedTreeSet<>();
  long[] longs = new long[23432];
  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();
    assertTrue(set.add(val));
  }
  assertEquals(longs.length, set.size());
  Arrays.sort(longs);
  Iterator<Holder> it = set.iterator();
  for (int i = 0; i < longs.length; i++) {
    assertTrue(it.hasNext());
    Holder val = it.next();
    assertEquals(longs[i], val.getId());
  }
  // Specially constructed adds to exercise all code paths
  FoldedTreeSet<Integer> specialAdds = new FoldedTreeSet<>();
  // Fill node with even numbers
  for (int i = 0; i < 128; i += 2) {
    assertTrue(specialAdds.add(i));
  }
  // Remove left and add left
  assertTrue(specialAdds.remove(0));
  assertTrue(specialAdds.add(-1));
  assertTrue(specialAdds.remove(-1));
  // Add right and shift everything left
  assertTrue(specialAdds.add(127));
  assertTrue(specialAdds.remove(127));
  // Empty at both ends
  assertTrue(specialAdds.add(0));
  assertTrue(specialAdds.remove(0));
  assertTrue(specialAdds.remove(126));
  // Add in the middle left to slide entries left
  assertTrue(specialAdds.add(11));
  assertTrue(specialAdds.remove(11));
  // Add in the middle right to slide entries right
  assertTrue(specialAdds.add(99));
  assertTrue(specialAdds.remove(99));
  // Add existing entry in the middle of a node
  assertFalse(specialAdds.add(64));
}