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

import java.util.ArrayList;
import java.util.List;
import net.ranides.assira.collection.iterators.IntIterator;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.test.TCollection;
import static org.junit.Assert.*;
import org.junit.Test;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class AIntCollectionTest {
    
    private final TCollection<Integer> $var = TMaps.MAP_IS.keys();

    @Test
    public void testSuite() {
        ContractTesters.runner()
			.param("collection!", $var)
			.function(new int[0], array -> new TIntCollection($var.list(array)))
			.run();
    }
    
    @Test
    public void testToString() {
        TIntCollection target1 = new TIntCollection($var.list(1,2,3,4,5));
        assertEquals("[1, 2, 3, 4, 5]", target1.toString());
		
		TIntCollection target2 = new TIntCollection($var.list(1));
        assertEquals("[1]", target2.toString());
		
		TIntCollection target3 = new TIntCollection($var.list());
        assertEquals("[]", target3.toString());
    }
    
    private static final class TIntCollection extends AIntCollection {
        
        private final List<Integer> list;

        public TIntCollection(TCollection.TItems<Integer> list) {
            this.list = list.into(new ArrayList<>());
        }

        @Override
        public boolean add(int k) {
            return list.add(k);
        }
        
        @Override
        public int size() {
            return list.size();
        }

        @Override
        public IntIterator iterator() {
            return IntIterator.wrap(list.iterator());
        }
        
    }
    
}
