示例#1
0
	void visit(StringHashMap<int>& map)
	{
		StringHashMap<int>::Iterator it = map.begin();
		for (; it != map.end(); ++it)
		{
			value_sum += (*it).second;
		}
	}
示例#2
0
	TEST_EQUAL(hm.getSize(), 1)
	hm.insert("a", 1);
	TEST_EQUAL(hm.getSize(), 1)
	hm.insert("b", 0);
	TEST_EQUAL(hm.getSize(), 2)
	hm.insert("b", 1);
	TEST_EQUAL(hm.getSize(), 2)
RESULT

// testing inherited method function
CHECK([EXTRA] find(const String& key))
	StringHashMap<int> hm;
	TEST_EQUAL((hm.find("a") == hm.end()), true)
	hm.insert("a", 0);
	TEST_EQUAL((hm.find("a") == hm.end()), false)
	TEST_EQUAL((hm.find("a") == hm.begin()), true)
	hm.insert("b", 1);
	TEST_EQUAL((hm.find("a") == hm.end()), false)
	TEST_EQUAL((hm.find("b") == hm.end()), false)
	TEST_EQUAL((hm.find("c") == hm.end()), true)
RESULT

CHECK([EXTRA]StringHashMap::erase(const KeyType& key))
	StringHashMap<int> hm;
	hm.insert("a", 0);
	hm.insert("b", 1);
	hm.insert("c", 2);
	hm.erase("a");
	TEST_EQUAL(hm.has("a"), false)
	TEST_EQUAL(hm.has("b"), true)
	TEST_EQUAL(hm.has("c"), true)