use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method test_values.
/**
* java.util.IdentityHashMap#values()
*/
public void test_values() {
// Test for method java.util.Collection
// java.util.IdentityHashMap.values()
Collection c = hm.values();
assertTrue("Returned collection of incorrect size()", c.size() == hm.size());
for (int i = 0; i < objArray.length; i++) assertTrue("Returned collection does not contain all keys", c.contains(objArray[i]));
IdentityHashMap myIdentityHashMap = new IdentityHashMap();
for (int i = 0; i < 100; i++) myIdentityHashMap.put(objArray2[i], objArray[i]);
Collection values = myIdentityHashMap.values();
values.remove(objArray[0]);
assertTrue("Removing from the values collection should remove from the original map", !myIdentityHashMap.containsValue(objArray2[0]));
}
use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method test_removeLjava_lang_Object.
/**
* java.util.IdentityHashMap#remove(java.lang.Object)
*/
public void test_removeLjava_lang_Object() {
// Test for method java.lang.Object
// java.util.IdentityHashMap.remove(java.lang.Object)
int size = hm.size();
Integer x = ((Integer) hm.remove(objArray2[9]));
assertTrue("Remove returned incorrect value", x.equals(new Integer(9)));
assertNull("Failed to remove given key", hm.get(objArray2[9]));
assertTrue("Failed to decrement size", hm.size() == (size - 1));
assertNull("Remove of non-existent key returned non-null", hm.remove("LCLCLC"));
IdentityHashMap m = new IdentityHashMap();
m.put(null, "test");
assertNull("Failed with same hash as null", m.remove(objArray[0]));
assertEquals("Failed with null key", "test", m.remove(null));
}
use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method test_containsKeyLjava_lang_Object.
/**
* java.util.IdentityHashMap#containsKey(java.lang.Object)
*/
public void test_containsKeyLjava_lang_Object() {
// Test for method boolean
// java.util.IdentityHashMap.containsKey(java.lang.Object)
assertTrue("Returned false for valid key", hm.containsKey(objArray2[23]));
assertTrue("Returned true for copy of valid key", !hm.containsKey(new Integer(23).toString()));
assertTrue("Returned true for invalid key", !hm.containsKey("KKDKDKD"));
IdentityHashMap m = new IdentityHashMap();
m.put(null, "test");
assertTrue("Failed with null key", m.containsKey(null));
assertTrue("Failed with missing key matching null hash", !m.containsKey(new Integer(0)));
}
use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method setUp.
/**
* Sets up the fixture, for example, open a network connection. This method
* is called before a test is executed.
*/
protected void setUp() {
objArray = new Object[hmSize];
objArray2 = new Object[hmSize];
for (int i = 0; i < objArray.length; i++) {
objArray[i] = new Integer(i);
// android-changed: the containsKey test requires unique strings.
objArray2[i] = new String(objArray[i].toString());
}
hm = new IdentityHashMap();
for (int i = 0; i < objArray.length; i++) hm.put(objArray2[i], objArray[i]);
hm.put("test", null);
hm.put(null, "test");
}
use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method test_equalsLjava_lang_Object.
/**
* java.util.IdentityHashMap#equals(java.lang.Object)
*/
public void test_equalsLjava_lang_Object() {
IdentityHashMap mapOne = new IdentityHashMap();
IdentityHashMap mapTwo = new IdentityHashMap();
IdentityHashMap mapThree = new IdentityHashMap();
IdentityHashMap mapFour = new IdentityHashMap();
String one = "one";
// use the new operator to ensure a
String alsoOne = new String(one);
// new reference is constructed
String two = "two";
// use the new operator to ensure a
String alsoTwo = new String(two);
// new reference is constructed
mapOne.put(one, two);
mapFour.put(one, two);
// these two are not equal to the above two
mapTwo.put(alsoOne, two);
mapThree.put(one, alsoTwo);
assertEquals("failure of equality of IdentityHashMaps", mapOne, mapFour);
assertTrue("failure of non-equality of IdentityHashMaps one and two", !mapOne.equals(mapTwo));
assertTrue("failure of non-equality of IdentityHashMaps one and three", !mapOne.equals(mapThree));
assertTrue("failure of non-equality of IdentityHashMaps two and three", !mapTwo.equals(mapThree));
HashMap hashMapTwo = new HashMap();
HashMap hashMapThree = new HashMap();
hashMapTwo.put(alsoOne, two);
hashMapThree.put(one, alsoTwo);
assertTrue("failure of non-equality of IdentityHashMaps one and Hashmap two", !mapOne.equals(hashMapTwo));
assertTrue("failure of non-equality of IdentityHashMaps one and Hashmap three", !mapOne.equals(hashMapThree));
}
Aggregations