package com.michaelthomas.map.hashmap;

/**
 * @author Michael Thomas (www.michael-thomas.com) michael@michael-thomas.com
 * 
 */

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import com.michaelthomas.map.MyMapTraverse;

public class MyHashMapTest {

	private MyHashMap myMapObj = new MyHashMap();
	private MyMapTraverse myMapTraverseObj = new MyMapTraverse();
	private HashMap<String, String> mapWeekDays = new HashMap<String, String>();
	private HashMap<String, String> mapAbbr = new HashMap<String, String>();
	private HashMap<String, String> mapPlay = new HashMap<String, String>();
	
	@Before
	public void setUp() throws Exception {
		mapWeekDays = myMapObj.buildMapWeekDays();
		mapAbbr = myMapObj.buildMapAbbreviations();
	}
	
	@Test
	public void testHashMapNotes(){
		//PLEASE READ THIS!
		//NOTE: Make sure that you look at the following JUnit test for a fairly complete
		//      coverage of all the methods of the Map interface.
		//      /collections/test/com/michaelthomas/map/MyMapTest.java
	}
	
	@Test
	public void testHashMapCommonUses(){

		//Most common uses:
		Map<String, String> mapPlay2 = new HashMap<String, String>();
		mapPlay2.put("NY", "New York");
		mapPlay2.put("LA", "Louisiana");
		mapPlay2.put("GA", "Georgia");
		
		assertEquals("Georgia", mapPlay2.get("GA"));
		assertEquals(3, mapPlay2.size());
		
	}
	
	@Test
	public void testHashMapCommonWeekDays(){
		assertEquals("Monday", mapWeekDays.get("Mon"));
		assertEquals(7, mapWeekDays.size());
	}

	@Test
	public void testHashMapCommonPutAll(){
		mapPlay.clear();
		assertEquals(0, mapPlay.size());
		mapPlay.putAll(mapWeekDays);
		assertEquals(7, mapPlay.size());
		mapPlay.putAll(mapAbbr);
		assertEquals(10, mapPlay.size());
		assertEquals("Monday", mapPlay.get("Mon"));
		assertEquals("Element", mapPlay.get("E"));
	}
	
	@Test
	public void testLinkedHashMapTraverseForEachExample() {
		//Note: The order is NOT guaranteed for HashMap.
		assertEquals("Thu = Thursday, Wed = Wednesday, Sun = Sunday, Sat = Saturday, Fri = Friday, Tue = Tuesday, Mon = Monday", 
				     myMapTraverseObj.forEachExampleEntrySet(mapWeekDays));
		
	}

}