package com.wizzardo.tools.collections;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by wizzardo on 14.09.15.
 */
public class CollectionToolsTest {

    @Test
    public void group() {
        List<Integer> list = new ArrayList<Integer>() {{
            add(1);
            add(2);
            add(3);
            add(4);
            add(5);
        }};

        Map<Boolean, List<Integer>> groups = CollectionTools.group(list, new CollectionTools.Closure<Boolean, Integer>() {
            @Override
            public Boolean execute(Integer it) {
                return it % 2 == 0;
            }
        }, new CollectionTools.Closure<Integer, Integer>() {
            @Override
            public Integer execute(Integer it) {
                return it;
            }
        });

        Assert.assertEquals(2, groups.size());
        Assert.assertEquals(2, groups.get(true).size());
        Assert.assertEquals(3, groups.get(false).size());
    }
}

@@ -155,16 +155,66 @@
 til.Map;
+%0Aimport java.util.concurrent.atomic.AtomicInteger;
 %0A%0A/**%0A *
@@ -287,16 +287,1783 @@
 Test %7B%0A%0A
+    @Test%0A    public void each() %7B%0A        List%3CInteger%3E list = new ArrayList%3CInteger%3E() %7B%7B%0A            add(1);%0A            add(2);%0A            add(3);%0A        %7D%7D;%0A        final AtomicInteger counter = new AtomicInteger();%0A        CollectionTools.each(list, new CollectionTools.Closure%3CVoid, Integer%3E() %7B%0A            @Override%0A            public Void execute(Integer it) %7B%0A                counter.addAndGet(it);%0A                return null;%0A            %7D%0A        %7D);%0A        Assert.assertEquals(6, counter.get());%0A    %7D%0A%0A    @Test%0A    public void eachWithIndex() %7B%0A        List%3CInteger%3E list = new ArrayList%3CInteger%3E() %7B%7B%0A            add(1);%0A            add(2);%0A            add(3);%0A        %7D%7D;%0A        final AtomicInteger counter = new AtomicInteger();%0A        CollectionTools.eachWithIndex(list, new CollectionTools.Closure2%3CVoid, Integer, Integer%3E() %7B%0A            @Override%0A            public Void execute(Integer i, Integer value) %7B%0A                counter.addAndGet(value * i);%0A                return null;%0A            %7D%0A        %7D);%0A        Assert.assertEquals(8, counter.get());%0A    %7D%0A%0A    @Test%0A    public void collect() %7B%0A        List%3CInteger%3E list = new ArrayList%3CInteger%3E() %7B%7B%0A            add(1);%0A            add(2);%0A            add(3);%0A        %7D%7D;%0A        List%3CInteger%3E result = CollectionTools.collect(list, new CollectionTools.Closure%3CInteger, Integer%3E() %7B%0A            @Override%0A            public Integer execute(Integer it) %7B%0A                return it * 2;%0A            %7D%0A        %7D);%0A%0A        Assert.assertEquals(3, result.size());%0A        Assert.assertNotSame(list, result);%0A        Assert.assertEquals((Integer) 2, result.get(0));%0A        Assert.assertEquals((Integer) 4, result.get(1));%0A        Assert.assertEquals((Integer) 6, result.get(2));%0A    %7D%0A%0A
     @Tes

add some tests