OLD | NEW |
---|---|
1 /* | |
2 * Copyright 2013 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 "Test.h" | 8 #include "Test.h" |
2 #include "SkTDynamicHash.h" | 9 #include "SkTDynamicHash.h" |
3 | 10 |
4 namespace { | |
5 | |
6 struct Entry { | 11 struct Entry { |
7 int key; | 12 int key; |
8 double value; | 13 double value; |
9 }; | 14 }; |
10 const int& GetKey(const Entry& entry) { return entry.key; } | |
11 uint32_t GetHash(const int& key) { return key; } | |
12 bool AreEqual(const Entry& entry, const int& key) { return entry.key == key; } | |
13 | 15 |
16 static const int& GetKey(const Entry& entry) { return entry.key; } | |
bsalomon
2013/10/11 14:46:41
Hey Thiago, static functions cannot be used as tem
tfarina
2013/10/11 23:47:04
Done.
| |
17 static uint32_t GetHash(const int& key) { return key; } | |
18 static bool AreEqual(const Entry& entry, const int& key) { | |
19 return entry.key == key; | |
20 } | |
14 | 21 |
15 class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> { | 22 class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> { |
16 public: | 23 public: |
17 Hash() : INHERITED() {} | 24 Hash() : INHERITED() {} |
18 Hash(int capacity) : INHERITED(capacity) {} | 25 Hash(int capacity) : INHERITED(capacity) {} |
19 | 26 |
20 // Promote protected methods to public for this test. | 27 // Promote protected methods to public for this test. |
21 int capacity() const { return this->INHERITED::capacity(); } | 28 int capacity() const { return this->INHERITED::capacity(); } |
22 int countCollisions(const int& key) const { return this->INHERITED::countCol lisions(key); } | 29 int countCollisions(const int& key) const { return this->INHERITED::countCol lisions(key); } |
23 | 30 |
24 private: | 31 private: |
25 typedef SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> INHERITED; | 32 typedef SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> INHERITED; |
26 }; | 33 }; |
27 | 34 |
28 } // namespace | |
29 | |
30 #define ASSERT(x) REPORTER_ASSERT(reporter, x) | 35 #define ASSERT(x) REPORTER_ASSERT(reporter, x) |
31 | 36 |
32 static void test_growth(skiatest::Reporter* reporter) { | 37 static void test_growth(skiatest::Reporter* reporter) { |
33 Entry a = { 1, 2.0 }; | 38 Entry a = { 1, 2.0 }; |
34 Entry b = { 2, 3.0 }; | 39 Entry b = { 2, 3.0 }; |
35 Entry c = { 3, 4.0 }; | 40 Entry c = { 3, 4.0 }; |
36 Entry d = { 4, 5.0 }; | 41 Entry d = { 4, 5.0 }; |
37 Entry e = { 5, 6.0 }; | 42 Entry e = { 5, 6.0 }; |
38 | 43 |
39 Hash hash(4); | 44 Hash hash(4); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 139 |
135 static void test_dynamic_hash(skiatest::Reporter* reporter) { | 140 static void test_dynamic_hash(skiatest::Reporter* reporter) { |
136 test_growth(reporter); | 141 test_growth(reporter); |
137 test_add(reporter); | 142 test_add(reporter); |
138 test_lookup(reporter); | 143 test_lookup(reporter); |
139 test_remove(reporter); | 144 test_remove(reporter); |
140 } | 145 } |
141 | 146 |
142 #include "TestClassDef.h" | 147 #include "TestClassDef.h" |
143 DEFINE_TESTCLASS("DynamicHash", DynamicHashTestClass, test_dynamic_hash); | 148 DEFINE_TESTCLASS("DynamicHash", DynamicHashTestClass, test_dynamic_hash); |
OLD | NEW |