/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.maps;

import java.util.Map;
import java.util.regex.Pattern;

import net.ranides.test.data.TCollection;
import net.ranides.test.data.TMaps;
import net.ranides.test.ContractTesters;
import net.ranides.test.data.TMap;
import net.ranides.test.data.TMapItems;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public class IntOpenMapTest {
    
    private final TMap<Integer, String> $map = TMaps.MAP_IS;
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
			.ignore(Pattern.compile(".*_HC"))
            .function(new int[0], array -> $map.list(array).into(new IntOpenMap<>(32, 0.75f)))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IntOpenMap<>(32, 0.75f) );
        assertNotNull( new IntOpenMap<>(32) );
        assertNotNull( new IntOpenMap<>() );

        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>(32, 0.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>(32, -1.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>(32, 1.1f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>(32, 2.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>(-1, 0.5f)
        );
    }
    
    @Test
    public void testConstructCopy() {
        TMapItems<Integer, String> items = $map.range(60).item(2).item(3);
        
        Map<Integer, String> imap = items.into(new java.util.HashMap<>());
        OpenMap<Integer, String> smap = new OpenMap<>(imap);
        
        assertEquals(60, new IntOpenMap<>(imap, 0.75f).size());
        assertEquals(60, new IntOpenMap<>(imap).size());
        
        assertEquals(60, new IntOpenMap<>(smap, 0.75f).size());
        assertEquals(60, new IntOpenMap<>(smap).size());
        
        assertEquals(60, new IntOpenMap<>(new IntOpenMap<>(smap), 0.75f).size());
        assertEquals(60, new IntOpenMap<>(new IntOpenMap<>(smap)).size());

        assertEquals(60, new IntOpenMap<>(items.keysInt(), items.values()).size());
        
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMap<>($map.range(60).keysInt(), $map.range(40).values())
        );
    }
    
}
