SlotMap basic testing
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m10s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m17s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m9s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m32s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m31s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m31s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m31s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m14s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m13s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m7s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m55s
Bigfoot / Clang Format Checks (push) Successful in 13s

This commit is contained in:
2026-08-08 15:31:32 +02:00
parent b1d71993da
commit f9a57e5172
2 changed files with 151 additions and 1 deletions
@@ -94,7 +94,7 @@ class SlotMapBase
}
[[nodiscard]]
std::size_t GetSize() const
std::size_t Size() const
{
return m_size;
}
+150
View File
@@ -0,0 +1,150 @@
/*********************************************************************
* \file SlotMap.cpp
*
* \author Romain BOULLARD
* \date August 2026
*********************************************************************/
#include <Utils/Containers/SlotMap.hpp>
#include <gtest/gtest.h>
namespace Bigfoot
{
class SlotMapKeyFixture: public ::testing::Test
{
protected:
};
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, INVALID_VERSION_IsZero)
{
EXPECT_EQ(SlotMapKey::INVALID_VERSION, 0);
}
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, MAX_INDEX_IsMaxU32)
{
EXPECT_EQ(SlotMapKey::MAX_INDEX, std::numeric_limits<std::uint32_t>::max());
}
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, Valid_ShouldReturnFalseIfVersionIsInvalid)
{
EXPECT_FALSE(SlotMapKey().Valid());
EXPECT_FALSE(SlotMapKey(0, 0).Valid());
EXPECT_FALSE(SlotMapKey(SlotMapKey::INVALID_VERSION, 0).Valid());
EXPECT_FALSE(SlotMapKey(0, 42).Valid());
EXPECT_FALSE(SlotMapKey(SlotMapKey::INVALID_VERSION, 42).Valid());
}
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, Valid_ShouldReturnTrueIfVersionisNotInvalid)
{
EXPECT_TRUE(SlotMapKey(1, 0).Valid());
EXPECT_TRUE(SlotMapKey(1, 42).Valid());
}
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, GetVersion_ShouldReturnTheVersion)
{
EXPECT_EQ(SlotMapKey(0, 0).GetVersion(), 0);
EXPECT_EQ(SlotMapKey(42, 69).GetVersion(), 42);
}
/****************************************************************************************/
TEST_F(SlotMapKeyFixture, GetIndex_ShouldReturnTheIndex)
{
EXPECT_EQ(SlotMapKey(0, 0).GetIndex(), 0);
EXPECT_EQ(SlotMapKey(42, 69).GetIndex(), 69);
}
/****************************************************************************************/
template<class SLOTMAP>
class SlotMapFixture: public ::testing::Test
{
protected:
SLOTMAP m_slotMap;
};
class SlotMapNameGenerator
{
public:
template<typename T>
static std::string GetName(int)
{
if constexpr (std::is_same_v<T, DenseSlotMap<std::uint32_t>>)
{
return "DenseSlotMap";
}
if constexpr (std::is_same_v<T, StableSlotMap<std::uint32_t>>)
{
return "StableSlotMap";
}
}
};
using SlotMapTypes = ::testing::Types<DenseSlotMap<std::uint32_t>, StableSlotMap<std::uint32_t>>;
TYPED_TEST_SUITE(SlotMapFixture, SlotMapTypes, SlotMapNameGenerator);
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Has_ReturnTrueIfSlotMapHasTheKey)
{
const SlotMapKey key = this->m_slotMap.Insert(42);
EXPECT_TRUE(this->m_slotMap.Has(key));
}
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Has_ReturnFalseIfSlotMapDoesNotHaveTheKey)
{
std::ignore = this->m_slotMap.Insert(42);
EXPECT_FALSE(this->m_slotMap.Has(SlotMapKey {1, 23}));
}
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Size_ShouldReturnTheSizeOfTheSlotMap)
{
EXPECT_EQ(this->m_slotMap.Size(), 0);
const SlotMapKey key1 = this->m_slotMap.Insert(42);
const SlotMapKey key2 = this->m_slotMap.Insert(69);
EXPECT_EQ(this->m_slotMap.Size(), 2);
this->m_slotMap.Remove(key1);
EXPECT_EQ(this->m_slotMap.Size(), 1);
this->m_slotMap.Remove(key2);
EXPECT_EQ(this->m_slotMap.Size(), 0);
}
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty)
{
EXPECT_TRUE(this->m_slotMap.Empty());
const SlotMapKey key1 = this->m_slotMap.Insert(42);
const SlotMapKey key2 = this->m_slotMap.Insert(69);
this->m_slotMap.Remove(key1);
this->m_slotMap.Remove(key2);
EXPECT_TRUE(this->m_slotMap.Empty());
}
/****************************************************************************************/
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnFalseIfTheSlotMapIsNotEmpty)
{
const SlotMapKey key1 = this->m_slotMap.Insert(42);
EXPECT_FALSE(this->m_slotMap.Empty());
const SlotMapKey key2 = this->m_slotMap.Insert(69);
EXPECT_FALSE(this->m_slotMap.Empty());
this->m_slotMap.Remove(key1);
EXPECT_FALSE(this->m_slotMap.Empty());
this->m_slotMap.Remove(key2);
}
} // namespace Bigfoot