From 13ed4afc959d4b25ebec50bfc8e85336b065e6dc Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 14 Feb 2023 10:35:35 -0800 Subject: [PATCH] Add foa-based node containers to reserve_tests --- test/unordered/reserve_tests.cpp | 170 +++++++++++++++---------------- 1 file changed, 82 insertions(+), 88 deletions(-) diff --git a/test/unordered/reserve_tests.cpp b/test/unordered/reserve_tests.cpp index ca7f9809..41bd17b1 100644 --- a/test/unordered/reserve_tests.cpp +++ b/test/unordered/reserve_tests.cpp @@ -1,4 +1,4 @@ -// Copyright 2021-2022 Christian Mazakas. +// Copyright 2021-2023 Christian Mazakas. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -45,7 +45,8 @@ template struct A template int A::count = 0; -template void bucket_count_constructor() +template +void bucket_count_constructor(UnorderedContainer*) { BOOST_TEST_EQ(num_allocations, 0u); BOOST_TEST_EQ(total_allocation, 0u); @@ -64,7 +65,8 @@ template void bucket_count_constructor() num_allocations = 0; } -template void range_bucket_constructor() +template +void range_bucket_constructor(UnorderedContainer*) { BOOST_TEST_EQ(num_allocations, 0u); BOOST_TEST_EQ(total_allocation, 0u); @@ -85,7 +87,7 @@ template void range_bucket_constructor() num_allocations = 0; } -template void reserve_tests() +template void reserve_tests(UnorderedContainer*) { BOOST_TEST_EQ(num_allocations, 0u); BOOST_TEST_EQ(total_allocation, 0u); @@ -124,7 +126,7 @@ template void reserve_tests() num_allocations = 0; } -template void rehash_tests() +template void rehash_tests(UnorderedContainer*) { BOOST_TEST_EQ(num_allocations, 0u); BOOST_TEST_EQ(total_allocation, 0u); @@ -191,89 +193,81 @@ template void rehash_tests() num_allocations = 0; } -UNORDERED_AUTO_TEST (unordered_set_reserve) { - { - // prove Allocator invariants - // from cppref: - // Given: - // * A, an Allocator type for type T - // * B, the corresponding Allocator type for some cv-unqualified object type - // U (as obtained by rebinding A) - // - // Expression: - // A a(b) - // - // Return Type: - // Constructs `a` such that `B(a)==b` and `A(b)==a`. - // (Note: This implies that all allocators related by rebind maintain each - // other's resources, such as memory pools.) - // - // - typedef boost::allocator_rebind, float>::type alloc_rebound; - alloc_rebound b; - A a(b); - BOOST_ASSERT(alloc_rebound(a) == b); - BOOST_ASSERT(A(b) == a); - } - -#ifdef BOOST_UNORDERED_FOA_TESTS - typedef boost::unordered_flat_set, - std::equal_to, A > - unordered_set; - - typedef boost::unordered_flat_map, - std::equal_to, A > > - unordered_map; - - bucket_count_constructor(); - bucket_count_constructor(); - - range_bucket_constructor(); - range_bucket_constructor(); - - reserve_tests(); - reserve_tests(); - - rehash_tests(); - rehash_tests(); - -#else - typedef boost::unordered_set, std::equal_to, - A > - unordered_set; - - typedef boost::unordered_multiset, std::equal_to, - A > - unordered_multiset; - - typedef boost::unordered_map, std::equal_to, - A > > - unordered_map; - - typedef boost::unordered_multimap, - std::equal_to, A > > - unordered_multimap; - - bucket_count_constructor(); - bucket_count_constructor(); - bucket_count_constructor(); - bucket_count_constructor(); - - range_bucket_constructor(); - range_bucket_constructor(); - range_bucket_constructor(); - range_bucket_constructor(); - - reserve_tests(); - reserve_tests(); - reserve_tests(); - reserve_tests(); - - rehash_tests(); - rehash_tests(); - rehash_tests(); - rehash_tests(); -#endif +UNORDERED_AUTO_TEST (allocator_check) { + // prove Allocator invariants + // from cppref: + // Given: + // * A, an Allocator type for type T + // * B, the corresponding Allocator type for some cv-unqualified object type + // U (as obtained by rebinding A) + // + // Expression: + // A a(b) + // + // Return Type: + // Constructs `a` such that `B(a)==b` and `A(b)==a`. + // (Note: This implies that all allocators related by rebind maintain each + // other's resources, such as memory pools.) + // + // + typedef boost::allocator_rebind, float>::type alloc_rebound; + alloc_rebound b; + A a(b); + BOOST_ASSERT(alloc_rebound(a) == b); + BOOST_ASSERT(A(b) == a); } +#ifdef BOOST_UNORDERED_FOA_TESTS +static boost::unordered_flat_set, std::equal_to, + A >* test_set; +static boost::unordered_flat_map, + std::equal_to, A > >* test_map; + +static boost::unordered_node_set, std::equal_to, + A >* test_node_set; + +static boost::unordered_node_map, + std::equal_to, A > >* test_node_map; + +// clang-format off +UNORDERED_TEST(bucket_count_constructor, + ((test_set)(test_map)(test_node_set)(test_node_map))) + +UNORDERED_TEST(range_bucket_constructor, + ((test_set)(test_map)(test_node_set)(test_node_map))) + +UNORDERED_TEST(reserve_tests, + ((test_set)(test_map)(test_node_set)(test_node_map))) + +UNORDERED_TEST(rehash_tests, + ((test_set)(test_map)(test_node_set)(test_node_map))) +// clang-format on +#else +static boost::unordered_set, std::equal_to, A >* + test_set; + +static boost::unordered_multiset, std::equal_to, + A >* test_multiset; + +static boost::unordered_map, std::equal_to, + A > >* test_map; + +static boost::unordered_multimap, std::equal_to, + A > >* test_multimap; + +// clang-format off +UNORDERED_TEST(bucket_count_constructor, + ((test_set)(test_map)(test_multiset)(test_multimap))) + +UNORDERED_TEST(range_bucket_constructor, + ((test_set)(test_map)(test_multiset)(test_multimap))) + +UNORDERED_TEST(reserve_tests, + ((test_set)(test_map)(test_multiset)(test_multimap))) + +UNORDERED_TEST(rehash_tests, + ((test_set)(test_map)(test_multiset)(test_multimap))) +// clang-format on +#endif + RUN_TESTS()