public void TestConstructorMap() { Map <Object, Object> myMap = new LinkedHashMap <Object, Object>(); for (int counter = 0; counter < hmSize; counter++) { myMap.Put(objArray2[counter], objArray[counter]); } HashMap <Object, Object> hm2 = new HashMap <Object, Object>(myMap); for (int counter = 0; counter < hmSize; counter++) { Assert.IsTrue(hm.Get(objArray2[counter]) == hm2.Get(objArray2[counter]), "Assert.Failed to construct correct HashMap"); } try { Map <Object, Object> mockMap = new MockMap(); hm = new HashMap <Object, Object>(mockMap); Assert.Fail("Should throw NullReferenceException"); } catch (NullReferenceException) { //empty } HashMap <Object, Object> map = new HashMap <Object, Object>(); map.Put("a", "a"); SubMap <Object, Object> map2 = new SubMap <Object, Object>(map); Assert.IsTrue(map2.ContainsKey("a")); Assert.IsTrue(map2.ContainsValue("a")); }
public void TestCloneMock() { LinkedHashMap <Object, Object> hashMap = new MockMap(); String value = "value a"; hashMap.Put("key", value); MockMap cloneMap = (MockMap)hashMap.Clone(); Assert.AreEqual(value, cloneMap.Get("key")); Assert.AreEqual(hashMap, cloneMap); Assert.AreEqual(1, cloneMap.Num); hashMap.Put("key", "value b"); Assert.IsFalse(hashMap.Equals(cloneMap)); }
public void TestPutAll() { HashMap <Object, Object> hm2 = new HashMap <Object, Object>(); hm2.PutAll(hm); for (int i = 0; i < 1000; i++) { Assert.IsTrue(hm2.Get(i.ToString()).Equals((i)), "Assert.Failed to Clear all elements"); } Map <Object, Object> mockMap = new MockMap(); hm2 = new HashMap <Object, Object>(); hm2.PutAll(mockMap); Assert.AreEqual(0, hm2.Size(), "Size should be 0"); }