/*
 * @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 java.util.regex.Pattern;
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 IdentMapTest {
    
    private final TMap<TPoint, Integer> $map = TMaps.MAP_PI.asIdentity();
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
			.ignore(Pattern.compile(".*_HC"))
            .ignore("MapTester.basicSerializable")
            .function(new int[0], array -> $map.list(array).into(new IdentMap<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IdentMap<>(32, 0.75f) );
        assertNotNull( new IdentMap<>(32) );
        assertNotNull( new IdentMap<>() );

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

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