From 58326b8fff3c2e7c2663fc4418c51414baf24b62 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 21 Dec 2021 14:51:10 -0800 Subject: [PATCH] Add transparent test support for multimap's `count()` --- test/unordered/transparent_tests.cpp | 68 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/test/unordered/transparent_tests.cpp b/test/unordered/transparent_tests.cpp index c64ead55..6656e95f 100644 --- a/test/unordered/transparent_tests.cpp +++ b/test/unordered/transparent_tests.cpp @@ -66,30 +66,26 @@ template void test_transparent_count() UnorderedMap map; - // initial `key(0)` expression increases the count - // then copying into the `unordered_map` increments the count again thus we - // have 2 - // - map[key(0)] = 1337; - BOOST_TEST(key::count_ == 2); + map.insert(std::make_pair(0, 1337)); + map.insert(std::make_pair(1, 1338)); + map.insert(std::make_pair(2, 1339)); + map.insert(std::make_pair(0, 1340)); + map.insert(std::make_pair(0, 1341)); + map.insert(std::make_pair(0, 1342)); + + int const expected_key_count = key::count_; - // now the number of `key` objects created should be a constant and never - // touched again - // std::size_t count = 0; count = map.count(0); - - BOOST_TEST(count == 1); - BOOST_TEST(key::count_ == 2); + BOOST_TEST_EQ(count, map.size() - 2); count = map.count(1); + BOOST_TEST_EQ(count, 1); - BOOST_TEST(count == 0); - BOOST_TEST(key::count_ == 2); + count = map.count(1337); + BOOST_TEST_EQ(count, 0); - count = map.count(key(0)); - BOOST_TEST(count == 1); - BOOST_TEST(key::count_ == 3); + BOOST_TEST_EQ(key::count_, expected_key_count); } template void test_non_transparent_count() @@ -98,30 +94,32 @@ template void test_non_transparent_count() UnorderedMap map; - // initial `key(0)` expression increases the count - // then copying into the `unordered_map` increments the count again thus we - // have 2 - // - map[key(0)] = 1337; - BOOST_TEST(key::count_ == 2); + map.insert(std::make_pair(0, 1337)); + map.insert(std::make_pair(1, 1338)); + map.insert(std::make_pair(2, 1339)); + map.insert(std::make_pair(0, 1340)); + map.insert(std::make_pair(0, 1341)); + map.insert(std::make_pair(0, 1342)); + + int key_count = key::count_; - // rely on the implicit constructor here to spawn a new object which - // increases the count - // std::size_t count = 0; count = map.count(0); + ++key_count; - BOOST_TEST(count == 1); - BOOST_TEST(key::count_ == 3); + BOOST_TEST_EQ(count, map.size() - 2); + BOOST_TEST_EQ(key::count_, key_count); count = map.count(1); + ++key_count; - BOOST_TEST(count == 0); - BOOST_TEST(key::count_ == 4); + BOOST_TEST_EQ(count, 1); - count = map.count(key(0)); - BOOST_TEST(count == 1); - BOOST_TEST(key::count_ == 5); + count = map.count(1337); + ++key_count; + + BOOST_TEST_EQ(count, 0); + BOOST_TEST_EQ(key::count_, key_count); } template void test_transparent_find() @@ -815,6 +813,7 @@ void test_unordered_multimap() transparent_key_equal> unordered_multimap; + test_transparent_count(); test_transparent_find(); test_transparent_equal_range(); test_transparent_erase(); @@ -827,6 +826,7 @@ void test_unordered_multimap() typedef boost::unordered_multimap unordered_multimap; + test_non_transparent_count(); test_non_transparent_find(); test_non_transparent_equal_range(); test_non_transparent_erase(); @@ -839,6 +839,7 @@ void test_unordered_multimap() typedef boost::unordered_multimap unordered_multimap; + test_non_transparent_count(); test_non_transparent_find(); test_non_transparent_equal_range(); test_non_transparent_erase(); @@ -851,6 +852,7 @@ void test_unordered_multimap() typedef boost::unordered_multimap unordered_multimap; + test_non_transparent_count(); test_non_transparent_find(); test_non_transparent_equal_range(); test_non_transparent_erase();