From 1b009da4d0f0b24bf93749e2da379866c32ae03d Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 22 Dec 2021 15:03:59 -0800 Subject: [PATCH] Add transparent test support for set's `find()` --- test/unordered/transparent_tests.cpp | 149 +++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/test/unordered/transparent_tests.cpp b/test/unordered/transparent_tests.cpp index 39c0186a..c53c2292 100644 --- a/test/unordered/transparent_tests.cpp +++ b/test/unordered/transparent_tests.cpp @@ -253,6 +253,118 @@ template void test_map_non_transparent_find() } } +template void test_set_transparent_find() +{ + count_reset(); + + typedef typename UnorderedSet::const_iterator set_iterator; + + UnorderedSet set; + + int n = 5; + + for (int i = 0; i < n; ++i) { + set.insert(i); + } + + int const expected_key_count = key::count_; + + // explicitly test `find()` and `find() const` separately + // + + { + UnorderedSet& m = set; + + for (int i = 0; i < n; ++i) { + set_iterator pos = m.find(i); + BOOST_TEST(pos != m.end()); + BOOST_TEST_EQ(*pos, i); + } + + BOOST_TEST_EQ(key::count_, expected_key_count); + + set_iterator pos = m.find(1337); + BOOST_TEST(pos == m.end()); + BOOST_TEST_EQ(key::count_, expected_key_count); + } + + { + UnorderedSet const& m = set; + + for (int i = 0; i < n; ++i) { + set_iterator pos = m.find(i); + BOOST_TEST(pos != m.end()); + BOOST_TEST_EQ(*pos, i); + } + + BOOST_TEST_EQ(key::count_, expected_key_count); + + set_iterator pos = m.find(1337); + BOOST_TEST(pos == m.end()); + BOOST_TEST_EQ(key::count_, expected_key_count); + } +} + +template void test_set_non_transparent_find() +{ + count_reset(); + + typedef typename UnorderedSet::const_iterator set_iterator; + + UnorderedSet set; + + int n = 5; + + for (int i = 0; i < n; ++i) { + set.insert(i); + } + + int key_count = key::count_; + + // explicitly test `find()` and `find() const` separately + // + + { + UnorderedSet& m = set; + + for (int i = 0; i < n; ++i) { + set_iterator pos = m.find(i); + ++key_count; + + BOOST_TEST(pos != m.end()); + BOOST_TEST_EQ(*pos, i); + } + + BOOST_TEST_EQ(key::count_, key_count); + + set_iterator pos = m.find(1337); + ++key_count; + + BOOST_TEST(pos == m.end()); + BOOST_TEST_EQ(key::count_, key_count); + } + + { + UnorderedSet const& m = set; + + for (int i = 0; i < n; ++i) { + set_iterator pos = m.find(i); + ++key_count; + + BOOST_TEST(pos != m.end()); + BOOST_TEST_EQ(*pos, i); + } + + BOOST_TEST_EQ(key::count_, key_count); + + set_iterator pos = m.find(1337); + ++key_count; + + BOOST_TEST(pos == m.end()); + BOOST_TEST_EQ(key::count_, key_count); + } +} + template void test_transparent_equal_range() { count_reset(); @@ -869,9 +981,46 @@ void test_unordered_multimap() } } +void test_unordered_set() +{ + { + typedef boost::unordered_set + unordered_set; + + test_set_transparent_find(); + } + + { + // non-transparent Hash, non-transparent KeyEqual + // + typedef boost::unordered_set unordered_set; + + test_set_non_transparent_find(); + } + + { + // transparent Hash, non-transparent KeyEqual + // + typedef boost::unordered_set + unordered_set; + + test_set_non_transparent_find(); + } + + { + // non-transparent Hash, transparent KeyEqual + // + typedef boost::unordered_set + unordered_set; + + test_set_non_transparent_find(); + } +} + UNORDERED_AUTO_TEST (transparent_ops) { test_unordered_map(); test_unordered_multimap(); + test_unordered_set(); } RUN_TESTS()