/*
 *  @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 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 CrossHashMapTest {
	
	@Test
	public void testBasic() {
		CrossHashMap<String,String,Integer> map = make();
		
		assertEquals(5, map.size());
		
		assertTrue( map.contains("a1","b1"));
		assertTrue( map.contains("a4", "b2"));
		assertFalse( map.contains("a4", "b6"));
		
		assertNull( map.remove("a1", "b6") );
		assertEquals(5, map.remove("a1", "b1").intValue() );
		
		assertNull( map.get("a1", "b6") );
		assertNull( map.get("a1", "b1") );
		assertEquals(8, map.get("a4", "b2").intValue() );
		
		assertEquals(4, map.size());
		assertFalse(map.isEmpty());
		
		map.clear();
		
		assertEquals(0, map.size());
		assertTrue(map.isEmpty());
	}
	
	@Test
	public void testReduceY() {
		CrossHashMap<String,String,Integer> map = make();
		MultiMap<String,Integer> ymap = map.reduceY();
		
		assertEquals(2, ymap.get("a1").size());
		assertTrue( ymap.get("a1").containsAll(Arrays.asList(5,6)) );
		
		assertEquals(3, ymap.get("a4").size());
		assertTrue( ymap.get("a4").containsAll(Arrays.asList(7,8,9)) );
		
	}
	
	@Test
	public void testReduceZ() {
		CrossHashMap<String,String,Integer> map = make();
		MultiMap<String,String> zmap = map.reduceZ();
		
		assertEquals(2, zmap.get("a1").size());
		assertTrue( zmap.get("a1").containsAll(Arrays.asList("b1","b2")) );
		
		assertEquals(3, zmap.get("a4").size());
		assertTrue( zmap.get("a4").containsAll(Arrays.asList("b1","b2","b4")) );
		
	}

	private CrossHashMap<String, String, Integer> make() {
		CrossHashMap<String,String,Integer> map = new CrossHashMap<>();
		map.put("a1", "b1", 5);
		map.put("a1", "b2", 6);
		map.put("a4", "b1", 7);
		map.put("a4", "b2", 8);
		map.put("a4", "b4", 9);
		return map;
	}
	
}
