/*
 * @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 net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.collection.mockup.TPoint;
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 HashSetTest {
    
    
    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 HashSet<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new HashSet<>(32, 0.75f) );
        assertNotNull( new HashSet<>(32) );
        assertNotNull( new HashSet<>() );

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

        assertEquals(120, new HashSet<>(items.values()).size());
        assertEquals(30, new HashSet<>($var.range(70).values(), 10, 30).size());
        
        assertEquals(120, new HashSet<>(imap.iterator()).size());
        assertEquals(120, new HashSet<>(imap.iterator(), 0.75f).size());
    }
    
}
