/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.lookups;

import java.util.Map;
import java.util.regex.Pattern;
import net.ranides.assira.collection.maps.HashMap;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.collection.mockup.TPoint;
import net.ranides.assira.test.TMap;
import net.ranides.assira.test.TMap.TItems;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

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

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

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