From 6f5727cbdb737709c4d51098bda41ed48a078571 Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Tue, 23 Nov 2021 14:14:26 -0800 Subject: [PATCH] Clean up tests by pulling transparent tests into a named function --- test/unordered/transparent_tests.cpp | 69 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/test/unordered/transparent_tests.cpp b/test/unordered/transparent_tests.cpp index f70a9e30..a0289c94 100644 --- a/test/unordered/transparent_tests.cpp +++ b/test/unordered/transparent_tests.cpp @@ -81,6 +81,39 @@ void count_reset() key_equal::was_called_ = false; } +template void test_transparent_count() +{ + count_reset(); + + 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); + + // 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(map.key_eq().was_called_); + + count = map.count(1); + + BOOST_TEST(count == 0); + BOOST_TEST(key::count_ == 2); + + count = map.count(key(0)); + BOOST_TEST(count == 1); + BOOST_TEST(key::count_ == 3); +} + template void test_non_transparent_count() { count_reset(); @@ -115,40 +148,8 @@ template void test_non_transparent_count() } UNORDERED_AUTO_TEST (unordered_map_transparent_count) { - { - // transparent Hash, transparent KeyEqual - // - count_reset(); - - boost::unordered_map - 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); - - // 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(map.key_eq().was_called_); - - count = map.count(1); - - BOOST_TEST(count == 0); - BOOST_TEST(key::count_ == 2); - - count = map.count(key(0)); - BOOST_TEST(count == 1); - BOOST_TEST(key::count_ == 3); - } + test_transparent_count >(); // non-transparent Hash, non-transparent KeyEqual //