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

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

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

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