Exemplo n.º 1
0
static bool MapsAreEqual(IntMap& am, IntMap& bm) {
  bool equal = true;
  if (am.count() != bm.count()) {
    equal = false;
    fprintf(stderr, "A.count() == %u and B.count() == %u\n", am.count(),
            bm.count());
  }
  for (auto iter = am.iter(); !iter.done(); iter.next()) {
    if (!bm.has(iter.get().key())) {
      equal = false;
      fprintf(stderr, "B does not have %x which is in A\n", iter.get().key());
    }
  }
  for (auto iter = bm.iter(); !iter.done(); iter.next()) {
    if (!am.has(iter.get().key())) {
      equal = false;
      fprintf(stderr, "A does not have %x which is in B\n", iter.get().key());
    }
  }
  return equal;
}
Exemplo n.º 2
0
static bool
MapsAreEqual(IntMap& am, IntMap& bm)
{
    bool equal = true;
    if (am.count() != bm.count()) {
        equal = false;
        fprintf(stderr, "A.count() == %u and B.count() == %u\n", am.count(), bm.count());
    }
    for (IntMap::Range r = am.all(); !r.empty(); r.popFront()) {
        if (!bm.has(r.front().key())) {
            equal = false;
            fprintf(stderr, "B does not have %x which is in A\n", r.front().key());
        }
    }
    for (IntMap::Range r = bm.all(); !r.empty(); r.popFront()) {
        if (!am.has(r.front().key())) {
            equal = false;
            fprintf(stderr, "A does not have %x which is in B\n", r.front().key());
        }
    }
    return equal;
}
Exemplo n.º 3
0
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);
	}		
}