package com.github.nikita_volkov.java.iterators;

import junit.framework.TestCase;

import java.util.*;

public class Test extends TestCase {

  public void testAppendIterator() {
    List<Integer> list1 = Arrays.asList(1, 2, 3, 4);
    List<Integer> list2 = Arrays.asList(5, 6, 7, 8);
    Iterator<Integer> iterator =
      new AppendingIterator<>(list1.iterator(), list2.iterator());

    assertEquals(36, sum(iterator));
  }

  public void testProjectIterator() {
    List<Integer> list = Arrays.asList(1, 2, 3, 4);
    Iterator<Integer> iterator =
      new MappingIterator<>(
        list.iterator(),
        n -> n * 2
      );

    assertEquals(20, sum(iterator));
  }

  public void testFilterIterator() {
    List<Integer> list = Arrays.asList(1, 2, 3, 4);
    Iterator<Integer> iterator =
      new FilteringIterator<>(
        list.iterator(),
        n -> n % 2 == 0
      );

    assertEquals(6, sum(iterator));
  }

  public void testUniqueIterator() {
    List<Integer> list = Arrays.asList(1, 2, 2, 3, 4);
    Iterator<Integer> iterator =
      new UniquifyingIterator<>(list.iterator());

    assertEquals(10, sum(iterator));
  }

  private static int sum(Iterator<Integer> iterator) {
    int sum = 0;
    while (iterator.hasNext()) {
      sum += iterator.next();
    }
    return sum;
  }

}
@@ -160,16 +160,19 @@
 stAppend
+ing
 Iterator
@@ -168,32 +168,32 @@
 ingIterator() %7B%0A
-
     List%3CInteger
@@ -447,15 +447,15 @@
 test
-Project
+Mapping
 Iter
@@ -697,16 +697,19 @@
 stFilter
+ing
 Iterator
@@ -952,17 +952,22 @@
 estUniqu
-e
+ifying
 Iterator

Rename tests