@Test
  public void builderTestRandom() {
    final Random rng = new Random(42);
    final ArrayDeque<Integer> deque = new ArrayDeque<>();
    for(int len = 0; len < 10_000; len++) {
      deque.clear();
      final ObjectArrayBuilder<Integer> builder = new ObjectArrayBuilder<>();

      for(int i = 0; i < len; i++) {
        final Integer val = i;
        if(rng.nextBoolean()) {
          builder.prepend(val);
          deque.addFirst(val);
        } else {
          builder.append(val);
          deque.addLast(val);
        }
      }

      final ObjectArray<Integer> arr = builder.freeze();
      arr.checkInvariants();
      assertEquals(len, arr.size());
      final Iterator<Integer> iter1 = deque.iterator(), iter2 = arr.iterator();
      while(iter1.hasNext()) {
        assertTrue(iter2.hasNext());
        assertEquals(iter1.next(), iter2.next());
      }
      assertFalse(iter2.hasNext());
    }
  }