parent
a0172c8dda
commit
c4a0d4c27e
|
@ -49,28 +49,43 @@ public class ExtendedIteratorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNoRemove() {
|
||||
Iterator<Integer> iter = ExtendedIterator.createNoRemove(collectionA.iterator());
|
||||
assertThrows(UnsupportedOperationException.class, iter::remove);
|
||||
public void testAddTo() {
|
||||
final List<Integer> expected = new ArrayList<>(collectionA);
|
||||
expected.addAll(collectionA);
|
||||
final List<Integer> actual = ExtendedIterator.create(collectionA.iterator()).addTo(new ArrayList<>(collectionA));
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithStream() {
|
||||
Iterator<Integer> iter = ExtendedIterator.create(collectionA.stream());
|
||||
assertThrows(UnsupportedOperationException.class, iter::remove);
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
public void testAndThen() {
|
||||
final Iterator<Integer> iter1 = Arrays.asList(1, 2, 3).iterator();
|
||||
final Iterator<Integer> iter2 = Arrays.asList(4, 5, 6).iterator();
|
||||
|
||||
final ExtendedIterator<Integer> underTest = ExtendedIterator.create(iter1).andThen(iter2);
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
final Iterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatten() {
|
||||
Iterator<Iterator<Integer>> iteratorIterator = Arrays.asList(
|
||||
Arrays.asList(1, 2, 3).iterator(),
|
||||
Arrays.asList(4, 5, 6).iterator()
|
||||
).iterator();
|
||||
Iterator<Integer> iter = ExtendedIterator.flatten(iteratorIterator);
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
public void testCreateNoRemove() {
|
||||
final Iterator<Integer> iter = ExtendedIterator.createNoRemove(collectionA.iterator());
|
||||
assertThrows(UnsupportedOperationException.class, iter::remove);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithStream() {
|
||||
final Iterator<Integer> iter = ExtendedIterator.create(collectionA.stream());
|
||||
assertThrows(UnsupportedOperationException.class, iter::remove);
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
@ -81,70 +96,55 @@ public class ExtendedIteratorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
Iterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
public void testFilter() {
|
||||
final List<Integer> expected = Arrays.asList(2, 4, 6);
|
||||
final Predicate<Integer> predicate = i -> i % 2 == 0;
|
||||
final ExtendedIterator<Integer> underTest = ExtendedIterator.create(collectionA.iterator()).filter(predicate);
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatten() {
|
||||
final Iterator<Iterator<Integer>> iteratorIterator = Arrays.asList(
|
||||
Arrays.asList(1, 2, 3).iterator(),
|
||||
Arrays.asList(4, 5, 6).iterator()
|
||||
).iterator();
|
||||
final Iterator<Integer> iter = ExtendedIterator.flatten(iteratorIterator);
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
final List<Double> expected = Arrays.asList(0.5, 1., 1.5, 2.0, 2.5, 3.0);
|
||||
final Function<Integer, Double> function = i -> i / 2.0;
|
||||
final ExtendedIterator<Double> underTest = ExtendedIterator.create(collectionA.iterator()).map(function);
|
||||
final List<Double> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
Iterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
Integer i = iter.next();
|
||||
final Iterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
final Integer i = iter.next();
|
||||
iter.remove();
|
||||
assertFalse(collectionA.contains(i));
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNext() {
|
||||
ExtendedIterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
Integer i = iter.removeNext();
|
||||
final ExtendedIterator<Integer> iter = ExtendedIterator.create(collectionA.iterator());
|
||||
final Integer i = iter.removeNext();
|
||||
assertFalse(collectionA.contains(i));
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
final List<Integer> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAndThen() {
|
||||
Iterator<Integer> iter1 = Arrays.asList(1, 2, 3).iterator();
|
||||
Iterator<Integer> iter2 = Arrays.asList(4, 5, 6).iterator();
|
||||
|
||||
ExtendedIterator<Integer> underTest = ExtendedIterator.create(iter1).andThen(iter2);
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(collectionA, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
List<Integer> expected = Arrays.asList(2, 4, 6);
|
||||
Predicate<Integer> predicate = i -> i % 2 == 0;
|
||||
ExtendedIterator<Integer> underTest = ExtendedIterator.create(collectionA.iterator()).filter(predicate);
|
||||
List<Integer> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
List<Double> expected = Arrays.asList(0.5, 1., 1.5, 2.0, 2.5, 3.0);
|
||||
Function<Integer, Double> function = i -> i / 2.0;
|
||||
ExtendedIterator<Double> underTest = ExtendedIterator.create(collectionA.iterator()).map(function);
|
||||
List<Double> actual = new ArrayList<>();
|
||||
underTest.forEachRemaining(actual::add);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTo() {
|
||||
List<Integer> expected = new ArrayList<>(collectionA);
|
||||
expected.addAll(collectionA);
|
||||
List<Integer> actual = ExtendedIterator.create(collectionA.iterator()).addTo(new ArrayList<>(collectionA));
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue