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

Unified Diff: tests/HashTest.cpp

Issue 1021033002: Some usability ideas around SkTHash. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: minor tweaks Created 5 years, 9 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 | « tests/ChecksumTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/HashTest.cpp
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp
index 623e597eeb2d48dc0238f4a72ae27a8043195558..5abf3db50a56885bd4fa7c0931590c6d1f2323d4 100644
--- a/tests/HashTest.cpp
+++ b/tests/HashTest.cpp
@@ -3,12 +3,15 @@
#include "SkTHash.h"
#include "Test.h"
-namespace { uint32_t hash_int(const int& k) { return SkChecksum::Mix(k); } }
-
-static void set_negative_key(int key, double* d) { *d = -key; }
+// Tests use of const foreach(). map.count() is of course the better way to do this.
+static int count(const SkTHashMap<int, double>& map) {
+ int n = 0;
+ map.foreach([&n](int, double) { n++; });
+ return n;
+}
DEF_TEST(HashMap, r) {
- SkTHashMap<int, double, hash_int> map;
+ SkTHashMap<int, double> map;
map.set(3, 4.0);
REPORTER_ASSERT(r, map.count() == 1);
@@ -17,7 +20,9 @@ DEF_TEST(HashMap, r) {
REPORTER_ASSERT(r, found);
REPORTER_ASSERT(r, *found == 4.0);
- map.foreach(set_negative_key);
+ map.foreach([](int key, double* d){ *d = -key; });
+ REPORTER_ASSERT(r, count(map) == 1);
+
found = map.find(3);
REPORTER_ASSERT(r, found);
REPORTER_ASSERT(r, *found == -3.0);
@@ -44,10 +49,8 @@ DEF_TEST(HashMap, r) {
REPORTER_ASSERT(r, map.count() == 0);
}
-namespace { uint32_t hash_string(const SkString& s) { return SkToInt(s.size()); } }
-
DEF_TEST(HashSet, r) {
- SkTHashSet<SkString, hash_string> set;
+ SkTHashSet<SkString> set;
set.add(SkString("Hello"));
set.add(SkString("World"));
« no previous file with comments | « tests/ChecksumTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698