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

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

        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMultiMap<>(32, 0.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMultiMap<>(32, -1.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMultiMap<>(32, 1.1f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMultiMap<>(32, 2.0f)
        );
        assertThrows(IllegalArgumentException.class, () -> 
            new IntOpenMultiMap<>(-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 IntOpenMultiMap<>(imap, 0.75f).size());
        assertEquals(60, new IntOpenMultiMap<>(imap).size());
        
        assertEquals(60, new IntOpenMultiMap<>(smap, 0.75f).size());
        assertEquals(60, new IntOpenMultiMap<>(smap).size());
        
        assertEquals(60, new IntOpenMultiMap<>(new IntOpenMultiMap<>(smap), 0.75f).size());
        assertEquals(60, new IntOpenMultiMap<>(new IntOpenMultiMap<>(smap)).size());

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