test/util/TestIntrusiveHashSet: add test for remove_and_dispose_key()

This commit is contained in:
Max Kellermann 2023-08-03 09:42:16 +02:00 committed by Max Kellermann
parent 9691b609a2
commit 78801f303e
1 changed files with 31 additions and 0 deletions

View File

@ -118,3 +118,34 @@ TEST(IntrusiveHashSet, Basic)
ASSERT_EQ(e.value, -1);
ASSERT_EQ(f.value, -1);
}
TEST(IntrusiveHashSet, Multi)
{
IntItem a{1}, b{2}, c{3}, d{4}, e{5}, f{1};
IntrusiveHashSet<IntItem, 3,
IntrusiveHashSetOperators<IntItem::Hash,
IntItem::Equal>> set;
set.insert(a);
set.insert(b);
set.insert(c);
set.insert(d);
set.insert(e);
set.insert(f);
ASSERT_NE(set.find(f), set.end());
ASSERT_TRUE(&*set.find(a) == &a || &*set.find(a) == &f);
ASSERT_TRUE(&*set.find(f) == &a || &*set.find(f) == &f);
ASSERT_EQ(set.remove_and_dispose_key(a, [](auto*){}), 2U);
ASSERT_EQ(set.find(a), set.end());
ASSERT_EQ(set.find(f), set.end());
ASSERT_NE(set.find(b), set.end());
ASSERT_EQ(&*set.find(b), &b);
ASSERT_EQ(set.remove_and_dispose_key(b, [](auto*){}), 1U);
ASSERT_EQ(set.find(b), set.end());
ASSERT_EQ(set.remove_and_dispose_key(b, [](auto*){}), 0U);
ASSERT_EQ(set.find(b), set.end());
}