public static void assertContents(LongIterator it, LongArray values) { int index = 0; while(it.hasNext()) { if(index >= values.size()) { fail("Iterator is too long: " + s(it) + " past expected " + s(values.iterator())); } assertEquals("Wrong value at index " + index, values.get(index), it.nextValue()); index++; } assertEquals("Iterator is too short", values.size(), index); }
ints = IntegersUtils.EMPTY_LONGS; CHECK.order(collection.toNativeArray(), ints); assertEquals(collection.size(), ints.length); CHECK.order(collection.iterator(), ints); LongListIterator it; long anInt = ints[i]; assertTrue(it.hasNext()); assertEquals(anInt, it.nextValue()); assertEquals(anInt, collection.get(i)); CheckLongCollection checker = new CheckLongCollection(collection, i); AbstractLongListDecorator.iterate(collection, i, ints.length, checker); assertEquals(ints.length, checker.index); long[] array = new long[ints.length - i + 1]; collection.toNativeArray(i, array, 1, collection.size() - i); CheckLongCollection checker = new CheckLongCollection(collection, 0); AbstractLongListDecorator.iterate(collection, 0, i, checker); assertEquals(i, checker.index);
protected void checkRemovedIndexes(final AbstractLongListRemovingDecorator rem, int... expected) { if (expected == null) expected = IntegersUtils.EMPTY_INTS; CHECK.order(rem.removedIndexIterator(), expected); LongList base = rem.getBase(); for (int i = 0; i < base.size(); i++) { boolean removed = rem.isRemovedAt(i); boolean kept = IntCollections.indexOf(i, expected) < 0; assertTrue(String.valueOf(i), removed != kept); int newIndex = rem.getNewIndex(i); if (removed) assertEquals(-1, newIndex); else { assertTrue(newIndex >= 0); assertEquals(base.get(i), rem.get(newIndex)); } } boolean res = rem.iterate(0, rem.size(), new AbstractLongListDecorator.LongVisitor() { int index = -1; public boolean accept(long value, LongList source) { index++; assertEquals(rem.get(index), value); assertSame(rem.getBase(), source); return true; } }); assertTrue(res); }
public static void checkSet(LongSet set, LongList sortedUniqueExpected) { assert sortedUniqueExpected.isSortedUnique(); assertEquals(sortedUniqueExpected.size(), set.size()); if (set instanceof LongSortedSet) { LongArray buffer = LongCollections.collectIterable(set.size(), set.iterator()); CHECK.order(sortedUniqueExpected, buffer); buffer = set.toArray(); CHECK.order(sortedUniqueExpected, buffer); } else { LongArray setToIterator = LongCollections.collectIterable(set.size(), set.iterator()); LongArray setToArray = set.toArray(); CHECK.order(setToArray, setToIterator); setToArray.sort(); CHECK.order(sortedUniqueExpected, setToArray); } }