/*
 * @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.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 net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class CustomSetTest {
    
    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 CustomSet<>($var.comparator())))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new CustomSet<>(32, 0.75f, $var.comparator()) );
        assertNotNull( new CustomSet<>(32, $var.comparator()) );
        assertNotNull( new CustomSet<>($var.comparator()) );

        assertThrows(IllegalArgumentException.class, () -> 
            new CustomSet<>(32, 0.0f, $var.comparator())
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new CustomSet<>(32, -1.0f, $var.comparator())
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new CustomSet<>(32, 1.1f, $var.comparator())
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new CustomSet<>(32, 2.0f, $var.comparator())
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new CustomSet<>(-1, 0.5f, $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);
        Set<TPoint> imap = items.into(new TreeSet<>(cmp1));
        
        assertEquals(180, new CustomSet<>(imap, $var.comparator()).size());
        
        assertEquals(180, new CustomSet<>(new CustomSet<>(imap, cmp1), cmp1).size());
        assertEquals(120, new CustomSet<>(new CustomSet<>(imap, cmp1), cmp2).size());
        assertEquals(12, new CustomSet<>(new CustomSet<>(imap, cmp1), cmp3).size());
        assertEquals(120, new CustomSet<>(new CustomSet<>(imap, cmp2), cmp1).size());
        assertEquals(120, new CustomSet<>(new CustomSet<>(imap, cmp2), cmp2).size());
        assertEquals(12, new CustomSet<>(new CustomSet<>(imap, cmp2), cmp3).size());
        assertEquals(12, new CustomSet<>(new CustomSet<>(imap, cmp3), cmp1).size());
        assertEquals(12, new CustomSet<>(new CustomSet<>(imap, cmp3), cmp2).size());
        assertEquals(12, new CustomSet<>(new CustomSet<>(imap, cmp3), cmp3).size());
        
        assertEquals(120, new CustomSet<>(items.values(), cmp2).size());
        assertEquals(30, new CustomSet<>(items.values(), 10, 30, cmp1).size());
        
        assertEquals(180, new CustomSet<>(imap.iterator(), cmp1).size());
        assertEquals(120, new CustomSet<>(imap.iterator(), cmp2).size());
        assertEquals(12, new CustomSet<>(imap.iterator(), cmp3).size());
        
        assertEquals(180, new CustomSet<>(imap.iterator(), 0.75f, cmp1).size());
        assertEquals(120, new CustomSet<>(imap.iterator(), 0.75f, cmp2).size());
        assertEquals(12, new CustomSet<>(imap.iterator(), 0.75f, cmp3).size());
        
        
        
    }
    
}
