/*
 * @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 IntAVLTreeSetTest {
    
    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 IntAVLTreeSet($var.comparator())))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IntAVLTreeSet() );
        assertNotNull( new IntAVLTreeSet($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);
		
		IntAVLTreeSet smap1 = new IntAVLTreeSet(items.valuesInt(), cmp1);
		IntAVLTreeSet smap2 = new IntAVLTreeSet(items.valuesInt(), cmp2);
		IntAVLTreeSet smap3 = new IntAVLTreeSet(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 IntAVLTreeSet(imap).size());
        assertEquals(180, new IntAVLTreeSet((SortedSet<Integer>)imap).size());
        
        assertEquals(180, new IntAVLTreeSet(smap1).size());
        assertEquals(120, new IntAVLTreeSet(smap2).size());
        
        assertEquals(180, new IntAVLTreeSet(smap1.iterator()).size());
        assertEquals(120, new IntAVLTreeSet(smap2.iterator()).size());
        assertEquals(180, new IntAVLTreeSet(imap.iterator()).size());
        
        assertEquals(180, new IntAVLTreeSet(items.valuesInt(), cmp1).size());
        assertEquals(120, new IntAVLTreeSet(items.valuesInt(), cmp2).size());
        assertEquals(12, new IntAVLTreeSet(items.valuesInt(), cmp3).size());
        
		assertEquals(180, new IntAVLTreeSet(items.valuesInt()).size());
        
        assertEquals(30, new IntAVLTreeSet($var.range(180).valuesInt(), 20, 30, $var.comparator()).size());
        assertEquals(30, new IntAVLTreeSet(TMaps.MAP_IS.keys().range(180).valuesInt(), 20, 30).size());
        
        assertEquals(180, new IntAVLTreeSet((IntSortedSet)smap1).size());
        assertEquals(180, new IntAVLTreeSet((IntCollection)smap1).size());
    }
    
}
