/*
 * @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.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Pattern;
import net.ranides.assira.collection.IntCollection;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.test.TCollection;
import net.ranides.assira.test.TComparator;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class IntRBTreeSetTest {
    
    private final TCollection<Integer> $var = TMaps.MAP_IS.keys();
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("collection!", $var)
			.ignore(Pattern.compile(".*_HC"))
            .function(new int[0], array -> $var.list(array).into(new IntRBTreeSet($var.comparator())))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IntRBTreeSet() );
        assertNotNull( new IntRBTreeSet($var.comparator()) );
    }
    
    @Test
    public void testConstructCopy() {
        TCollection.TItems<Integer> items = $var.range(180);
        
		TComparator<Integer> cmp1 = new TComparator<>(items);
		TComparator<Integer> cmp2 = new TComparator<>(items).uorder();
		TComparator<Integer> cmp3 = new TComparator<>(items).hash(1,2,3,4).order(1,2,3,4,5,6,7,8,9,10,11,12);
		items.shuffle(777);
		
		IntRBTreeSet smap1 = new IntRBTreeSet(items.valuesInt(), cmp1);
		IntRBTreeSet smap2 = new IntRBTreeSet(items.valuesInt(), cmp2);
		IntRBTreeSet smap3 = new IntRBTreeSet(items.valuesInt(), cmp3);

		assertEquals(180, smap1.size());
		assertEquals(120, smap2.size());
		assertEquals(12, smap3.size());
		
		Set<Integer> imap = items.into(new TreeSet<>(cmp1));
		
        assertEquals(180, new IntRBTreeSet(imap).size());
        assertEquals(180, new IntRBTreeSet((SortedSet<Integer>)imap).size());
        
        assertEquals(180, new IntRBTreeSet(smap1).size());
        assertEquals(120, new IntRBTreeSet(smap2).size());
        
        assertEquals(180, new IntRBTreeSet(smap1.iterator()).size());
        assertEquals(120, new IntRBTreeSet(smap2.iterator()).size());
        assertEquals(180, new IntRBTreeSet(imap.iterator()).size());
        
        assertEquals(180, new IntRBTreeSet(items.valuesInt(), cmp1).size());
        assertEquals(120, new IntRBTreeSet(items.valuesInt(), cmp2).size());
        assertEquals(12, new IntRBTreeSet(items.valuesInt(), cmp3).size());
        
		assertEquals(180, new IntRBTreeSet(items.valuesInt()).size());
        
        assertEquals(30, new IntRBTreeSet($var.range(180).valuesInt(), 20, 30, $var.comparator()).size());
        assertEquals(30, new IntRBTreeSet(TMaps.MAP_IS.keys().range(180).valuesInt(), 20, 30).size());
        
        assertEquals(180, new IntRBTreeSet((IntSortedSet)smap1).size());
        assertEquals(180, new IntRBTreeSet((IntCollection)smap1).size());
    }
    
    
}
