/*
 * @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.Iterator;
import java.util.List;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.collection.mockup.TPoint;
import net.ranides.assira.test.TCollection;
import static org.junit.Assert.*;
import org.junit.Test;

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

    @Test
    public void testSuite() {
        ContractTesters.runner()
			.param("collection!", $var)
			.function(new int[0], (array) -> new MCollection<>($var.list(array)))
			.run();
    }
    
    @Test
    public void testToString() {
        MCollection<TPoint> target1 = new MCollection<>($var.list(1,2,3,4,5));
        assertEquals("[(1:1:10), (2:2:20), (3:3:30), (4:4:40), (5:5:50)]", target1.toString());
		
		MCollection<TPoint> target2 = new MCollection<>($var.list(1));
        assertEquals("[(1:1:10)]", target2.toString());
		
		MCollection<TPoint> target3 = new MCollection<>($var.list());
        assertEquals("[]", target3.toString());
    }
    
    private static final class MCollection<T> extends ACollection<T> {
        
        private final List<T> list;

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

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

        @Override
        public Iterator<T> iterator() {
            return list.iterator();
        }
        
    }
    
}
