| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 double* found = map.find(i);; | 45 double* found = map.find(i);; |
| 46 REPORTER_ASSERT(r, found); | 46 REPORTER_ASSERT(r, found); |
| 47 REPORTER_ASSERT(r, *found == i*2.0); | 47 REPORTER_ASSERT(r, *found == i*2.0); |
| 48 } | 48 } |
| 49 for (int i = N; i < 2*N; i++) { | 49 for (int i = N; i < 2*N; i++) { |
| 50 REPORTER_ASSERT(r, !map.find(i)); | 50 REPORTER_ASSERT(r, !map.find(i)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 REPORTER_ASSERT(r, map.count() == N); | 53 REPORTER_ASSERT(r, map.count() == N); |
| 54 | 54 |
| 55 for (int i = 0; i < N/2; i++) { |
| 56 map.remove(i); |
| 57 } |
| 58 for (int i = 0; i < N; i++) { |
| 59 double* found = map.find(i); |
| 60 REPORTER_ASSERT(r, (found == nullptr) == (i < N/2)); |
| 61 } |
| 62 REPORTER_ASSERT(r, map.count() == N/2); |
| 63 |
| 55 map.reset(); | 64 map.reset(); |
| 56 REPORTER_ASSERT(r, map.count() == 0); | 65 REPORTER_ASSERT(r, map.count() == 0); |
| 57 } | 66 } |
| 58 | 67 |
| 59 DEF_TEST(HashSet, r) { | 68 DEF_TEST(HashSet, r) { |
| 60 SkTHashSet<SkString> set; | 69 SkTHashSet<SkString> set; |
| 61 | 70 |
| 62 set.add(SkString("Hello")); | 71 set.add(SkString("Hello")); |
| 63 set.add(SkString("World")); | 72 set.add(SkString("World")); |
| 64 | 73 |
| 65 REPORTER_ASSERT(r, set.count() == 2); | 74 REPORTER_ASSERT(r, set.count() == 2); |
| 66 | 75 |
| 67 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); | 76 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); |
| 68 REPORTER_ASSERT(r, set.contains(SkString("World"))); | 77 REPORTER_ASSERT(r, set.contains(SkString("World"))); |
| 69 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); | 78 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); |
| 70 | 79 |
| 71 REPORTER_ASSERT(r, set.find(SkString("Hello"))); | 80 REPORTER_ASSERT(r, set.find(SkString("Hello"))); |
| 72 REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello")); | 81 REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello")); |
| 73 | 82 |
| 83 set.remove(SkString("Hello")); |
| 84 REPORTER_ASSERT(r, !set.contains(SkString("Hello"))); |
| 85 REPORTER_ASSERT(r, set.count() == 1); |
| 86 |
| 74 set.reset(); | 87 set.reset(); |
| 75 REPORTER_ASSERT(r, set.count() == 0); | 88 REPORTER_ASSERT(r, set.count() == 0); |
| 76 } | 89 } |
| 77 | 90 |
| 78 namespace { | 91 namespace { |
| 79 | 92 |
| 80 class CopyCounter { | 93 class CopyCounter { |
| 81 public: | 94 public: |
| 82 CopyCounter() : fID(0), fCounter(NULL) {} | 95 CopyCounter() : fID(0), fCounter(NULL) {} |
| 83 | 96 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 set.add(copyCounter2); | 143 set.add(copyCounter2); |
| 131 REPORTER_ASSERT(r, globalCounter == 3); | 144 REPORTER_ASSERT(r, globalCounter == 3); |
| 132 REPORTER_ASSERT(r, set.contains(copyCounter1)); | 145 REPORTER_ASSERT(r, set.contains(copyCounter1)); |
| 133 REPORTER_ASSERT(r, set.contains(copyCounter2)); | 146 REPORTER_ASSERT(r, set.contains(copyCounter2)); |
| 134 REPORTER_ASSERT(r, globalCounter == 3); | 147 REPORTER_ASSERT(r, globalCounter == 3); |
| 135 set.add(copyCounter1); | 148 set.add(copyCounter1); |
| 136 set.add(copyCounter2); | 149 set.add(copyCounter2); |
| 137 // We allow copies for same-value adds for now. | 150 // We allow copies for same-value adds for now. |
| 138 REPORTER_ASSERT(r, globalCounter == 5); | 151 REPORTER_ASSERT(r, globalCounter == 5); |
| 139 } | 152 } |
| OLD | NEW |