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

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
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 org.junit.Test;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ASetTest {
    
    private final TCollection<TPoint> $var = TMaps.MAP_PI.keys();
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("collection!", $var)
            .function(new int[0], array -> $var.list(array).into(new ATSet($var.comparator())))
			.run();
    }
    
    private static class ATSet extends ASet<TPoint> {
        
        private final Set<TPoint> data;

        public ATSet(Comparator<TPoint> cmp) {
            data = new TreeSet<>(cmp);
        }

        @Override
        public Iterator<TPoint> iterator() {
            return data.iterator();
        }

        @Override
        public boolean add(TPoint key) {
            return data.add(key);
        }

        @Override
        public boolean remove(Object key) {
            if(!(key instanceof TPoint)) {
                return false;
            }
            return data.remove(key);
        }

        @Override
        public void clear() {
            data.clear();
        }

        @Override
        public boolean contains(Object key) {
            if(!(key instanceof TPoint)) {
                return false;
            }
            return data.contains(key);
        }

        @Override
        public int size() {
            return data.size();
        }

    }
    
}
