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

Side by Side Diff: tests/HashTest.cpp

Issue 1058553002: Add SkTHashSet::find() (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: const Created 5 years, 8 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
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "SkChecksum.h" 8 #include "SkChecksum.h"
2 #include "SkString.h" 9 #include "SkString.h"
3 #include "SkTHash.h" 10 #include "SkTHash.h"
4 #include "Test.h" 11 #include "Test.h"
5 12
6 // Tests use of const foreach(). map.count() is of course the better way to do this. 13 // Tests use of const foreach(). map.count() is of course the better way to do this.
7 static int count(const SkTHashMap<int, double>& map) { 14 static int count(const SkTHashMap<int, double>& map) {
8 int n = 0; 15 int n = 0;
9 map.foreach([&n](int, double) { n++; }); 16 map.foreach([&n](int, double) { n++; });
10 return n; 17 return n;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 61
55 set.add(SkString("Hello")); 62 set.add(SkString("Hello"));
56 set.add(SkString("World")); 63 set.add(SkString("World"));
57 64
58 REPORTER_ASSERT(r, set.count() == 2); 65 REPORTER_ASSERT(r, set.count() == 2);
59 66
60 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); 67 REPORTER_ASSERT(r, set.contains(SkString("Hello")));
61 REPORTER_ASSERT(r, set.contains(SkString("World"))); 68 REPORTER_ASSERT(r, set.contains(SkString("World")));
62 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); 69 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye")));
63 70
71 REPORTER_ASSERT(r, set.find(SkString("Hello")));
72 REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello"));
73
64 set.reset(); 74 set.reset();
65 REPORTER_ASSERT(r, set.count() == 0); 75 REPORTER_ASSERT(r, set.count() == 0);
66 } 76 }
67 77
68 namespace { 78 namespace {
69 79
70 class CopyCounter { 80 class CopyCounter {
71 public: 81 public:
72 CopyCounter() : fID(0), fCounter(NULL) {} 82 CopyCounter() : fID(0), fCounter(NULL) {}
73 83
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 set.add(copyCounter2); 130 set.add(copyCounter2);
121 REPORTER_ASSERT(r, globalCounter == 3); 131 REPORTER_ASSERT(r, globalCounter == 3);
122 REPORTER_ASSERT(r, set.contains(copyCounter1)); 132 REPORTER_ASSERT(r, set.contains(copyCounter1));
123 REPORTER_ASSERT(r, set.contains(copyCounter2)); 133 REPORTER_ASSERT(r, set.contains(copyCounter2));
124 REPORTER_ASSERT(r, globalCounter == 3); 134 REPORTER_ASSERT(r, globalCounter == 3);
125 set.add(copyCounter1); 135 set.add(copyCounter1);
126 set.add(copyCounter2); 136 set.add(copyCounter2);
127 // We allow copies for same-value adds for now. 137 // We allow copies for same-value adds for now.
128 REPORTER_ASSERT(r, globalCounter == 5); 138 REPORTER_ASSERT(r, globalCounter == 5);
129 } 139 }
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