/*
 * @author Ranides Atterwim {@literal <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.test.data.TMaps;
import net.ranides.test.ContractTesters;
import net.ranides.test.data.TCollection;
import net.ranides.test.data.TCollection.TItems;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

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

        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenSet(32, 0.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenSet(32, -1.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenSet(32, 1.1f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenSet(32, 2.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenSet(-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<>());
        OpenSet<Integer> smap = new OpenSet<>(imap);
        
        assertEquals(60, new IntOpenSet(imap, 0.75f).size());
        assertEquals(60, new IntOpenSet(imap).size());
        
        assertEquals(60, new IntOpenSet(smap, 0.75f).size());
        assertEquals(60, new IntOpenSet(smap).size());

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