private void runListIteratorTest(Set<IteratorFeature> features) { new ListIteratorTester<E>( listListIteratorTesterNumIterations(), singleton(e4()), features, Helpers.copyToList(getOrderedElements()), 0) { @Override protected ListIterator<E> newTargetIterator() { resetCollection(); return getList().listIterator(); } @Override protected void verify(List<E> elements) { expectContents(elements); } }.test(); }
private <T extends Comparable<T>> void runIterator( final List<T> values, int steps) throws Exception { IteratorTester<T> tester = new IteratorTester<T>( steps, IteratorFeature.MODIFIABLE, Lists.newLinkedList(values), IteratorTester.KnownOrder.UNKNOWN_ORDER) { private MinMaxPriorityQueue<T> mmHeap; @Override protected Iterator<T> newTargetIterator() { mmHeap = MinMaxPriorityQueue.create(values); return mmHeap.iterator(); } @Override protected void verify(List<T> elements) { assertEquals(Sets.newHashSet(elements), Sets.newHashSet(mmHeap.iterator())); assertTrue("Invalid MinMaxHeap: " + mmHeap, mmHeap.isIntact()); } }; tester.test(); }
private void runListIteratorTest(Set<IteratorFeature> features) { new ListIteratorTester<E>( listListIteratorTesterNumIterations(), singleton(e4()), features, Helpers.copyToList(getOrderedElements()), 0) { { // TODO: don't set this universally stopTestingWhenAddThrowsException(); } @Override protected ListIterator<E> newTargetIterator() { resetCollection(); return getList().listIterator(); } @Override protected void verify(List<E> elements) { expectContents(elements); } }.test(); }
private <T extends Comparable<T>> void runIterator(final List<T> values, int steps) throws Exception { IteratorTester<T> tester = new IteratorTester<T>( steps, IteratorFeature.MODIFIABLE, Lists.newLinkedList(values), IteratorTester.KnownOrder.UNKNOWN_ORDER) { private MinMaxPriorityQueue<T> mmHeap; @Override protected Iterator<T> newTargetIterator() { mmHeap = MinMaxPriorityQueue.create(values); return mmHeap.iterator(); } @Override protected void verify(List<T> elements) { assertEquals(Sets.newHashSet(elements), Sets.newHashSet(mmHeap.iterator())); assertIntact(mmHeap); } }; tester.test(); }
@GwtIncompatible // fairly slow (~50s) public void testPartition_general() { new IteratorTester<List<Integer>>(5, IteratorFeature.UNMODIFIABLE, ImmutableList.of( asList(1, 2, 3), asList(4, 5, 6), asList(7)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test(); }
@GwtIncompatible // fairly slow (~50s) public void testPaddedPartition_general() { new IteratorTester<List<Integer>>(5, IteratorFeature.UNMODIFIABLE, ImmutableList.of( asList(1, 2, 3), asList(4, 5, 6), asList(7, null, null)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.paddedPartition(source, 3); } }.test(); }
public void testSkip_iterator() throws Exception { new IteratorTester<Integer>(5, IteratorFeature.MODIFIABLE, Lists.newArrayList(2, 3), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<Integer> newTargetIterator() { Collection<Integer> collection = Sets.newLinkedHashSet(); Collections.addAll(collection, 1, 2, 3); return FluentIterable.from(collection).skip(1).iterator(); } }.test(); }
public void testSkip_iteratorList() throws Exception { new IteratorTester<Integer>(5, IteratorFeature.MODIFIABLE, Lists.newArrayList(2, 3), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<Integer> newTargetIterator() { return FluentIterable.from(Lists.newArrayList(1, 2, 3)).skip(1).iterator(); } }.test(); }
@SuppressWarnings("unchecked") @CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER}) public void testRemovingIteratorKnownOrder() { new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, getSubjectGenerator().order( Arrays.asList(e0(), e1(), e1(), e2())), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<E> newTargetIterator() { return getSubjectGenerator().create(e0(), e1(), e1(), e2()) .iterator(); } }.test(); }
@SuppressWarnings("unchecked") @CollectionFeature.Require(value = SUPPORTS_ITERATOR_REMOVE, absent = KNOWN_ORDER) public void testRemovingIteratorUnknownOrder() { new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, Arrays.asList(e0(), e1(), e1(), e2()), IteratorTester.KnownOrder.UNKNOWN_ORDER) { @Override protected Iterator<E> newTargetIterator() { return getSubjectGenerator().create(e0(), e1(), e1(), e2()) .iterator(); } }.test(); }
@SuppressWarnings("unchecked") @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE) public void testIteratorKnownOrder() { new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, getSubjectGenerator().order( Arrays.asList(e0(), e1(), e1(), e2())), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<E> newTargetIterator() { return getSubjectGenerator().create(e0(), e1(), e1(), e2()) .iterator(); } }.test(); }
@SuppressWarnings("unchecked") @CollectionFeature.Require(absent = {SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER}) public void testIteratorUnknownOrder() { new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, Arrays.asList(e0(), e1(), e1(), e2()), IteratorTester.KnownOrder.UNKNOWN_ORDER) { @Override protected Iterator<E> newTargetIterator() { return getSubjectGenerator().create(e0(), e1(), e1(), e2()) .iterator(); } }.test(); }
@GwtIncompatible("fairly slow (~50s)") public void testPartition_general() { new IteratorTester<List<Integer>>(5, IteratorFeature.UNMODIFIABLE, ImmutableList.of( asList(1, 2, 3), asList(4, 5, 6), asList(7)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test(); }
@GwtIncompatible("fairly slow (~50s)") public void testPaddedPartition_general() { new IteratorTester<List<Integer>>(5, IteratorFeature.UNMODIFIABLE, ImmutableList.of( asList(1, 2, 3), asList(4, 5, 6), asList(7, null, null)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.paddedPartition(source, 3); } }.test(); }
@GwtIncompatible // fairly slow (~50s) public void testPartition_general() { new IteratorTester<List<Integer>>( 5, IteratorFeature.UNMODIFIABLE, ImmutableList.of(asList(1, 2, 3), asList(4, 5, 6), asList(7)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test(); }
@GwtIncompatible // fairly slow (~50s) public void testPaddedPartition_general() { new IteratorTester<List<Integer>>( 5, IteratorFeature.UNMODIFIABLE, ImmutableList.of(asList(1, 2, 3), asList(4, 5, 6), asList(7, null, null)), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.paddedPartition(source, 3); } }.test(); }
public void testSkip_iterator() throws Exception { new IteratorTester<Integer>( 5, IteratorFeature.MODIFIABLE, Lists.newArrayList(2, 3), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<Integer> newTargetIterator() { Collection<Integer> collection = Sets.newLinkedHashSet(); Collections.addAll(collection, 1, 2, 3); return FluentIterable.from(collection).skip(1).iterator(); } }.test(); }
public void testSkip_iteratorList() throws Exception { new IteratorTester<Integer>( 5, IteratorFeature.MODIFIABLE, Lists.newArrayList(2, 3), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator<Integer> newTargetIterator() { return FluentIterable.from(Lists.newArrayList(1, 2, 3)).skip(1).iterator(); } }.test(); }