| 1 | |
| 2 | // Copyright 2022-2023 Christian Mazakas. |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or move at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #if !defined(BOOST_UNORDERED_FOA_TESTS) |
| 7 | #error "max_load_tests is currently only supported by open-addressed containers" |
| 8 | #else |
| 9 | |
| 10 | #include "../helpers/unordered.hpp" |
| 11 | |
| 12 | #include "../helpers/helpers.hpp" |
| 13 | #include "../helpers/random_values.hpp" |
| 14 | #include "../helpers/test.hpp" |
| 15 | #include "../helpers/tracker.hpp" |
| 16 | #include "../objects/test.hpp" |
| 17 | |
| 18 | template <class X> void max_load_tests(X*, test::random_generator generator) |
| 19 | { |
| 20 | typedef typename X::size_type size_type; |
| 21 | |
| 22 | test::reset_sequence(); |
| 23 | |
| 24 | X x; |
| 25 | |
| 26 | x.reserve(1000); |
| 27 | size_type max_load = x.max_load(); |
| 28 | |
| 29 | BOOST_TEST_GT(max_load, 0u); |
| 30 | |
| 31 | size_type bucket_count = x.bucket_count(); |
| 32 | BOOST_TEST_GE(bucket_count, 1000u); |
| 33 | |
| 34 | test::ordered<X> tracker; |
| 35 | { |
| 36 | test::random_values<X> v(max_load, generator); |
| 37 | |
| 38 | x.insert(v.begin(), v.end()); |
| 39 | tracker.insert_range(v.begin(), v.end()); |
| 40 | |
| 41 | BOOST_TEST_EQ(x.bucket_count(), bucket_count); |
| 42 | BOOST_TEST_EQ(x.max_load(), max_load); |
| 43 | BOOST_TEST_EQ(x.size(), max_load); |
| 44 | } |
| 45 | |
| 46 | { |
| 47 | test::random_values<X> v(100, generator); |
| 48 | |
| 49 | x.insert(v.begin(), v.end()); |
| 50 | tracker.insert_range(v.begin(), v.end()); |
| 51 | |
| 52 | BOOST_TEST_GT(x.bucket_count(), bucket_count); |
| 53 | BOOST_TEST_GT(x.max_load(), max_load); |
| 54 | BOOST_TEST_GT(x.size(), max_load); |
| 55 | } |
| 56 | |
| 57 | tracker.compare(x); |
| 58 | } |
| 59 | |
| 60 | using test::default_generator; |
| 61 | using test::generate_collisions; |
| 62 | using test::limited_range; |
| 63 | using test::sequential; |
| 64 | |
| 65 | boost::unordered_flat_set<int>* int_set_ptr; |
| 66 | boost::unordered_flat_map<test::movable, test::movable, test::hash, |
| 67 | test::equal_to, test::allocator2<test::movable> >* test_map_ptr; |
| 68 | |
| 69 | boost::unordered_flat_set<test::object, test::hash, test::equal_to, |
| 70 | test::allocator1<test::object> >* test_set_tracking; |
| 71 | boost::unordered_flat_map<test::object, test::object, test::hash, |
| 72 | test::equal_to, |
| 73 | test::allocator1<std::pair<test::object const, test::object> > >* |
| 74 | test_map_tracking; |
| 75 | |
| 76 | boost::unordered_node_set<int>* int_node_set_ptr; |
| 77 | boost::unordered_node_map<test::movable, test::movable, test::hash, |
| 78 | test::equal_to, test::allocator2<test::movable> >* test_node_map_ptr; |
| 79 | |
| 80 | boost::unordered_node_set<test::object, test::hash, test::equal_to, |
| 81 | test::allocator1<test::object> >* test_node_set_tracking; |
| 82 | boost::unordered_node_map<test::object, test::object, test::hash, |
| 83 | test::equal_to, |
| 84 | test::allocator1<std::pair<test::object const, test::object> > >* |
| 85 | test_node_map_tracking; |
| 86 | |
| 87 | // clang-format off |
| 88 | UNORDERED_TEST(max_load_tests, |
| 89 | ((int_set_ptr)(test_map_ptr)(test_set_tracking)(test_map_tracking) |
| 90 | (int_node_set_ptr)(test_node_map_ptr) |
| 91 | (test_node_set_tracking)(test_node_map_tracking))( |
| 92 | (sequential))) |
| 93 | // clang-format on |
| 94 | #endif |
| 95 | |
| 96 | RUN_TESTS() |
| 97 | |