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

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class IdentSetTest {
    
    private final TCollection<TPoint> $var = TMaps.MAP_PI.keys().asIdentity();
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("collection!", $var)
			.ignore(Pattern.compile(".*_HC"))
            .ignore("SetTester.basicSerializable")
            .function(new int[0], array -> $var.list(array).into(new IdentSet<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IdentSet<>(32, 0.75f) );
        assertNotNull( new IdentSet<>(32) );
        assertNotNull( new IdentSet<>() );

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

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