@Test
  public void builderTestAlternating() {
    for(int len = 0; len < 10_000; len++) {
      final IntArrayBuilder builder = new IntArrayBuilder();

      final int mid = len / 2;
      if(len % 2 == 0) {
        for(int i = 0; i < len; i++) {
          if(i % 2 == 0) builder.prepend(mid - 1 - i / 2);
          else builder.append(mid + i / 2);
        }
      } else {
        for(int i = 0; i < len; i++) {
          if(i % 2 == 0) builder.prepend(mid - i / 2);
          else builder.append(mid + 1 + i / 2);
        }
      }

      final IntArray arr = builder.freeze();
      arr.checkInvariants();
      assertEquals(len, arr.size());
      final Iterator<Integer> iter = arr.iterator();
      for(int i = 0; i < len; i++) {
        assertTrue(iter.hasNext());
        assertEquals(i, iter.next().intValue());
      }
      assertFalse(iter.hasNext());
    }
  }