/*
 * @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 net.ranides.test.data.TMaps;
import net.ranides.test.data.TPoint;
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 OpenSetTest {
    
    
    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 OpenSet<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new OpenSet<>(32, 0.75f) );
        assertNotNull( new OpenSet<>(32) );
        assertNotNull( new OpenSet<>() );

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

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