BLI: add Map.is_empty() method

This commit is contained in:
Jacques Lucke 2020-04-28 11:44:10 +02:00
parent 7acc8a5a92
commit 9c2715ffda
2 changed files with 12 additions and 0 deletions

View File

@ -415,6 +415,14 @@ class Map {
return m_array.slots_set();
}
/**
* Returns true if there are no elements in the map.
*/
bool is_empty() const
{
return this->size() == 0;
}
/**
* Calls the given function for each key-value-pair.
*/

View File

@ -9,16 +9,20 @@ TEST(map, DefaultConstructor)
{
IntFloatMap map;
EXPECT_EQ(map.size(), 0);
EXPECT_TRUE(map.is_empty());
}
TEST(map, AddIncreasesSize)
{
IntFloatMap map;
EXPECT_EQ(map.size(), 0);
EXPECT_TRUE(map.is_empty());
map.add(2, 5.0f);
EXPECT_EQ(map.size(), 1);
EXPECT_FALSE(map.is_empty());
map.add(6, 2.0f);
EXPECT_EQ(map.size(), 2);
EXPECT_FALSE(map.is_empty());
}
TEST(map, Contains)