policy_tests.cpp
Go to the documentation of this file.
1 
25 
26 #include <boost/mpl/list.hpp>
27 #include <boost/test/unit_test.hpp>
28 #include <cstddef>
29 #include <limits>
30 #include <ratio>
31 #include <stdexcept>
32 
33 #include "utils.h"
34 
35 BOOST_AUTO_TEST_SUITE(test_policy)
36 
37 using test_types =
38  boost::mpl::list<tsl::rh::power_of_two_growth_policy<2>,
42 
44  // Call next_bucket_count() on the policy until we reach its
45  // max_bucket_count()
46  std::size_t bucket_count = 0;
47  Policy policy(bucket_count);
48 
49  BOOST_CHECK_EQUAL(policy.bucket_for_hash(0), 0);
50  BOOST_CHECK_EQUAL(bucket_count, 0);
51 
52 #ifndef TSL_RH_NO_EXCEPTIONS
53  bool exception_thrown = false;
54  try {
55  while (true) {
56  const std::size_t previous_bucket_count = bucket_count;
57 
58  bucket_count = policy.next_bucket_count();
59  policy = Policy(bucket_count);
60 
61  BOOST_CHECK_EQUAL(policy.bucket_for_hash(0), 0);
62  BOOST_CHECK(bucket_count > previous_bucket_count);
63  }
64  } catch (const std::length_error&) {
65  exception_thrown = true;
66  }
67 
68  BOOST_CHECK(exception_thrown);
69 #endif
70 }
71 
72 BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy_min_bucket_count, Policy,
73  test_types) {
74  // Check policy when a bucket_count of 0 is asked.
75  std::size_t bucket_count = 0;
76  Policy policy(bucket_count);
77 
78  BOOST_CHECK_EQUAL(policy.bucket_for_hash(0), 0);
79 }
80 
81 BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy_max_bucket_count, Policy,
82  test_types) {
83  // Test a bucket_count equals to the max_bucket_count limit and above
84  std::size_t bucket_count = 0;
85  Policy policy(bucket_count);
86 
87  bucket_count = policy.max_bucket_count();
88  Policy policy2(bucket_count);
89 
90  bucket_count = std::numeric_limits<std::size_t>::max();
91  TSL_RH_CHECK_THROW((Policy(bucket_count)), std::length_error);
92 
93  bucket_count = policy.max_bucket_count() + 1;
94  TSL_RH_CHECK_THROW((Policy(bucket_count)), std::length_error);
95 }
96 
97 BOOST_AUTO_TEST_SUITE_END()
tsl::rh::prime_growth_policy
Definition: robin_growth_policy.h:369
robin_growth_policy.h
test_types
boost::mpl::list< tsl::rh::power_of_two_growth_policy< 2 >, tsl::rh::power_of_two_growth_policy< 4 >, tsl::rh::prime_growth_policy, tsl::rh::mod_growth_policy<>, tsl::rh::mod_growth_policy< std::ratio< 7, 2 > >> test_types
Definition: policy_tests.cpp:41
utils.h
BOOST_AUTO_TEST_CASE_TEMPLATE
BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy, Policy, test_types)
Definition: policy_tests.cpp:43
TSL_RH_CHECK_THROW
#define TSL_RH_CHECK_THROW(S, E)
Definition: robin-map/tests/utils.h:41
tsl::rh::power_of_two_growth_policy
Definition: robin_growth_policy.h:95
tsl::rh::mod_growth_policy
Definition: robin_growth_policy.h:190


mp2p_icp
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Wed Jun 26 2024 02:47:09