Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1655)

Unified Diff: tests/DynamicHashTest.cpp

Issue 22571010: SkTDynamicHash: support remove() without needing Deleted(). (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/core/SkTDynamicHash.h ('K') | « src/core/SkTDynamicHash.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DynamicHashTest.cpp
diff --git a/tests/DynamicHashTest.cpp b/tests/DynamicHashTest.cpp
index 4a8c3a01a28d316016eb7091ed6e39c17e052712..179f0ebe25d858b4a965b19cc0719159eaa5582a 100644
--- a/tests/DynamicHashTest.cpp
+++ b/tests/DynamicHashTest.cpp
@@ -113,38 +113,74 @@ static void test_lookup(skiatest::Reporter* reporter) {
ASSERT(hash.find(9) == NULL);
}
-static void test_remove(skiatest::Reporter* reporter) {
+static void test_easy_remove(skiatest::Reporter* reporter) {
Hash hash(4);
ASSERT(hash.capacity() == 4);
// These collide.
Entry a = { 1, 2.0 };
Entry b = { 5, 3.0 };
- Entry c = { 9, 4.0 };
hash.add(&a);
+ ASSERT(hash.count() == 1);
+ ASSERT(hash.countCollisions(1) == 0);
+
hash.add(&b);
- hash.remove(1);
- // a should be marked deleted, and b should still be findable.
+ ASSERT(hash.count() == 2);
+ ASSERT(hash.countCollisions(1) == 0);
+ ASSERT(hash.countCollisions(5) == 1);
- ASSERT(hash.find(1) == NULL);
- ASSERT(hash.find(5) != NULL);
- ASSERT(hash.find(5)->value == 3.0);
+ hash.remove(5);
+ ASSERT(hash.count() == 1);
+ ASSERT(hash.countCollisions(1) == 0);
+}
- // This will go in the same slot as 'a' did before.
- ASSERT(hash.countCollisions(9) == 0);
+static void test_interesting_remove(skiatest::Reporter* reporter) {
+ Hash hash(8);
+ ASSERT(hash.capacity() == 8);
+
+ // These collide.
+ Entry a = { 1, 2.0 };
+ Entry b = { 9, 3.0 };
+ Entry c = { 17, 4.0 };
+ Entry d = { 25, 5.0 };
+
+ // This will trigger interesting behavior in remove.
+ hash.add(&a);
+ hash.add(&b);
hash.add(&c);
- ASSERT(hash.find(9) != NULL);
- ASSERT(hash.find(9)->value == 4.0);
- ASSERT(hash.find(5) != NULL);
- ASSERT(hash.find(5)->value == 3.0);
+ hash.remove(9);
+
+ // a shouldn't have moved.
+ ASSERT(hash.find(1) != NULL);
+ ASSERT(hash.find(1)->value == 2.0);
+ ASSERT(hash.countCollisions(1) == 0);
+ // c should have moved into b's position.
+ ASSERT(hash.find(17) != NULL);
+ ASSERT(hash.find(17)->value == 4.0);
+ ASSERT(hash.countCollisions(17) == 1);
+
+ hash.add(&d);
+ // a shouldn't have moved.
+ ASSERT(hash.find(1) != NULL);
+ ASSERT(hash.find(1)->value == 2.0);
+ ASSERT(hash.countCollisions(1) == 0);
+ // c shouldn't have moved.
+ ASSERT(hash.find(17) != NULL);
+ ASSERT(hash.find(17)->value == 4.0);
+ ASSERT(hash.countCollisions(17) == 1);
+ // d's after both of them.
+ ASSERT(hash.find(25) != NULL);
+ ASSERT(hash.find(25)->value == 5.0);
+ ASSERT(hash.countCollisions(25) == 2);
}
static void test_dynamic_hash(skiatest::Reporter* reporter) {
test_growth(reporter);
test_add(reporter);
test_lookup(reporter);
- test_remove(reporter);
+ test_easy_remove(reporter);
+ test_interesting_remove(reporter);
}
#include "TestClassDef.h"
« src/core/SkTDynamicHash.h ('K') | « src/core/SkTDynamicHash.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698