aboutsummaryrefslogtreecommitdiff
path: root/test/common/hashmap.h
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-09-22 12:49:32 +0000
committerWillem Jan Palenstijn2009-09-22 12:49:32 +0000
commit46511f3c63039912794ee9c5a41b3164498731f4 (patch)
tree3eaaa69a05bb9d0caf61d667ad125323654a140b /test/common/hashmap.h
parentf9909bfbf5f813a1d80e07e1844162f36a6980c4 (diff)
downloadscummvm-rg350-46511f3c63039912794ee9c5a41b3164498731f4.tar.gz
scummvm-rg350-46511f3c63039912794ee9c5a41b3164498731f4.tar.bz2
scummvm-rg350-46511f3c63039912794ee9c5a41b3164498731f4.zip
Add basic test for HashMap::iterator
svn-id: r44259
Diffstat (limited to 'test/common/hashmap.h')
-rw-r--r--test/common/hashmap.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/common/hashmap.h b/test/common/hashmap.h
index 03db5518c0..b90d91467c 100644
--- a/test/common/hashmap.h
+++ b/test/common/hashmap.h
@@ -168,6 +168,38 @@ class HashMapTestSuite : public CxxTest::TestSuite
TS_ASSERT(h.empty());
}
+ void test_iterator() {
+ Common::HashMap<int, int> container;
+ container[0] = 17;
+ container[1] = 33;
+ container[2] = 45;
+ container[3] = 12;
+ container[4] = 96;
+ container.erase(1);
+ container[1] = 42;
+ container.erase(0);
+ container.erase(1);
+
+ int found = 0;
+ Common::HashMap<int, int>::iterator i;
+ for (i = container.begin(); i != container.end(); ++i) {
+ int key = i->_key;
+ TS_ASSERT(key >= 0 && key <= 4);
+ TS_ASSERT(!(found & (1 << key)));
+ found |= 1 << key;
+ }
+ TS_ASSERT(found == 16+8+4);
+
+ found = 0;
+ Common::HashMap<int, int>::const_iterator j;
+ for (j = container.begin(); j != container.end(); ++j) {
+ int key = j->_key;
+ TS_ASSERT(key >= 0 && key <= 4);
+ TS_ASSERT(!(found & (1 << key)));
+ found |= 1 << key;
+ }
+ TS_ASSERT(found == 16+8+4);
+}
// TODO: Add test cases for iterators, find, ...
};