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

Unified Diff: tests/DynamicHashTest.cpp

Issue 177263005: Counterproposal to 182733007: Add iterator to SkTDynamicHash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: DEF_TEST Created 6 years, 10 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
« no previous file with comments | « 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 db6622d7a7c38e363aa207e43dc1171b83326f79..14ecf7a5be7b71e7feccbbccb88b63e3b94f1754 100644
--- a/tests/DynamicHashTest.cpp
+++ b/tests/DynamicHashTest.cpp
@@ -35,7 +35,7 @@ private:
#define ASSERT(x) REPORTER_ASSERT(reporter, x)
-static void test_growth(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_growth, reporter) {
Entry a = { 1, 2.0 };
Entry b = { 2, 3.0 };
Entry c = { 3, 4.0 };
@@ -63,7 +63,7 @@ static void test_growth(skiatest::Reporter* reporter) {
ASSERT(hash.count() == 5);
}
-static void test_add(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_add, reporter) {
Hash hash;
Entry a = { 1, 2.0 };
Entry b = { 2, 3.0 };
@@ -75,7 +75,7 @@ static void test_add(skiatest::Reporter* reporter) {
ASSERT(hash.count() == 2);
}
-static void test_lookup(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_lookup, reporter) {
Hash hash;
// These collide.
@@ -110,7 +110,7 @@ static void test_lookup(skiatest::Reporter* reporter) {
ASSERT(hash.find(9) == NULL);
}
-static void test_remove(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_remove, reporter) {
Hash hash;
// These collide.
@@ -136,9 +136,51 @@ static void test_remove(skiatest::Reporter* reporter) {
ASSERT(hash.find(5)->value == 3.0);
}
-DEF_TEST(DynamicHash, reporter) {
- test_growth(reporter);
- test_add(reporter);
- test_lookup(reporter);
- test_remove(reporter);
+DEF_TEST(DynamicHash_iterator, reporter) {
+ Hash hash;
+
+ int count = 0;
+ // this should fall out of loop immediately
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
egdaniel 2014/03/04 23:56:34 Part of me feels like this done() function name is
mtklein 2014/03/05 00:13:05 Yeah, I feel you. I think .done() is actually the
+ ++count;
+ }
+ ASSERT(0 == count);
+
+ // These collide.
+ Entry a = { 1, 2.0 };
+ Entry b = { 5, 3.0 };
+ Entry c = { 9, 4.0 };
+
+ hash.add(&a);
+ hash.add(&b);
+ hash.add(&c);
+
+ // should see all 3 unique keys when iterating over hash
+ count = 0;
+ int keys[3] = {0, 0, 0};
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
+ int key = (*iter).key;
+ keys[count] = key;
+ ASSERT(hash.find(key) != NULL);
+ ++count;
+ }
+ ASSERT(3 == count);
+ ASSERT(keys[0] != keys[1]);
+ ASSERT(keys[0] != keys[2]);
+ ASSERT(keys[1] != keys[2]);
+
+ // should see 2 unique keys when iterating over hash that aren't 1
+ hash.remove(1);
+ count = 0;
+ memset(keys,0,sizeof(keys));
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
+ int key = (*iter).key;
+ keys[count] = key;
+ ASSERT(key != 1);
+ ASSERT(hash.find(key) != NULL);
+ ++count;
+ }
+ ASSERT(2 == count);
+ ASSERT(keys[0] != keys[1]);
}
+
« no previous file with comments | « src/core/SkTDynamicHash.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698