private E[] checkSequence(final int[] commands) {

    int maxSize = 0;
    for (int ops : commands) {
      maxSize = ops > 0 ? maxSize + ops : maxSize;
    }

    @SuppressWarnings("unchecked")
    E[] vals = (E[]) new Object[maxSize];

    assertTrue(queue.isEmpty());

    int posW = 0;
    int posR = 0;
    int tot = 0;
    for (int c = 0; c < commands.length; c++) {

      int ops = Math.abs(commands[c]);
      for (int i = 0; i < ops; i++) {

        if (commands[c] > 0) { // Add the required # of values to the queue and save them
          final E val = generateValue();
          vals[posW++] = val;
          queue.enqueue(val);

        } else { // Read the required # of values from the queue and verify them

          final E val = queue.dequeue();
          assertEquals(vals[posR++], val);

        }
      }

      // Keep a count of how many values are in the queue and verify the size.
      tot += commands[c];
      assertEquals(tot, queue.size());
    }

    assertEquals(tot == 0, queue.isEmpty());
    return vals;
  }