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

import java.util.function.Consumer;
import java.util.function.IntFunction;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TCollections;
import net.ranides.assira.collection.mockup.TPoint;
import net.ranides.assira.collection.suite.IteratorTester.IteratorParams;
import org.junit.Test;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ForwardIteratorTest {

    private static final IntFunction<TPoint[]> $data = size -> TCollections.POINT.range(size).values();

    @Test
    public void testContract() {
        ContractTesters
            .runner()
            .param("iterator.array!", $data)
            .function(new IteratorParams(0,0), NIterator::new)
            .run();
    }
    
    private static final class NIterator extends ForwardIterator<TPoint> {
        
        private final TPoint[] data;
        private int index;

        public NIterator(IteratorParams params) {
            this.data = $data.apply(params.size);
            this.index = params.index;
        }

        @Override
        protected boolean next(Consumer<? super TPoint> action) {
            if(index>=data.length) {
                return false;
            }
            action.accept(data[index++]);
            return true;
            
        }
        
    }
}
