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

import java.util.Arrays;
import net.ranides.assira.collection.SetUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author ranides
 */
public class CrossEnumMapTest {
	
	@Test
	public void testBasic() {
		CrossEnumMap<A,B,Integer> map = make();
		
		assertEquals(5, map.size());
		
		assertTrue( map.contains(A.A1, B.B1));
		assertTrue( map.contains(A.A4, B.B2));
		assertFalse( map.contains(A.A4, B.B6));
		
		assertNull( map.remove(A.A1, B.B6) );
		assertEquals(5, map.remove(A.A1, B.B1).intValue() );
		
		assertNull( map.get(A.A1, B.B6) );
		assertNull( map.get(A.A1, B.B1) );
		assertEquals(8, map.get(A.A4, B.B2).intValue() );
		
		assertEquals(4, map.size());
		assertFalse(map.isEmpty());
		
		map.clear();
		
		assertEquals(0, map.size());
		assertTrue(map.isEmpty());
	}
	
	@Test
	public void testReduceY() {
		CrossEnumMap<A,B,Integer> map = make();
		MultiMap<A,Integer> ymap = map.reduceY();
		
		assertEquals(2, ymap.get(A.A1).size());
		assertTrue( ymap.get(A.A1).containsAll(Arrays.asList(5,6)) );
		
		assertEquals(3, ymap.get(A.A4).size());
		assertTrue( ymap.get(A.A4).containsAll(Arrays.asList(7,8,9)) );
		
	}
	
	@Test
	public void testReduceZ() {
		CrossEnumMap<A,B,Integer> map = make();
		MultiMap<A,B> zmap = map.reduceZ();
		
		assertEquals(2, zmap.get(A.A1).size());
		assertTrue( zmap.get(A.A1).containsAll(Arrays.asList(B.B1,B.B2)) );
		
		assertEquals(3, zmap.get(A.A4).size());
		assertTrue( zmap.get(A.A4).containsAll(Arrays.asList(B.B1, B.B2, B.B4)) );
		
	}

	private CrossEnumMap<A, B, Integer> make() {
		CrossEnumMap<A,B,Integer> map = new CrossEnumMap<>(A.class, B.class);
		map.put(A.A1, B.B1, 5);
		map.put(A.A1, B.B2, 6);
		map.put(A.A4, B.B1, 7);
		map.put(A.A4, B.B2, 8);
		map.put(A.A4, B.B4, 9);
		return map;
	}
	
	
	
	public enum A { A1, A2, A3, A4 }
	
	public enum B { B1, B2, B3, B4, B5, B6 }
	
}
