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

import java.io.Serializable;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Pattern;
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.TWrapper;
import org.junit.Test;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class MapUtilsTest {
    
    @Test
    public void testMap_Projection() {
        TMap<TPoint, Integer> tmap = TMaps.MAP_PI;
        
        Function<int[], Map<TPoint, Integer>> gf = (Function<int[], Map<TPoint, Integer>> & Serializable)(int[] array) -> {
            Map<TPoint, TWrapper<Integer>> mmap = new HashMap<>();
            TWrapper.into(mmap, tmap.list(array));
            return MapUtils.map(mmap, TWrapper.projection());
        };
        
        ContractTesters.runner()
            .param("map!", tmap)
            .function(new int[0], gf)
			.run();
        
    }
    
    @Test
    public void testMap_Function() {
        TMap<TPoint, Integer> tmap = TMaps.MAP_PI;
        
        Function<int[], Map<TPoint, Integer>> gf = (Function<int[], Map<TPoint, Integer>> & Serializable)(int[] array) -> {
            Map<TPoint, TWrapper<Integer>> mmap = new HashMap<>();
            TWrapper.into(mmap, tmap.list(array));
            return MapUtils.map(mmap, TWrapper.unwrap());
        };
        
        ContractTesters.runner()
            .ignore(Pattern.compile(".*_HC"))
            .ignore("MapTester.basicEntrySet_Iterator_SetValue")
            .ignore("MapTester.basicPut")
            .ignore("MapTester.basicPutRandom")
            .ignore("MapTester.basicPutReplace")
            .param("map!", tmap)
            .function(new int[0], gf)
			.run();
        
    }
       
}
