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

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class HashMapTest {
    
    private final TMap<TPoint, Integer> $map = TMaps.MAP_PI;
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
            .function(new int[0], array -> $map.list(array).into(new HashMap<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new HashMap<>(32, 0.75f) );
        assertNotNull( new HashMap<>(32) );
        assertNotNull( new HashMap<>() );

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

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