/*
 * @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.regex.Pattern;
import net.ranides.assira.collection.lists.IntArrayList;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.test.TCollection;
import net.ranides.assira.test.TCollection.TItems;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

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

        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashSet(32, 0.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashSet(32, -1.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashSet(32, 1.1f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashSet(32, 2.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashSet(-1, 0.5f)
        );
    }
    
    @Test
    public void testConstructCopy() {
        TItems<Integer> items = $var.range(60).item(2).item(3);
        
        Set<Integer> imap = items.into(new java.util.HashSet<>());
        HashSet<Integer> smap = new HashSet<>(imap);
        
        assertEquals(60, new IntHashSet(imap, 0.75f).size());
        assertEquals(60, new IntHashSet(imap).size());
        
        assertEquals(60, new IntHashSet(smap, 0.75f).size());
        assertEquals(60, new IntHashSet(smap).size());

        assertEquals(60, new IntHashSet(items.valuesInt()).size());
        assertEquals(30, new IntHashSet(items.valuesInt(), 10, 30).size());
        
        assertEquals(60, new IntHashSet(new IntArrayList(imap), 0.75f).size());
        assertEquals(60, new IntHashSet(new IntArrayList(imap)).size());
        
        assertEquals(60, new IntHashSet(imap.iterator()).size());
        assertEquals(60, new IntHashSet(imap.iterator(), 0.75f).size());
        
        assertEquals(60, new IntHashSet(new IntArrayList(imap).iterator()).size());
        assertEquals(60, new IntHashSet(new IntArrayList(imap).iterator(), 0.75f).size());
    }
    
}
