void LinkedHashMapTest::testClear() { LinkedHashMap<int, std::string> hashMap; hashMap.put(1, "one"); hashMap.put(3, "three"); hashMap.put(2, "two"); hashMap.clear(); CPPUNIT_ASSERT_EQUAL_MESSAGE("Clear failed to reset size", 0, hashMap.size()); for (int i = 0; i < 125; i++) { CPPUNIT_ASSERT_THROW_MESSAGE( "Failed to clear all elements", hashMap.get(i), NoSuchElementException); } // Check clear on a large loaded map of Integer keys LinkedHashMap<int, std::string> map; for (int i = -32767; i < 32768; i++) { map.put(i, "foobar"); } map.clear(); CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to reset size on large integer map", 0, map.size()); for (int i = -32767; i < 32768; i++) { CPPUNIT_ASSERT_THROW_MESSAGE( "Failed to clear all elements", map.get(i), NoSuchElementException); } }
void LinkedHashMapTest::testIsEmpty() { LinkedHashMap<int, std::string> hashMap; CPPUNIT_ASSERT_MESSAGE("Returned false for new map", hashMap.isEmpty()); hashMap.put(1, "1"); CPPUNIT_ASSERT_MESSAGE("Returned true for non-empty", !hashMap.isEmpty()); hashMap.clear(); CPPUNIT_ASSERT_MESSAGE("Returned false for cleared map", hashMap.isEmpty()); }