package net.ranides.assira.collection.lists;

import net.ranides.test.ContractTesters;
import net.ranides.test.data.TCollection;
import net.ranides.test.data.TMaps;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.ListIterator;

import static org.junit.Assert.*;

public class CopyListTest {
    private final TCollection<Integer> $var = TMaps.MAP_IS.keys();

    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("collection!", $var)
            .function(new int[0], array -> new CopyList<>($var.list(array).values()))
            .run();
    }

    @Test
    public void testIterator() {
        ArrayList<Integer> source = new ArrayList<>(Arrays.asList(7, 8, 9));
        CopyList<Integer> list = new CopyList<>(source);

        ListIterator<Integer> itr = list.listIterator();
        itr.next();
        itr.add(11);
        itr.add(12);

        assertEquals((Integer)8, itr.next());
        assertEquals(Arrays.asList(7,8,9), source);
        assertEquals(Arrays.asList(7,11,12,8,9), list);
    }
}