[Scummvm-cvs-logs] SF.net SVN: scummvm:[41400] scummvm/trunk/test/common/hashmap.h
wjpalenstijn at users.sourceforge.net
wjpalenstijn at users.sourceforge.net
Tue Jun 9 17:26:09 CEST 2009
Revision: 41400
http://scummvm.svn.sourceforge.net/scummvm/?rev=41400&view=rev
Author: wjpalenstijn
Date: 2009-06-09 15:26:09 +0000 (Tue, 09 Jun 2009)
Log Message:
-----------
Add (failing) hashmap test case for collision handling
Modified Paths:
--------------
scummvm/trunk/test/common/hashmap.h
Modified: scummvm/trunk/test/common/hashmap.h
===================================================================
--- scummvm/trunk/test/common/hashmap.h 2009-06-09 14:46:20 UTC (rev 41399)
+++ scummvm/trunk/test/common/hashmap.h 2009-06-09 15:26:09 UTC (rev 41400)
@@ -108,5 +108,48 @@
TS_ASSERT_EQUALS(container2[323], 32);
}
+ void test_collision() {
+ // NB: The usefulness of this example depends strongly on the
+ // specific hashmap implementation.
+ // It is constructed to insert multiple colliding elements.
+ Common::HashMap<int, int> h;
+ h[5] = 1;
+ h[32+5] = 1;
+ h[64+5] = 1;
+ h[128+5] = 1;
+ TS_ASSERT(h.contains(5));
+ TS_ASSERT(h.contains(32+5));
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h.erase(32+5);
+ TS_ASSERT(h.contains(5));
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h.erase(5);
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h[32+5] = 1;
+ TS_ASSERT(h.contains(32+5));
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h[5] = 1;
+ TS_ASSERT(h.contains(5));
+ TS_ASSERT(h.contains(32+5));
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h.erase(5);
+ TS_ASSERT(h.contains(32+5));
+ TS_ASSERT(h.contains(64+5));
+ TS_ASSERT(h.contains(128+5));
+ h.erase(64+5);
+ TS_ASSERT(h.contains(32+5));
+ TS_ASSERT(h.contains(128+5));
+ h.erase(128+5);
+ TS_ASSERT(h.contains(32+5));
+ h.erase(32+5);
+ TS_ASSERT(h.empty());
+ }
+
+
// TODO: Add test cases for iterators, find, ...
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list