package net.ranides.assira.collection.lists;

import org.junit.Test;

import net.ranides.assira.time.TimeMetric;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import static org.junit.Assert.*;

public class VirtualListBenchmark {

    public static void main(String[] args) {
        testSpliterator();
    }

    private static void testSpliterator() {
        List<Integer> list = VirtualList.of(100, i -> i);

        AtomicInteger out1 = runStream(list.parallelStream());
        assertEquals(100, out1.get());

        AtomicInteger out2 = runStream(list.stream());
        assertEquals(100, out2.get());
    }

    private static AtomicInteger runStream(Stream<Integer> stream) {
        TimeMetric tm = new TimeMetric();
        AtomicInteger out = new AtomicInteger(0);
        stream.forEach(v -> {
            out.incrementAndGet();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println(tm.stop());
        return out;
    }


}