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

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

        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashMultiMap<>(32, 0.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashMultiMap<>(32, -1.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashMultiMap<>(32, 1.1f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashMultiMap<>(32, 2.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntHashMultiMap<>(-1, 0.5f)
        );
    }
    
    @Test
    public void testConstructCopy() {
        TMap.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 IntHashMultiMap<>(imap, 0.75f).size());
        assertEquals(60, new IntHashMultiMap<>(imap).size());
        
        assertEquals(60, new IntHashMultiMap<>(smap, 0.75f).size());
        assertEquals(60, new IntHashMultiMap<>(smap).size());
        
        assertEquals(60, new IntHashMultiMap<>(new IntHashMultiMap<>(smap), 0.75f).size());
        assertEquals(60, new IntHashMultiMap<>(new IntHashMultiMap<>(smap)).size());

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