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

Function TEST

SlotMapTest02.cpp:7–104  ·  view source on GitHub ↗

Note: You could skip slow tests by using "SlotMapTest --gtest_filter=-SlotMapTest.*_Slow"

Source from the content-addressed store, hash-verified

5
6// Note: You could skip slow tests by using "SlotMapTest --gtest_filter=-SlotMapTest.*_Slow"
7TEST(SlotMapTest, IdCollisions_Slow)
8{
9 static const int kNumberOfIds = 1024;
10 std::vector<dod::slot_map<int>::key> ids;
11 ids.resize(kNumberOfIds);
12
13 dod::slot_map<int> slotMap;
14 for (size_t i = 0; i < ids.size(); i++)
15 {
16 ids[i] = slotMap.emplace(int(113 + i));
17 }
18
19 for (size_t i = 0; i < ids.size(); i++)
20 {
21 EXPECT_TRUE(slotMap.has_key(ids[i]));
22 }
23
24 for (size_t i = 0; i < ids.size(); i++)
25 {
26 slotMap.erase(ids[i]);
27 }
28
29 std::unordered_set<dod::slot_map<int>::key> idsToTest;
30 for (size_t i = 0; i < ids.size(); i++)
31 {
32 idsToTest.emplace(ids[i]);
33 EXPECT_FALSE(slotMap.has_key(ids[i]));
34 }
35
36 EXPECT_EQ(idsToTest.size(), ids.size());
37 EXPECT_EQ(slotMap.size(), 0u);
38
39#ifdef _DEBUG
40 static const int kNumberOfIterations = 300000;
41#else
42 static const int kNumberOfIterations = 5000000;
43#endif
44
45 static const int kNumberOfTempIds = 1024;
46 std::array<dod::slot_map<int>::key, kNumberOfTempIds> tempIds;
47
48 size_t numAllocationsChecked = 0;
49 for (size_t iter = 1; iter <= kNumberOfIterations; iter++)
50 {
51 if ((iter % 8839) == 0 || (iter + 1) == kNumberOfIterations || (iter == 1))
52 {
53 printf("Iteration: %d (%3.2f%%) \r", int(iter), 100.0f * double(iter) / double(kNumberOfIterations));
54 }
55
56 for (size_t j = 0; j < kNumberOfTempIds; j++)
57 {
58 numAllocationsChecked++;
59 auto id = slotMap.emplace(int(j + 7));
60 tempIds[j] = id;
61
62 // check for collisions
63 auto it = idsToTest.find(id);
64 ASSERT_EQ(it, idsToTest.end());

Callers

nothing calls this directly

Calls 10

sizeMethod · 0.80
emplaceMethod · 0.80
has_keyMethod · 0.80
eraseMethod · 0.80
getMethod · 0.80
popMethod · 0.80
debug_statsMethod · 0.80
clearMethod · 0.80
resetMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected