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

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

import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.collection.query.CQueryFeatures;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;

public class CQSingleTest {

    @Test
    public void value() {
        CQuery<Integer> query = CQuery.from().value(15);
        CQueryAssert.assertEquals(Arrays.asList(15), query);
    }

    @Test
    public void features() {
        CQuery<Integer> query = CQuery.from().value(15);
        assertTrue(query.features().hasFastEach());
        assertTrue(query.features().hasFastStream());
        assertTrue(query.features().hasFastIterator());
        assertTrue(query.features().hasFastLength());
        assertTrue(query.features().hasFastList());
    }

    @Test
    public void limitSkipSlice() {
        CQuery<Integer> query = CQuery.from().value(15);

        assertSame(query, query.limit(15));
        assertSame(query, query.skip(0));
        assertSame(query, query.slice(0,10));
        assertSame(query, query.slice(0,1));

        CQueryAssert.assertEmpty(query.limit(0));
        CQueryAssert.assertEmpty(query.skip(1));
        CQueryAssert.assertEmpty(query.skip(5));
        CQueryAssert.assertEmpty(query.slice(1,10));
        CQueryAssert.assertEmpty(query.slice(5,10));
        CQueryAssert.assertEmpty(query.slice(0,0));
    }

    @Test
    public void fetch() {
        CQSingle<Integer> query = new CQSingle<>(15);

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