MCPcopy Create free account
hub / github.com/SergeyMakeev/ExcaliburHash / MutabilityTest

Function MutabilityTest

ExcaliburHashTest03.cpp:220–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220void MutabilityTest(Excalibur::HashTable<int, int>& ht)
221{
222 // find() can be used to get non-const kv iterator
223 auto it1 = ht.find(1);
224 ASSERT_NE(it1, ht.iend());
225 int& v = it1->second;
226 EXPECT_EQ(v, 2);
227 v = 3;
228 EXPECT_EQ(v, 3);
229
230 // you can mutate values when iterate
231 for (auto it2 = ht.vbegin(); it2 != ht.vend(); ++it2)
232 {
233 int& val = *it2;
234 val++;
235 }
236
237 for (auto it3 = ht.ibegin(); it3 != ht.iend(); ++it3)
238 {
239 int& val = it3->second;
240 val++;
241 }
242
243 for (int& k : ht.values())
244 {
245 k++;
246 }
247
248 for (auto& kv : ht.items())
249 {
250 int& val = kv.second;
251 val++;
252 }
253
254 auto it4 = ht.find(1);
255 ASSERT_NE(it4, ht.iend());
256 const int& testVal = it4->second;
257 EXPECT_EQ(testVal, 7);
258}
259
260TEST(SmFlatHashMap, ConstCorrectness)
261{

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected