/*
 * @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 net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.collection.mockup.TPoint;
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 HashMultiMapTest {
    
    private final TMap<TPoint, Integer> $map = TMaps.MAP_PI;
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
            .ignore("MapTester.basicEquals_HC")
            .supplier(() -> new HashMultiMap<>())
            .function(new int[0], array -> $map.list(array).into(new HashMultiMap<>()))
			.run();
    }

    @Test
    public void testConstruct() {
        assertNotNull( new HashMultiMap<>(32, 0.75f) );
        assertNotNull( new HashMultiMap<>(32) );
        assertNotNull( new HashMultiMap<>() );

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

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