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

import net.ranides.assira.ContractTesters;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.collection.mockup.TPoint;
import net.ranides.assira.collection.sets.HashSet;
import net.ranides.assira.collection.utils.CollectionSort;
import net.ranides.assira.test.TCollection.TItems;
import net.ranides.assira.test.TMap;
import org.junit.Test;

import java.util.List;
import java.util.regex.Pattern;

import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ArrayMapTest {

    private final TMap<TPoint, Integer> $map = TMaps.MAP_PI;


    @Test
    public void testBasics() throws Exception {
        TItems<TPoint> keys = $map.keys().range(32).shuffle(5);
        TItems<Integer> values = $map.values().range(32).shuffle(5);

        ArrayMap<TPoint, Integer> map = new ArrayMap<>(
            keys.values(), values.values(), $map.comparator()
        );

        List<TPoint> ekeys = keys.intoList();
        List<Integer> evalues = values.intoList();

        CollectionSort.sort($map.comparator(), ekeys, evalues);

        assertEquals("[(0:0:0), (1:1:10), (2:2:20), (3:3:30), (4:4:40), (5:5:50), (6:6:60), (7:7:70), (8:8:80), (9:9:90), (10:10:100), (11:11:110), (12:12:120), (13:13:130), (14:14:140), (15:15:150), (16:16:160), (17:17:170), (18:18:180), (19:19:190), (20:20:200), (21:21:210), (22:22:220), (23:23:230), (24:24:240), (25:25:250), (26:26:260), (27:27:270), (28:28:280), (29:29:290), (30:30:300), (31:31:310)]", ekeys.toString());
        assertEquals("[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310]",evalues.toString());

        assertEquals(new HashSet<>(ekeys), map.keySet());
        assertEquals(evalues, map.values());
    }

    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
            .function(new int[0], array -> new ArrayMap<>($map.keys().list(array).values(), $map.values().list(array).values(), $map.comparator()))
            .ignore("MapTester.basicEntrySet_Iterator_RemoveAll")
            .ignore("MapTester.basicEntrySet_Iterator_SetValue")
            .ignore(Pattern.compile("MapTester\\..*Remove"))
            .ignore(Pattern.compile("MapTester\\.basicPut.*"))
            .ignore(Pattern.compile("MapTester\\.basicRemove.*"))
            .ignore(Pattern.compile("MapTester\\.basicClear.*"))
            .ignore(Pattern.compile(".*_HC"))
            .run();
    }

    @Test
    public void testMap() {
        ArrayMap<String, Integer> map = new ArrayMap<>(
                new String[]{"a","b","c","d","e"},
                new Integer[]{71,62,53,24,15}
        );
        
        assertEquals(62, map.get("b").intValue());
        assertEquals(15, map.get("e").intValue());
        assertEquals(71, map.get("a").intValue());
        assertEquals(null, map.get("q"));
    }
    
}
