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()); +}