| 132 | } |
| 133 | |
| 134 | void ConstCorrectnessTest(const Excalibur::HashTable<int, int>& ht) |
| 135 | { |
| 136 | // this test is more of an API const correctness test (this code is expected to compile without errors) |
| 137 | uint32_t size = ht.size(); |
| 138 | EXPECT_EQ(size, uint32_t(1)); |
| 139 | |
| 140 | uint32_t capacity = ht.capacity(); |
| 141 | EXPECT_GE(capacity, uint32_t(1)); |
| 142 | |
| 143 | bool isEmpty = ht.empty(); |
| 144 | EXPECT_FALSE(isEmpty); |
| 145 | |
| 146 | bool shouldBeTrue = ht.has(1); |
| 147 | EXPECT_TRUE(shouldBeTrue); |
| 148 | |
| 149 | bool shouldBeFalse = ht.has(-1); |
| 150 | EXPECT_FALSE(shouldBeFalse); |
| 151 | |
| 152 | uint64_t sum = 0; |
| 153 | |
| 154 | auto it1 = ht.find(1); |
| 155 | ASSERT_NE(it1, ht.iend()); |
| 156 | sum += it1->first; |
| 157 | sum += it1->second; |
| 158 | |
| 159 | // this should not compile! |
| 160 | /* |
| 161 | int& v = it1->second; |
| 162 | v = 7; |
| 163 | */ |
| 164 | |
| 165 | auto it2 = ht.find(-1); |
| 166 | EXPECT_EQ(it2, ht.iend()); |
| 167 | |
| 168 | for (auto it3 = ht.begin(); it3 != ht.end(); ++it3) |
| 169 | { |
| 170 | sum += *it3; |
| 171 | } |
| 172 | |
| 173 | for (auto it4 = ht.vbegin(); it4 != ht.vend(); ++it4) |
| 174 | { |
| 175 | sum += *it4; |
| 176 | } |
| 177 | |
| 178 | for (auto it5 = ht.ibegin(); it5 != ht.iend(); ++it5) |
| 179 | { |
| 180 | sum += it5->first; |
| 181 | sum += it5->second; |
| 182 | |
| 183 | // this should not compile! |
| 184 | /* |
| 185 | int& v = it5->second; |
| 186 | v = 7; |
| 187 | */ |
| 188 | } |
| 189 | |
| 190 | for (int k : ht) |
| 191 | { |