| 26 | } // namespace Excalibur |
| 27 | |
| 28 | TEST(SmFlatHashMap, BadHashFunction) |
| 29 | { |
| 30 | Excalibur::HashTable<CustomStruct, int> ht; |
| 31 | EXPECT_TRUE(ht.empty()); |
| 32 | EXPECT_EQ(ht.size(), 0u); |
| 33 | EXPECT_GE(ht.capacity(), 0u); |
| 34 | |
| 35 | const int kNumElements = 500; |
| 36 | for (int i = 0; i < kNumElements; i++) |
| 37 | { |
| 38 | int v = 3 + i; |
| 39 | auto it = ht.emplace(CustomStruct{256 * i + 1}, v); |
| 40 | EXPECT_TRUE(it.second); |
| 41 | } |
| 42 | |
| 43 | for (int i = 0; i < kNumElements; i++) |
| 44 | { |
| 45 | auto v = ht.find(CustomStruct{256 * i + 1}); |
| 46 | ASSERT_NE(v, ht.iend()); |
| 47 | int refVal = 3 + i; |
| 48 | EXPECT_EQ(v.value(), refVal); |
| 49 | } |
| 50 | |
| 51 | // search for non-existing keys |
| 52 | auto f0 = ht.find(CustomStruct{-3}); |
| 53 | EXPECT_EQ(f0, ht.iend()); |
| 54 | auto f1 = ht.find(CustomStruct{-13}); |
| 55 | EXPECT_EQ(f1, ht.iend()); |
| 56 | |
| 57 | // erase non-existing keys |
| 58 | bool e0 = ht.erase(CustomStruct{-3}); |
| 59 | EXPECT_FALSE(e0); |
| 60 | bool e1 = ht.erase(CustomStruct{-13}); |
| 61 | EXPECT_FALSE(e1); |
| 62 | } |
| 63 | |
| 64 | TEST(SmFlatHashMap, EmplaceEdgeCase) |
| 65 | { |
nothing calls this directly
no test coverage detected