package net.ranides.assira.collection.maps;

import net.ranides.assira.collection.prototype.GenericKey;
import net.ranides.assira.collection.prototype.GenericMap;
import net.ranides.assira.collection.prototype.OpenGenericMap;
import net.ranides.test.contracts.collection.maps.GenericMapTester;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class OpenGenericMapTest {

    @Test
    public void basic() {
        GenericMapTester.basic(OpenGenericMap::new);
    }

    @Test
    public void contains() {
        GenericMapTester.contains(OpenGenericMap::new);
    }

    @Test
    public void entries() {
        GenericMapTester.entries(OpenGenericMap::new);
    }

    @Test
    public void views() {
        GenericMapTester.views(OpenGenericMap::new);
    }

    @Test
    public void setEntry() {
        GenericMapTester.setEntry(OpenGenericMap::new);
    }

    @Test
    public void keyInstance() {
        GenericMap<String> map = new OpenGenericMap<>();
        map.put(GenericKey.of(Integer.class, "a"), 1);
        map.put(GenericKey.of(Float.class, "b"), 2.0f);

        assertEquals(Integer.valueOf(1), map.get(GenericKey.of(Integer.class, "a")));
        assertEquals(1, map.get(GenericKey.of(Number.class, "a")));
        assertEquals(1, map.get(GenericKey.of("a")));
    }
}