/*
 * @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 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 net.ranides.assira.test.TComparator;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class AVLTreeSetTest {
    
    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 AVLTreeSet<>($var.comparator())))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new AVLTreeSet<>() );
        assertNotNull( new AVLTreeSet<>($var.comparator()) );
    }
    
    @Test
    public void testConstructCopy() {
        TCollection.TItems<TPoint> items = $var.range(180);
        
		TComparator<TPoint> cmp1 = new TComparator<>(items);
		TComparator<TPoint> cmp2 = new TComparator<>(items).uorder();
		TComparator<TPoint> 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);
		
		AVLTreeSet<TPoint> smap1 = new AVLTreeSet<>(items.values(), cmp1);
		AVLTreeSet<TPoint> smap2 = new AVLTreeSet<>(items.values(), cmp2);
		AVLTreeSet<TPoint> smap3 = new AVLTreeSet<>(items.values(), cmp3);

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