void HashMapTest::testInsert() { const int N = 1000; typedef HashMap<int, int> IntMap; IntMap hm; assert (hm.empty()); for (int i = 0; i < N; ++i) { std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2)); assert (res.first->first == i); assert (res.first->second == i*2); assert (res.second); IntMap::Iterator it = hm.find(i); assert (it != hm.end()); assert (it->first == i); assert (it->second == i*2); assert (hm.count(i) == 1); assert (hm.size() == i + 1); } assert (!hm.empty()); for (int i = 0; i < N; ++i) { IntMap::Iterator it = hm.find(i); assert (it != hm.end()); assert (it->first == i); assert (it->second == i*2); } for (int i = 0; i < N; ++i) { std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0)); assert (res.first->first == i); assert (res.first->second == i*2); assert (!res.second); } }
void ListMapTest::testInsert() { const int N = 1000; typedef ListMap<int, int> IntMap; IntMap hm; assert (hm.empty()); for (int i = 0; i < N; ++i) { IntMap::Iterator res = hm.insert(IntMap::ValueType(i, i*2)); assert (res->first == i); assert (res->second == i*2); IntMap::Iterator it = hm.find(i); assert (it != hm.end()); assert (it->first == i); assert (it->second == i*2); assert (hm.size() == i + 1); } assert (!hm.empty()); for (int i = 0; i < N; ++i) { IntMap::Iterator it = hm.find(i); assert (it != hm.end()); assert (it->first == i); assert (it->second == i*2); } hm.clear(); for (int i = 0; i < N; ++i) { IntMap::Iterator res = hm.insert(IntMap::ValueType(i, 0)); assert (res->first == i); assert (res->second == 0); } }