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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkTHash.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "SkChecksum.h"
2 #include "SkString.h"
3 #include "SkTHash.h"
4 #include "Test.h"
5
6 namespace { uint32_t hash_int(int k) { return SkChecksum::Mix(k); } }
7
8 static void set_negative_key(int key, double* d) { *d = -key; }
9
10 DEF_TEST(HashMap, r) {
11 SkTHashMap<int, double, hash_int> map;
12
13 map.set(3, 4.0);
14 REPORTER_ASSERT(r, map.count() == 1);
15
16 double* found = map.find(3);
17 REPORTER_ASSERT(r, found);
18 REPORTER_ASSERT(r, *found == 4.0);
19
20 map.foreach(set_negative_key);
21 found = map.find(3);
22 REPORTER_ASSERT(r, found);
23 REPORTER_ASSERT(r, *found == -3.0);
24
25 REPORTER_ASSERT(r, !map.find(2));
26
27 const int N = 20;
28
29 for (int i = 0; i < N; i++) {
30 map.set(i, 2.0*i);
31 }
32 for (int i = 0; i < N; i++) {
33 double* found = map.find(i);;
34 REPORTER_ASSERT(r, found);
35 REPORTER_ASSERT(r, *found == i*2.0);
36 }
37 for (int i = N; i < 2*N; i++) {
38 REPORTER_ASSERT(r, !map.find(i));
39 }
40
41 REPORTER_ASSERT(r, map.count() == N);
42 }
43
44 namespace { uint32_t hash_string(SkString s) { return s.size(); } }
45
46 DEF_TEST(HashSet, r) {
47 SkTHashSet<SkString, hash_string> set;
48
49 set.add(SkString("Hello"));
50 set.add(SkString("World"));
51
52 REPORTER_ASSERT(r, set.count() == 2);
53
54 REPORTER_ASSERT(r, set.contains(SkString("Hello")));
55 REPORTER_ASSERT(r, set.contains(SkString("World")));
56 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye")));
57 }
OLDNEW
« 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