/*
 * @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.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;
import net.ranides.assira.collection.mockup.TMaps;
import net.ranides.assira.ContractTesters;
import net.ranides.assira.test.TComparator;
import net.ranides.assira.test.TMap;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class IntAVLTreeMapTest {
    
    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 IntAVLTreeMap<>($map.comparator())))
			.run();
    }

    @Test
    public void testConstruct() {
        assertNotNull( new IntAVLTreeMap<>() );
        assertNotNull( new IntAVLTreeMap<>($map.comparator()) );
    }
    
    @Test
    public void testConstructCopy() {
        TMap.TItems<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);
		
		IntAVLTreeMap<String> smap1 = new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp1);
		IntAVLTreeMap<String> smap2 = new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp2);
		IntAVLTreeMap<String> smap3 = new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp3);
		IntHashMap<String> hmap1 = new IntHashMap<>(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 IntAVLTreeMap<>(imap).size());
        assertEquals(180, new IntAVLTreeMap<>((SortedMap<Integer, String>)imap).size());
        assertEquals(180, new IntAVLTreeMap<>(hmap1).size());
        
        assertEquals(180, new IntAVLTreeMap<>(smap1).size());
        assertEquals(120, new IntAVLTreeMap<>(smap2).size());
        
        assertEquals(180, new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp1).size());
        assertEquals(120, new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp2).size());
        assertEquals(12, new IntAVLTreeMap<>(items.keysInt(), items.values(), cmp3).size());
        
		assertEquals(180, new IntAVLTreeMap<>(items.keysInt(), items.values()).size());

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