From 78801f303ece1208eb39d26d80c392b35d84a067 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Aug 2023 09:42:16 +0200 Subject: [PATCH] test/util/TestIntrusiveHashSet: add test for remove_and_dispose_key() --- test/util/TestIntrusiveHashSet.cxx | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/util/TestIntrusiveHashSet.cxx b/test/util/TestIntrusiveHashSet.cxx index 8a66d651a..4a23ad798 100644 --- a/test/util/TestIntrusiveHashSet.cxx +++ b/test/util/TestIntrusiveHashSet.cxx @@ -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> 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()); +}