MCPcopy Create free account
hub / github.com/SergeyMakeev/SlotMap / TEST

Function TEST

SlotMapTest03.cpp:5–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <unordered_map>
4
5TEST(SlotMapTest, BasicIterators)
6{
7 dod::slot_map32<int, 32, 0> slotMap;
8
9 // allocate and remove some IDs (to waste a few allocation pages)
10 for (size_t i = 0; i < static_cast<size_t>(decltype(slotMap)::kPageSize) * 2; i++)
11 {
12 for (size_t j = 0; j < static_cast<size_t>(decltype(slotMap)::key::kMaxVersion) + 10; j++)
13 {
14 auto id = slotMap.emplace(13);
15 slotMap.erase(id);
16 }
17 }
18
19 EXPECT_EQ(slotMap.size(), uint32_t(0));
20
21 std::unordered_map<dod::slot_map32<int>::key, int> keyToValue;
22 uint32_t numElements = 16384;
23 for (int j = 0; j < int(numElements); j++)
24 {
25 auto id = slotMap.emplace(j);
26 keyToValue[id] = j;
27 }
28
29 EXPECT_EQ(slotMap.size(), numElements);
30 EXPECT_EQ(size_t(slotMap.size()), keyToValue.size());
31
32 // iterate over all slot map values
33 std::vector<uint8_t> isFound;
34 isFound.resize(numElements, 0);
35
36 for (const int& value : slotMap)
37 {
38 ASSERT_TRUE(value >= 0 && value < int(numElements));
39 ASSERT_EQ(isFound[value], 0);
40 isFound[value] = 1;
41 }
42
43 uint32_t sum = 0;
44 for (uint8_t v : isFound)
45 {
46 sum += v;
47 }
48 EXPECT_EQ(sum, numElements);
49
50 // iterate over all slot map keys & values
51 isFound.clear();
52 isFound.resize(numElements, 0);
53 for (const auto& [key, value] : slotMap.items())
54 {
55 auto it = keyToValue.find(key);
56 ASSERT_NE(it, keyToValue.end());
57 ASSERT_EQ(it->second, value);
58 ASSERT_TRUE(value >= 0 && value < int(numElements));
59 ASSERT_EQ(isFound[value], 0);
60 isFound[value] = 1;
61 }
62

Callers

nothing calls this directly

Calls 8

emplaceMethod · 0.80
eraseMethod · 0.80
sizeMethod · 0.80
clearMethod · 0.80
itemsMethod · 0.80
getMethod · 0.80
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected