/*
 * Copyright 2015 Tagir Valeev
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package javax.util.streamex;

import static javax.util.streamex.TestHelpers.*;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Spliterator;

import org.junit.Test;

/**
 * @author Tagir Valeev
 */
public class CrossSpliteratorTest {
    @Test
    public void testCross() {
        for(int limit : new int[] {1, 2, 4, 9}) {
			List<List<Integer>> input = Collections.nCopies(3, IntStreamEx
					.range(limit).boxed().toList());
			List<List<Integer>> expected = IntStreamEx
					.range(limit * limit * limit)
					.mapToObj(
							i -> Arrays.asList(i / limit / limit, i / limit
									% limit, i % limit)).toList();
            checkSpliterator("cross", expected, () -> new CrossSpliterator.ToList<>(input));
        }
    }
    
    @Test
    public void testBigSize() {
        List<List<Integer>> input = new ArrayList<>();
        input.add(IntStreamEx.rangeClosed(1, 20).boxed().toList());
        input.addAll(Collections.nCopies(18, IntStreamEx.rangeClosed(1, 10).boxed().toList()));
        Spliterator<List<Integer>> spltr = new CrossSpliterator.ToList<>(input);
        assertFalse(spltr.hasCharacteristics(Spliterator.SIZED));
        assertEquals(Long.MAX_VALUE, spltr.estimateSize());
        spltr.trySplit();
        assertFalse(spltr.hasCharacteristics(Spliterator.SIZED));
        assertEquals(Long.MAX_VALUE, spltr.estimateSize());
        spltr.trySplit();
        assertTrue(spltr.hasCharacteristics(Spliterator.SIZED));
        assertEquals(5_000_000_000_000_000_000L, spltr.estimateSize());
    }
}

@@ -1003,16 +1003,22 @@
 estCross
+ToList
 () %7B%0D%0A  
@@ -1490,32 +1490,586 @@
    %0D%0A    @Test%0D%0A
+    public void testCrossReduce() %7B%0D%0A        for(int limit : new int%5B%5D %7B1, 2, 4, 9%7D) %7B%0D%0A            List%3CList%3CInteger%3E%3E input = Collections.nCopies(3, IntStreamEx%0D%0A                    .range(limit).boxed().toList());%0D%0A            List%3CString%3E expected = IntStreamEx.range(limit * limit * limit)%0D%0A                    .mapToObj(i -%3E %22%22 + (i / limit / limit) + (i / limit %25 limit) + (i %25 limit)).toList();%0D%0A            checkSpliterator(%22cross%22, expected, () -%3E new CrossSpliterator.Reducing%3C%3E(input, %22%22, (s, b) -%3E s+b));%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A    @Test%0D%0A
     public void 

test for reducing spliterator