OLD | NEW |
1 #include "SkChecksum.h" | 1 #include "SkChecksum.h" |
2 #include "SkString.h" | 2 #include "SkString.h" |
3 #include "SkTHash.h" | 3 #include "SkTHash.h" |
4 #include "Test.h" | 4 #include "Test.h" |
5 | 5 |
6 namespace { uint32_t hash_int(const int& k) { return SkChecksum::Mix(k); } } | 6 namespace { uint32_t hash_int(const int& k) { return SkChecksum::Mix(k); } } |
7 | 7 |
8 static void set_negative_key(int key, double* d) { *d = -key; } | 8 static void set_negative_key(int key, double* d) { *d = -key; } |
9 | 9 |
10 DEF_TEST(HashMap, r) { | 10 DEF_TEST(HashMap, r) { |
(...skipping 21 matching lines...) Expand all Loading... |
32 for (int i = 0; i < N; i++) { | 32 for (int i = 0; i < N; i++) { |
33 double* found = map.find(i);; | 33 double* found = map.find(i);; |
34 REPORTER_ASSERT(r, found); | 34 REPORTER_ASSERT(r, found); |
35 REPORTER_ASSERT(r, *found == i*2.0); | 35 REPORTER_ASSERT(r, *found == i*2.0); |
36 } | 36 } |
37 for (int i = N; i < 2*N; i++) { | 37 for (int i = N; i < 2*N; i++) { |
38 REPORTER_ASSERT(r, !map.find(i)); | 38 REPORTER_ASSERT(r, !map.find(i)); |
39 } | 39 } |
40 | 40 |
41 REPORTER_ASSERT(r, map.count() == N); | 41 REPORTER_ASSERT(r, map.count() == N); |
| 42 |
| 43 map.reset(); |
| 44 REPORTER_ASSERT(r, map.count() == 0); |
42 } | 45 } |
43 | 46 |
44 namespace { uint32_t hash_string(const SkString& s) { return SkToInt(s.size());
} } | 47 namespace { uint32_t hash_string(const SkString& s) { return SkToInt(s.size());
} } |
45 | 48 |
46 DEF_TEST(HashSet, r) { | 49 DEF_TEST(HashSet, r) { |
47 SkTHashSet<SkString, hash_string> set; | 50 SkTHashSet<SkString, hash_string> set; |
48 | 51 |
49 set.add(SkString("Hello")); | 52 set.add(SkString("Hello")); |
50 set.add(SkString("World")); | 53 set.add(SkString("World")); |
51 | 54 |
52 REPORTER_ASSERT(r, set.count() == 2); | 55 REPORTER_ASSERT(r, set.count() == 2); |
53 | 56 |
54 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); | 57 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); |
55 REPORTER_ASSERT(r, set.contains(SkString("World"))); | 58 REPORTER_ASSERT(r, set.contains(SkString("World"))); |
56 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); | 59 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); |
| 60 |
| 61 set.reset(); |
| 62 REPORTER_ASSERT(r, set.count() == 0); |
57 } | 63 } |
58 | 64 |
59 namespace { | 65 namespace { |
60 | 66 |
61 class CopyCounter { | 67 class CopyCounter { |
62 public: | 68 public: |
63 CopyCounter() : fID(0), fCounter(NULL) {} | 69 CopyCounter() : fID(0), fCounter(NULL) {} |
64 | 70 |
65 CopyCounter(uint32_t id, uint32_t* counter) : fID(id), fCounter(counter) {} | 71 CopyCounter(uint32_t id, uint32_t* counter) : fID(id), fCounter(counter) {} |
66 | 72 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 set.add(copyCounter2); | 117 set.add(copyCounter2); |
112 REPORTER_ASSERT(r, globalCounter == 3); | 118 REPORTER_ASSERT(r, globalCounter == 3); |
113 REPORTER_ASSERT(r, set.contains(copyCounter1)); | 119 REPORTER_ASSERT(r, set.contains(copyCounter1)); |
114 REPORTER_ASSERT(r, set.contains(copyCounter2)); | 120 REPORTER_ASSERT(r, set.contains(copyCounter2)); |
115 REPORTER_ASSERT(r, globalCounter == 3); | 121 REPORTER_ASSERT(r, globalCounter == 3); |
116 set.add(copyCounter1); | 122 set.add(copyCounter1); |
117 set.add(copyCounter2); | 123 set.add(copyCounter2); |
118 // We allow copies for same-value adds for now. | 124 // We allow copies for same-value adds for now. |
119 REPORTER_ASSERT(r, globalCounter == 5); | 125 REPORTER_ASSERT(r, globalCounter == 5); |
120 } | 126 } |
OLD | NEW |