| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkChecksum.h" | 8 #include "SkChecksum.h" |
| 9 #include "SkString.h" | 9 #include "SkString.h" |
| 10 #include "SkTHash.h" | 10 #include "SkTHash.h" |
| 11 #include "Test.h" | 11 #include "Test.h" |
| 12 | 12 |
| 13 // 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. |
| 14 static int count(const SkTHashMap<int, double>& map) { | 14 static int count(const SkTHashMap<int, double>& map) { |
| 15 int n = 0; | 15 int n = 0; |
| 16 map.foreach([&n](int, double) { n++; }); | 16 map.foreach([&n](int, double) { n++; }); |
| 17 return n; | 17 return n; |
| 18 } | 18 } |
| 19 | 19 |
| 20 DEF_TEST(HashMap, r) { | 20 DEF_TEST(HashMap, r) { |
| 21 SkTHashMap<int, double> map; | 21 SkTHashMap<int, double> map; |
| 22 | 22 |
| 23 map.set(3, 4.0); | 23 map.set(3, 4.0); |
| 24 REPORTER_ASSERT(r, map.count() == 1); | 24 REPORTER_ASSERT(r, map.count() == 1); |
| 25 | 25 |
| 26 REPORTER_ASSERT(r, map.approxBytesUsed() > 0); |
| 27 |
| 26 double* found = map.find(3); | 28 double* found = map.find(3); |
| 27 REPORTER_ASSERT(r, found); | 29 REPORTER_ASSERT(r, found); |
| 28 REPORTER_ASSERT(r, *found == 4.0); | 30 REPORTER_ASSERT(r, *found == 4.0); |
| 29 | 31 |
| 30 map.foreach([](int key, double* d){ *d = -key; }); | 32 map.foreach([](int key, double* d){ *d = -key; }); |
| 31 REPORTER_ASSERT(r, count(map) == 1); | 33 REPORTER_ASSERT(r, count(map) == 1); |
| 32 | 34 |
| 33 found = map.find(3); | 35 found = map.find(3); |
| 34 REPORTER_ASSERT(r, found); | 36 REPORTER_ASSERT(r, found); |
| 35 REPORTER_ASSERT(r, *found == -3.0); | 37 REPORTER_ASSERT(r, *found == -3.0); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 set.add(copyCounter2); | 145 set.add(copyCounter2); |
| 144 REPORTER_ASSERT(r, globalCounter == 3); | 146 REPORTER_ASSERT(r, globalCounter == 3); |
| 145 REPORTER_ASSERT(r, set.contains(copyCounter1)); | 147 REPORTER_ASSERT(r, set.contains(copyCounter1)); |
| 146 REPORTER_ASSERT(r, set.contains(copyCounter2)); | 148 REPORTER_ASSERT(r, set.contains(copyCounter2)); |
| 147 REPORTER_ASSERT(r, globalCounter == 3); | 149 REPORTER_ASSERT(r, globalCounter == 3); |
| 148 set.add(copyCounter1); | 150 set.add(copyCounter1); |
| 149 set.add(copyCounter2); | 151 set.add(copyCounter2); |
| 150 // We allow copies for same-value adds for now. | 152 // We allow copies for same-value adds for now. |
| 151 REPORTER_ASSERT(r, globalCounter == 5); | 153 REPORTER_ASSERT(r, globalCounter == 5); |
| 152 } | 154 } |
| OLD | NEW |