SlotMap benchmark
Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m20s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m17s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 5m55s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Clang Format Checks (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled

This commit is contained in:
2026-05-16 01:53:43 +02:00
parent acdbfb505e
commit 943597202b
8 changed files with 649 additions and 241 deletions

View File

@@ -1,3 +1,3 @@
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)

View File

@@ -10,208 +10,258 @@
namespace Bigfoot
{
class SlotKeyFixture: public ::testing::Test
template<class VERSION_TYPE, class INDEX_TYPE>
struct SlotMapConfig
{
protected:
using Version = VERSION_TYPE;
using Index = INDEX_TYPE;
};
using SlotMapConfigs = ::testing::Types<SlotMapConfig<std::uint8_t, std::uint8_t>,
SlotMapConfig<std::uint8_t, std::uint16_t>,
SlotMapConfig<std::uint8_t, std::uint32_t>,
SlotMapConfig<std::uint16_t, std::uint8_t>,
SlotMapConfig<std::uint16_t, std::uint16_t>,
SlotMapConfig<std::uint16_t, std::uint32_t>,
SlotMapConfig<std::uint32_t, std::uint8_t>,
SlotMapConfig<std::uint32_t, std::uint16_t>,
SlotMapConfig<std::uint32_t, std::uint32_t>>;
struct SlotMapConfigNames
{
template<class T>
static std::string GetName(int)
{
return "VERSION" + std::to_string(sizeof(typename T::Version) * 8) + "_INDEX" +
std::to_string(sizeof(typename T::Index) * 8);
}
};
/****************************************************************************************/
TEST_F(SlotKeyFixture, DefaultSlotKeyIsInvalid)
template<class CONFIG>
class SlotKeyFixture: public ::testing::Test
{
constexpr SlotMap<std::uint32_t>::SlotKey::IndexType index = 0;
constexpr SlotMap<std::uint32_t>::SlotKey::VersionType version = 0;
protected:
using SlotMapVersion = typename CONFIG::Version;
using SlotMapIndex = typename CONFIG::Index;
using SlotMapType = SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>;
using SlotKey = typename SlotMapType::SlotKey;
};
SlotMap<std::uint32_t>::SlotKey slotKey {};
TYPED_TEST_SUITE(SlotKeyFixture, SlotMapConfigs, SlotMapConfigNames);
/****************************************************************************************/
TYPED_TEST(SlotKeyFixture, DefaultSlotKeyIsInvalid)
{
constexpr typename TestFixture::SlotMapIndex index = 0;
constexpr typename TestFixture::SlotMapVersion version = 0;
constexpr typename TestFixture::SlotKey slotKey {};
EXPECT_FALSE(slotKey.Valid());
EXPECT_EQ(slotKey.Version(), index);
EXPECT_EQ(slotKey.Index(), version);
}
/****************************************************************************************/
TEST_F(SlotKeyFixture, Valid_ShouldReturnTrueIfTheSlotKeyIsValid)
{
constexpr SlotMap<std::uint32_t>::SlotKey::IndexType index = 0;
constexpr SlotMap<std::uint32_t>::SlotKey::VersionType version = 1;
SlotMap<std::uint32_t>::SlotKey slotKey {version, index};
EXPECT_TRUE(slotKey.Valid());
}
/****************************************************************************************/
TEST_F(SlotKeyFixture, Valid_ShouldReturnFalseIfTheSlotKeyIsValid)
{
constexpr SlotMap<std::uint32_t>::SlotKey::IndexType index = 0;
constexpr SlotMap<std::uint32_t>::SlotKey::VersionType version = 0;
SlotMap<std::uint32_t>::SlotKey slotKey {version, index};
EXPECT_FALSE(slotKey.Valid());
}
/****************************************************************************************/
TEST_F(SlotKeyFixture, Version_ShouldReturnTheVersion)
{
constexpr SlotMap<std::uint32_t>::SlotKey::IndexType index = 0;
constexpr SlotMap<std::uint32_t>::SlotKey::VersionType version = 42;
SlotMap<std::uint32_t>::SlotKey slotKey {version, index};
EXPECT_EQ(slotKey.Version(), version);
}
/****************************************************************************************/
TEST_F(SlotKeyFixture, Index_ShouldReturnTheIndex)
{
constexpr SlotMap<std::uint32_t>::SlotKey::IndexType index = 42;
constexpr SlotMap<std::uint32_t>::SlotKey::VersionType version = 0;
SlotMap<std::uint32_t>::SlotKey slotKey {version, index};
EXPECT_EQ(slotKey.Index(), index);
}
/****************************************************************************************/
class SlotMapFixture: public ::testing::Test
TYPED_TEST(SlotKeyFixture, Valid_ShouldReturnTrueIfTheSlotKeyIsValid)
{
protected:
using SlotMapVersion = std::uint8_t;
using SlotMapIndex = std::uint32_t;
constexpr typename TestFixture::SlotMapIndex index = 0;
constexpr typename TestFixture::SlotMapVersion version = 1;
SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex> m_slotMap;
};
/****************************************************************************************/
TEST_F(SlotMapFixture, Insert_ShouldReturnAValidSlotKey)
{
const auto slotKey = m_slotMap.Insert(42);
constexpr typename TestFixture::SlotKey slotKey {version, index};
EXPECT_TRUE(slotKey.Valid());
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Insert_ShouldRecycleASlotKeyAfterARemove)
TYPED_TEST(SlotKeyFixture, Valid_ShouldReturnFalseIfTheSlotKeyIsValid)
{
const auto slotKey = m_slotMap.Insert(42);
m_slotMap.Remove(slotKey);
constexpr typename TestFixture::SlotMapIndex index = 0;
constexpr typename TestFixture::SlotMapVersion version = 0;
const auto secondSlotKey = m_slotMap.Insert(69);
constexpr typename TestFixture::SlotKey slotKey {version, index};
EXPECT_FALSE(slotKey.Valid());
}
/****************************************************************************************/
TYPED_TEST(SlotKeyFixture, Version_ShouldReturnTheVersion)
{
constexpr typename TestFixture::SlotMapIndex index = 0;
constexpr typename TestFixture::SlotMapVersion version = 42;
constexpr typename TestFixture::SlotKey slotKey {version, index};
EXPECT_EQ(slotKey.Version(), version);
}
/****************************************************************************************/
TYPED_TEST(SlotKeyFixture, Index_ShouldReturnTheIndex)
{
constexpr typename TestFixture::SlotMapIndex index = 42;
constexpr typename TestFixture::SlotMapVersion version = 0;
constexpr typename TestFixture::SlotKey slotKey {version, index};
EXPECT_EQ(slotKey.Index(), index);
}
/****************************************************************************************/
template<class CONFIG>
class SlotMapFixture: public ::testing::Test
{
protected:
using SlotMapVersion = typename CONFIG::Version;
using SlotMapIndex = typename CONFIG::Index;
using SlotMapType = SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>;
using SlotKey = typename SlotMapType::SlotKey;
SlotMapType m_slotMap;
};
TYPED_TEST_SUITE(SlotMapFixture, SlotMapConfigs, SlotMapConfigNames);
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Insert_ShouldReturnAValidSlotKey)
{
const auto slotKey = this->m_slotMap.Insert(42);
EXPECT_TRUE(slotKey.Valid());
}
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Insert_ShouldRecycleASlotKeyAfterARemove)
{
const auto slotKey = this->m_slotMap.Insert(42);
this->m_slotMap.Remove(slotKey);
const auto secondSlotKey = this->m_slotMap.Insert(69);
EXPECT_NE(secondSlotKey.Version(), slotKey.Version());
EXPECT_EQ(secondSlotKey.Index(), slotKey.Index());
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Has_ShouldReturnTrueIfTheSlotMapHasTheKey)
TYPED_TEST(SlotMapFixture, Has_ShouldReturnTrueIfTheSlotMapHasTheKey)
{
const auto slotKey = m_slotMap.Insert(42);
EXPECT_TRUE(m_slotMap.Has(slotKey));
const auto slotKey = this->m_slotMap.Insert(42);
EXPECT_TRUE(this->m_slotMap.Has(slotKey));
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Has_ShouldReturnFalseIfTheSlotMapDoesNotHaveTheKey)
TYPED_TEST(SlotMapFixture, Has_ShouldReturnFalseIfTheSlotMapDoesNotHaveTheKey)
{
const auto slotKey = m_slotMap.Insert(42);
m_slotMap.Remove(slotKey);
EXPECT_FALSE(m_slotMap.Has(slotKey));
EXPECT_FALSE(m_slotMap.Has((SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {1, 22})));
EXPECT_FALSE(m_slotMap.Has((SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {})));
const auto slotKey = this->m_slotMap.Insert(42);
this->m_slotMap.Remove(slotKey);
EXPECT_FALSE(this->m_slotMap.Has(slotKey));
EXPECT_FALSE(this->m_slotMap.Has(typename TestFixture::SlotKey {1, 22}));
EXPECT_FALSE(this->m_slotMap.Has(typename TestFixture::SlotKey {}));
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Remove_ShouldRemoveTheSlotKey)
TYPED_TEST(SlotMapFixture, Remove_ShouldRemoveTheSlotKey)
{
const auto slotKey = m_slotMap.Insert(42);
m_slotMap.Remove(slotKey);
EXPECT_FALSE(m_slotMap.Has(slotKey));
const auto slotKey = this->m_slotMap.Insert(42);
this->m_slotMap.Remove(slotKey);
EXPECT_FALSE(this->m_slotMap.Has(slotKey));
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Remove_ShouldNotRecycleASlotWhenVersionWasExhausted)
TYPED_TEST(SlotMapFixture, Remove_ShouldNotRecycleASlotWhenVersionWasExhausted)
{
auto key = m_slotMap.Insert(1);
for (SlotMapVersion i = 1; i < std::numeric_limits<SlotMapVersion>::max(); ++i)
if constexpr (std::is_same_v<typename TestFixture::SlotMapVersion, std::uint32_t>)
{
m_slotMap.Remove(key);
const auto newKey = m_slotMap.Insert(1);
EXPECT_EQ(newKey.Index(), key.Index());
key = newKey;
GTEST_SKIP() << "Skipped for 32-bit version: exhausting all versions is too slow.";
}
else
{
auto key = this->m_slotMap.Insert(1);
// Slot is at MAX_VERSION — one more remove should overflow and permanently deactivate it
EXPECT_EQ(key.Version(), std::numeric_limits<SlotMapVersion>::max());
m_slotMap.Remove(key);
for (typename TestFixture::SlotMapVersion i = 1;
i < std::numeric_limits<typename TestFixture::SlotMapVersion>::max();
++i)
{
this->m_slotMap.Remove(key);
const auto newKey = this->m_slotMap.Insert(1);
EXPECT_EQ(newKey.Index(), key.Index());
key = newKey;
}
EXPECT_FALSE(m_slotMap.Has(key));
// Slot is at MAX_VERSION — one more remove should overflow and permanently deactivate it
EXPECT_EQ(key.Version(), std::numeric_limits<typename TestFixture::SlotMapVersion>::max());
this->m_slotMap.Remove(key);
// Dead slot must not be recycled; a new insert must allocate a fresh slot index
const auto newKey = m_slotMap.Insert(2);
EXPECT_NE(newKey.Index(), key.Index());
EXPECT_FALSE(this->m_slotMap.Has(key));
// Ensure an invalid key does not return an exhausted slot
EXPECT_EQ(m_slotMap.Get(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {}), nullptr);
// Dead slot must not be recycled; a new insert must allocate a fresh slot index
const auto newKey = this->m_slotMap.Insert(2);
EXPECT_NE(newKey.Index(), key.Index());
// Ensure an invalid key does not return an exhausted slot
EXPECT_EQ(this->m_slotMap.Get(typename TestFixture::SlotKey {}), nullptr);
}
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseOfDoubleRemove)
TYPED_TEST(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseOfDoubleRemove)
{
const auto slotKey1 = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
const auto slotKey1 = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
m_slotMap.Remove(slotKey1);
m_slotMap.Remove(slotKey1);
this->m_slotMap.Remove(slotKey1);
this->m_slotMap.Remove(slotKey1);
EXPECT_EQ(*m_slotMap.Get(slotKey2), 69);
EXPECT_EQ(*this->m_slotMap.Get(slotKey2), 69);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseStaleKey)
TYPED_TEST(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseStaleKey)
{
const auto slotKey1 = m_slotMap.Insert(42);
const auto slotKey1 = this->m_slotMap.Insert(42);
m_slotMap.Remove(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {2, 0});
this->m_slotMap.Remove(typename TestFixture::SlotKey {2, 0});
EXPECT_EQ(*m_slotMap.Get(slotKey1), 42);
EXPECT_EQ(*this->m_slotMap.Get(slotKey1), 42);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Get_ShouldReturnNullptrForInvalidSlotKeys)
TYPED_TEST(SlotMapFixture, Get_ShouldReturnNullptrForInvalidSlotKeys)
{
const auto slotKey = m_slotMap.Insert(42);
m_slotMap.Remove(slotKey);
const auto slotKey = this->m_slotMap.Insert(42);
this->m_slotMap.Remove(slotKey);
const auto validate = [&](auto& p_slotMap)
{
EXPECT_EQ(p_slotMap.Get(slotKey), nullptr);
EXPECT_EQ(p_slotMap.Get(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {1, 3}), nullptr);
EXPECT_EQ(p_slotMap.Get(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {}), nullptr);
EXPECT_EQ(p_slotMap.Get(typename TestFixture::SlotKey {1, 3}), nullptr);
EXPECT_EQ(p_slotMap.Get(typename TestFixture::SlotKey {}), nullptr);
};
validate(m_slotMap);
const auto& constSlotMap = m_slotMap;
validate(this->m_slotMap);
const auto& constSlotMap = this->m_slotMap;
validate(constSlotMap);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Get_ShouldReturnTheValueForValidSlotKeys)
TYPED_TEST(SlotMapFixture, Get_ShouldReturnTheValueForValidSlotKeys)
{
const auto slotKey1 = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
const auto slotKey3 = m_slotMap.Insert(28);
const auto slotKey4 = m_slotMap.Insert(0);
const auto slotKey1 = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
const auto slotKey3 = this->m_slotMap.Insert(28);
const auto slotKey4 = this->m_slotMap.Insert(0);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
const auto validate = [&](auto& p_slotMap)
{
@@ -220,150 +270,150 @@ TEST_F(SlotMapFixture, Get_ShouldReturnTheValueForValidSlotKeys)
EXPECT_EQ(*p_slotMap.Get(slotKey4), 0);
};
validate(m_slotMap);
const auto& constSlotMap = m_slotMap;
validate(this->m_slotMap);
const auto& constSlotMap = this->m_slotMap;
validate(constSlotMap);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Reset_ResetsTheSlotMapAndMakesCollisionWithOldSlotKeys)
TYPED_TEST(SlotMapFixture, Reset_ResetsTheSlotMapAndMakesCollisionWithOldSlotKeys)
{
const auto slotKey1 = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
const auto slotKey1 = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Reset();
this->m_slotMap.Reset();
const auto slotKey5 = m_slotMap.Insert(128);
const auto slotKey5 = this->m_slotMap.Insert(128);
EXPECT_EQ(slotKey1, slotKey5);
EXPECT_EQ(*m_slotMap.Get(slotKey5), 128);
EXPECT_EQ(*m_slotMap.Get(slotKey1), 128);
EXPECT_EQ(*this->m_slotMap.Get(slotKey5), 128);
EXPECT_EQ(*this->m_slotMap.Get(slotKey1), 128);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Clear_ResetsTheSlotMapAndButGuaranteesNotCollisionWithOldSlotKeys)
TYPED_TEST(SlotMapFixture, Clear_ResetsTheSlotMapAndButGuaranteesNotCollisionWithOldSlotKeys)
{
const auto slotKey1 = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
const auto slotKey1 = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Clear();
this->m_slotMap.Clear();
const auto slotKey5 = m_slotMap.Insert(128);
const auto slotKey5 = this->m_slotMap.Insert(128);
EXPECT_NE(slotKey1, slotKey5);
EXPECT_EQ(*m_slotMap.Get(slotKey5), 128);
EXPECT_EQ(m_slotMap.Get(slotKey1), nullptr);
EXPECT_EQ(*this->m_slotMap.Get(slotKey5), 128);
EXPECT_EQ(this->m_slotMap.Get(slotKey1), nullptr);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Size_ReturnTheSizeOfTheSlotMap)
TYPED_TEST(SlotMapFixture, Size_ReturnTheSizeOfTheSlotMap)
{
EXPECT_EQ(m_slotMap.Size(), 0);
EXPECT_EQ(this->m_slotMap.Size(), 0);
std::ignore = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
EXPECT_EQ(m_slotMap.Size(), 4);
EXPECT_EQ(this->m_slotMap.Size(), 4);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
EXPECT_EQ(m_slotMap.Size(), 3);
EXPECT_EQ(this->m_slotMap.Size(), 3);
m_slotMap.Clear();
this->m_slotMap.Clear();
EXPECT_EQ(m_slotMap.Size(), 0);
EXPECT_EQ(this->m_slotMap.Size(), 0);
std::ignore = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
EXPECT_EQ(m_slotMap.Size(), 4);
EXPECT_EQ(this->m_slotMap.Size(), 4);
m_slotMap.Reset();
this->m_slotMap.Reset();
EXPECT_EQ(m_slotMap.Size(), 0);
EXPECT_EQ(this->m_slotMap.Size(), 0);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty)
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty)
{
EXPECT_TRUE(m_slotMap.Empty());
EXPECT_TRUE(this->m_slotMap.Empty());
std::ignore = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Clear();
this->m_slotMap.Clear();
EXPECT_TRUE(m_slotMap.Empty());
EXPECT_TRUE(this->m_slotMap.Empty());
std::ignore = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Reset();
this->m_slotMap.Reset();
EXPECT_TRUE(m_slotMap.Empty());
EXPECT_TRUE(this->m_slotMap.Empty());
const auto slotKey9 = m_slotMap.Insert(42);
m_slotMap.Remove(slotKey9);
const auto slotKey9 = this->m_slotMap.Insert(42);
this->m_slotMap.Remove(slotKey9);
EXPECT_TRUE(m_slotMap.Empty());
EXPECT_TRUE(this->m_slotMap.Empty());
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Empty_ShouldReturnFalseIfTheSlotMapIsNotEmpty)
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnFalseIfTheSlotMapIsNotEmpty)
{
std::ignore = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
EXPECT_FALSE(m_slotMap.Empty());
EXPECT_FALSE(this->m_slotMap.Empty());
m_slotMap.Clear();
this->m_slotMap.Clear();
std::ignore = m_slotMap.Insert(42);
std::ignore = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
std::ignore = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
EXPECT_FALSE(m_slotMap.Empty());
EXPECT_FALSE(this->m_slotMap.Empty());
m_slotMap.Reset();
this->m_slotMap.Reset();
const auto slotKey9 = m_slotMap.Insert(42);
EXPECT_FALSE(m_slotMap.Empty());
m_slotMap.Remove(slotKey9);
const auto slotKey9 = this->m_slotMap.Insert(42);
EXPECT_FALSE(this->m_slotMap.Empty());
this->m_slotMap.Remove(slotKey9);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, Iterator)
TYPED_TEST(SlotMapFixture, Iterator)
{
const auto slotKey1 = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
const auto slotKey3 = m_slotMap.Insert(28);
const auto slotKey4 = m_slotMap.Insert(0);
const auto slotKey1 = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
const auto slotKey3 = this->m_slotMap.Insert(28);
const auto slotKey4 = this->m_slotMap.Insert(0);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
eastl::vector<std::uint32_t> values;
for (auto it = m_slotMap.begin(); it != m_slotMap.end(); ++it)
for (auto it = this->m_slotMap.begin(); it != this->m_slotMap.end(); ++it)
{
values.push_back(*it);
}
@@ -374,28 +424,28 @@ TEST_F(SlotMapFixture, Iterator)
EXPECT_EQ(values[2], 28);
// The non-const iterator is mutable.
for (std::uint32_t& value: m_slotMap)
for (std::uint32_t& value: this->m_slotMap)
{
value += 100;
}
EXPECT_EQ(*m_slotMap.Get(slotKey1), 142);
EXPECT_EQ(*m_slotMap.Get(slotKey3), 128);
EXPECT_EQ(*m_slotMap.Get(slotKey4), 100);
EXPECT_EQ(*this->m_slotMap.Get(slotKey1), 142);
EXPECT_EQ(*this->m_slotMap.Get(slotKey3), 128);
EXPECT_EQ(*this->m_slotMap.Get(slotKey4), 100);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, ConstIterator)
TYPED_TEST(SlotMapFixture, ConstIterator)
{
std::ignore = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
const auto& constSlotMap = m_slotMap;
const auto& constSlotMap = this->m_slotMap;
eastl::vector<std::uint32_t> values;
for (auto it = constSlotMap.begin(); it != constSlotMap.end(); ++it)
@@ -410,7 +460,7 @@ TEST_F(SlotMapFixture, ConstIterator)
// cbegin/cend yield the same const traversal.
eastl::vector<std::uint32_t> cValues;
for (auto it = m_slotMap.cbegin(); it != m_slotMap.cend(); ++it)
for (auto it = this->m_slotMap.cbegin(); it != this->m_slotMap.cend(); ++it)
{
cValues.push_back(*it);
}
@@ -420,17 +470,17 @@ TEST_F(SlotMapFixture, ConstIterator)
/****************************************************************************************/
TEST_F(SlotMapFixture, ReverseIterator)
TYPED_TEST(SlotMapFixture, ReverseIterator)
{
const auto slotKey1 = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
const auto slotKey3 = m_slotMap.Insert(28);
const auto slotKey4 = m_slotMap.Insert(0);
const auto slotKey1 = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
const auto slotKey3 = this->m_slotMap.Insert(28);
const auto slotKey4 = this->m_slotMap.Insert(0);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
eastl::vector<std::uint32_t> values;
for (auto it = m_slotMap.rbegin(); it != m_slotMap.rend(); ++it)
for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it)
{
values.push_back(*it);
}
@@ -441,28 +491,28 @@ TEST_F(SlotMapFixture, ReverseIterator)
EXPECT_EQ(values[2], 42);
// The non-const reverse iterator is mutable.
for (auto it = m_slotMap.rbegin(); it != m_slotMap.rend(); ++it)
for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it)
{
*it += 100;
}
EXPECT_EQ(*m_slotMap.Get(slotKey1), 142);
EXPECT_EQ(*m_slotMap.Get(slotKey3), 128);
EXPECT_EQ(*m_slotMap.Get(slotKey4), 100);
EXPECT_EQ(*this->m_slotMap.Get(slotKey1), 142);
EXPECT_EQ(*this->m_slotMap.Get(slotKey3), 128);
EXPECT_EQ(*this->m_slotMap.Get(slotKey4), 100);
}
/****************************************************************************************/
TEST_F(SlotMapFixture, ConstReverseIterator)
TYPED_TEST(SlotMapFixture, ConstReverseIterator)
{
std::ignore = m_slotMap.Insert(42);
const auto slotKey2 = m_slotMap.Insert(69);
std::ignore = m_slotMap.Insert(28);
std::ignore = m_slotMap.Insert(0);
std::ignore = this->m_slotMap.Insert(42);
const auto slotKey2 = this->m_slotMap.Insert(69);
std::ignore = this->m_slotMap.Insert(28);
std::ignore = this->m_slotMap.Insert(0);
m_slotMap.Remove(slotKey2);
this->m_slotMap.Remove(slotKey2);
const auto& constSlotMap = m_slotMap;
const auto& constSlotMap = this->m_slotMap;
eastl::vector<std::uint32_t> values;
for (auto it = constSlotMap.rbegin(); it != constSlotMap.rend(); ++it)
@@ -477,7 +527,7 @@ TEST_F(SlotMapFixture, ConstReverseIterator)
// crbegin/crend yield the same const reverse traversal.
eastl::vector<std::uint32_t> crValues;
for (auto it = m_slotMap.crbegin(); it != m_slotMap.crend(); ++it)
for (auto it = this->m_slotMap.crbegin(); it != this->m_slotMap.crend(); ++it)
{
crValues.push_back(*it);
}