@Test
  public void fuzzyTest() {
    for(int test = 0; test < 100; test++) {
      final Random rng = new Random(42 + test);
      final ObjectArrayBuilder<Integer> builder = new ObjectArrayBuilder<>();
      int size = 100_000, l = 0, n = 0;
      do {
        final int action = rng.nextInt(4);
        if(action == 0) {
          // check iterator
          final Iterator<Integer> iter = builder.iterator();
          for(int i = 0; i < n; i++) {
            assertTrue(iter.hasNext());
            assertEquals(l + i, iter.next().intValue());
          }
          assertFalse(iter.hasNext());
        } else if(action == 1) {
          // prepend element
          builder.prepend(--l);
          n++;
        } else if(action == 2) {
          // append element
          builder.append(l + n++);
        } else {
          // append array
          final int k = rng.nextInt(Math.min(size - n, 1_000));
          builder.append(array(l + n, k));
          n += k;
        }
      } while(n < size);

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