LongCyclicQueue.PinnedIterator it = myArray.pinnedIterator(); assertTrue(it.hasNext()); assertEquals(10, it.nextValue()); assertEquals(11, it.nextValue()); myArray.addAll(14, 15); assertEquals(12, it.value()); assertTrue(it.hasNext()); assertEquals(13, it.nextValue()); assertTrue(it.hasNext()); assertEquals(14, it.nextValue()); assertTrue(it.hasNext()); assertEquals(15, it.nextValue()); assertFalse(it.hasNext()); assertEquals(15, it.value()); assertFalse(it.hasNext()); assertEquals(15, it.value()); assertFalse(it.hasNext()); assertEquals(15, it.value()); assertFalse(it.hasNext()); myArray.addAll(LongProgression.arithmetic(16, 100)); assertEquals(15, it.value()); assertTrue(it.hasNext()); assertEquals(16, it.nextValue());
public void testPiteratorIndex2() { int mSize = 15; for (int startIdx = 0; startIdx < mSize; startIdx++) { for (int pinnedIdx = 0; pinnedIdx < mSize; pinnedIdx++) { LongCyclicQueue queue = new LongCyclicQueue(); queue.addAll(LongCollections.repeat(-1, startIdx)); queue.removeFirst(startIdx); queue.addAll(range(mSize)); LongCyclicQueue.PinnedIterator it = queue.pinnedIterator(); checkRemoveAndCatchISE(queue, -1); it.next(); assertEquals(0, it.index()); it.detach(); it = queue.pinnedIterator(pinnedIdx); checkRemoveAndCatchISE(queue, pinnedIdx + 1); it.next(); assertEquals(pinnedIdx != mSize - 1, it.hasNext()); assertEquals("startIdx = " + startIdx, pinnedIdx, it.index()); queue.addAll(1, 2, 3); assertEquals(pinnedIdx, it.index()); if (pinnedIdx != 0) { queue.removeFirst(); assertEquals(pinnedIdx - 1, it.index()); } } } }
public void testAttachDetach() { myArray.add(10); LongCyclicQueue.PinnedIterator it = myArray.pinnedIterator(); checkRemoveAndCatchISE(myArray, -1); assertEquals(10, it.nextValue()); it.detach(); myArray.removeFirst(); assertEquals(10, it.value()); myArray.addAll(LongArray.create(11, 12, 13, 14, 15).iterator()); CHECK.order(myArray, 11, 12, 13, 14, 15); myArray.removeFirst(); myArray.add(16); CHECK.order(myArray, 12, 13, 14, 15, 16); // Note: the value has changed! assertEquals(16, it.value()); it.attach(); assertEquals(16, it.value()); assertFalse(it.hasNext()); checkRemoveAndCatchISE(myArray, -2); checkRemoveAndCatchISE(myArray, 5); myArray.removeFirst(4); myArray.add(17); assertTrue(it.hasNext()); assertEquals(17, it.nextValue()); assertFalse(it.hasNext()); }