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

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

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

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