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

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

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

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