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

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

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

        assertEquals(120, new OpenLookup<>(items.keys(), items.valuesInt()).size());
  
        assertThrows(IllegalArgumentException.class, () -> 
            new OpenLookup<>($map.range(60).keys(), $map.range(20).valuesInt())
        );
    }
    
}
