/*
 * @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.TreeMap;
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 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 HashLookup<>()))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new HashLookup<>(32, 0.75f) );
        assertNotNull( new HashLookup<>(32) );
        assertNotNull( new HashLookup<>() );

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

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