/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.query;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.collection.query.CQueryBuilder;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class CQueryTest {
    
    private static final List<Character> CHARS = Arrays.asList('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    
    @Test
    public void testSimple() {
        List<String> exp1 = Arrays.asList(
            "4.a", "4.b", 
            "6.a", "6.b", "6.c",
            "8.a", "8.b", "8.c", "8.d"
        );
        List<String> exp2 = Arrays.asList(
            "6.a", "6.b", "6.c",
            "6.a", "6.b", "6.c",
            "10.a", "10.b", "10.c", "10.d", "10.e"
        );
        
        List<Integer> src = new ArrayList<>();
        
        CQuery<String> query = CQueryBuilder.fromCollection(src)
            .filter(v -> v%2 == 0)
            .filter(v -> v>3)
            .limit(3)
            .unfold(i -> CQueryBuilder.fromCollection(CHARS).limit(i/2).map(c->i+"."+c));
        
        src.addAll(Arrays.asList(0,1,2,3,4,5,6,7,8,9,10));
        
        assertEquals(exp1, query.list());
        assertEquals(exp1, query.list());
        
        src.clear();
        src.addAll(Arrays.asList(6,3,5,6,7,9,10));
        
        assertEquals(exp2, query.list());
        assertEquals(exp2, query.list());
    }
    
}
