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

Unified Diff: tests/HashTest.cpp

Issue 925613002: Spin off SkTHashTable, SkTHashMap, SkTHashSet (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows Created 5 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/SkTHash.h ('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
new file mode 100644
index 0000000000000000000000000000000000000000..24032a5ec5652dc6f3d150fe175414b24af1f72a
--- /dev/null
+++ b/tests/HashTest.cpp
@@ -0,0 +1,57 @@
+#include "SkChecksum.h"
+#include "SkString.h"
+#include "SkTHash.h"
+#include "Test.h"
+
+namespace { uint32_t hash_int(int k) { return SkChecksum::Mix(k); } }
+
+static void set_negative_key(int key, double* d) { *d = -key; }
+
+DEF_TEST(HashMap, r) {
+ SkTHashMap<int, double, hash_int> map;
+
+ map.set(3, 4.0);
+ REPORTER_ASSERT(r, map.count() == 1);
+
+ double* found = map.find(3);
+ REPORTER_ASSERT(r, found);
+ REPORTER_ASSERT(r, *found == 4.0);
+
+ map.foreach(set_negative_key);
+ found = map.find(3);
+ REPORTER_ASSERT(r, found);
+ REPORTER_ASSERT(r, *found == -3.0);
+
+ REPORTER_ASSERT(r, !map.find(2));
+
+ const int N = 20;
+
+ for (int i = 0; i < N; i++) {
+ map.set(i, 2.0*i);
+ }
+ for (int i = 0; i < N; i++) {
+ double* found = map.find(i);;
+ REPORTER_ASSERT(r, found);
+ REPORTER_ASSERT(r, *found == i*2.0);
+ }
+ for (int i = N; i < 2*N; i++) {
+ REPORTER_ASSERT(r, !map.find(i));
+ }
+
+ REPORTER_ASSERT(r, map.count() == N);
+}
+
+namespace { uint32_t hash_string(SkString s) { return s.size(); } }
+
+DEF_TEST(HashSet, r) {
+ SkTHashSet<SkString, hash_string> set;
+
+ set.add(SkString("Hello"));
+ set.add(SkString("World"));
+
+ REPORTER_ASSERT(r, set.count() == 2);
+
+ REPORTER_ASSERT(r, set.contains(SkString("Hello")));
+ REPORTER_ASSERT(r, set.contains(SkString("World")));
+ REPORTER_ASSERT(r, !set.contains(SkString("Goodbye")));
+}
« no previous file with comments | « src/core/SkTHash.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698