package net.ranides.assira.collection.query.base;

import net.ranides.test.CQueryAssert;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import net.ranides.assira.collection.lists.IntRange;
import net.ranides.assira.collection.maps.OpenMap;
import net.ranides.assira.generic.HashUtils;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static org.junit.Assert.*;

public class CQCollectionTest {

    @Test
    public void whileEach() {
        Integer[] input = {7, 6, 2, 3, 4, 9, 2, 5, 1, 6, 7, 8, 4};

        int[] out1 = {0};
        boolean all = new CQCollection<>(Arrays.asList(input)).whileEach(v -> {
            out1[0]++;
            return v != 1;
        });
        assertFalse(all);
        assertEquals(9, out1[0]);
    }

    @Test
    public void fetch() {
        CQCollection<Integer> query = new CQCollection<>(Arrays.asList(1, 2, 3, 4, 5));

        Assert.assertSame(query, query.fetch());
        Assert.assertSame(query, query.prefetch());
        Assert.assertSame(query, query.cache(Paths.get("abc")));
    }

    @Test
    public void paralellEach() {
        List<Integer> range = new ArrayList<>(new IntRange(0, 50));
        CQueryAssert.assertOrderedParallel(new CQCollection<>(range));
    }

}