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

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;

import net.ranides.test.data.TMapItems;
import net.ranides.test.data.TMaps;
import net.ranides.test.ContractTesters;
import net.ranides.test.data.TComparator;
import net.ranides.test.data.TMap;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public class IntRBTreeMapTest {
    
    private final TMap<Integer, String> $map = TMaps.MAP_IS;
    
    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
			.ignore(Pattern.compile(".*_HC"))
            .function(new int[0], array -> $map.list(array).into(new IntRBTreeMap<>($map.comparator())))
			.run();
    }
    
    @Test
    public void testConstruct() {
        assertNotNull( new IntRBTreeMap<>() );
        assertNotNull( new IntRBTreeMap<>($map.comparator()) );
    }
    
    @Test
    public void testConstructCopy() {
        TMapItems<Integer, String> items = $map.range(180);
        
		TComparator<Integer> cmp1 = new TComparator<>(items);
		TComparator<Integer> cmp2 = new TComparator<>(items).uorder();
		TComparator<Integer> cmp3 = new TComparator<>(items).hash(1,2,3,4).order(1,2,3,4,5,6,7,8,9,10,11,12);
		items.shuffle(777);
		
		IntRBTreeMap<String> smap1 = new IntRBTreeMap<>(items.keysInt(), items.values(), cmp1);
		IntRBTreeMap<String> smap2 = new IntRBTreeMap<>(items.keysInt(), items.values(), cmp2);
		IntRBTreeMap<String> smap3 = new IntRBTreeMap<>(items.keysInt(), items.values(), cmp3);
        IntOpenMap<String> hmap1 = new IntOpenMap<>(items.keysInt(), items.values());

		assertEquals(180, smap1.size());
		assertEquals(120, smap2.size());
		assertEquals(12, smap3.size());
		
		Map<Integer, String> imap = items.into(new TreeMap<>(cmp1));
		
        assertEquals(180, new IntRBTreeMap<>(imap).size());
        assertEquals(180, new IntRBTreeMap<>((SortedMap<Integer, String>)imap).size());
        assertEquals(180, new IntRBTreeMap<>(hmap1).size());
        
        assertEquals(180, new IntRBTreeMap<>(smap1).size());
        assertEquals(120, new IntRBTreeMap<>(smap2).size());
        
        assertEquals(180, new IntRBTreeMap<>(items.keysInt(), items.values(), cmp1).size());
        assertEquals(120, new IntRBTreeMap<>(items.keysInt(), items.values(), cmp2).size());
        assertEquals(12, new IntRBTreeMap<>(items.keysInt(), items.values(), cmp3).size());
        
		assertEquals(180, new IntRBTreeMap<>(items.keysInt(), items.values()).size());

        assertThrows(IllegalArgumentException.class, () -> 
            new IntRBTreeMap<>($map.range(60).keysInt(), $map.range(40).values(), cmp1)
        );
    }

}
