mirror of
https://github.com/FEX-Emu/robin-map.git
synced 2024-11-27 00:10:45 +00:00
Add specific tests for growth policies classes.
This commit is contained in:
parent
c3bfa5a12f
commit
94558a03a2
@ -8,7 +8,8 @@ find_package(Boost 1.54.0 REQUIRED COMPONENTS unit_test_framework)
|
||||
set(TEST_EXECUTABLE "test_robin_map")
|
||||
|
||||
add_executable("${TEST_EXECUTABLE}" "tests/main.cpp"
|
||||
"tests/custom_allocator_tests.cpp"
|
||||
"tests/custom_allocator_tests.cpp"
|
||||
"tests/policy_tests.cpp"
|
||||
"tests/robin_map_tests.cpp"
|
||||
"tests/robin_set_tests.cpp")
|
||||
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <tsl/robin_map.h>
|
||||
#include "utils.h"
|
||||
#include "tsl/robin_map.h"
|
||||
|
||||
|
||||
static std::size_t nb_custom_allocs = 0;
|
||||
|
93
tests/policy_tests.cpp
Normal file
93
tests/policy_tests.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2017 Tessil
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <ratio>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <tsl/robin_growth_policy.h>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_policy)
|
||||
|
||||
using test_types = boost::mpl::list<tsl::power_of_two_growth_policy_rh<2>,
|
||||
tsl::power_of_two_growth_policy_rh<4>,
|
||||
tsl::prime_growth_policy_rh,
|
||||
tsl::mod_growth_policy_rh<>,
|
||||
tsl::mod_growth_policy_rh<std::ratio<7,2>>>;
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy, Policy, test_types) {
|
||||
// Call next_bucket_count() on the policy until we reach its max_bucket_count()
|
||||
bool exception_thrown = false;
|
||||
|
||||
std::size_t bucket_count = 0;
|
||||
Policy policy(bucket_count);
|
||||
|
||||
try {
|
||||
while(true) {
|
||||
bucket_count = policy.next_bucket_count();
|
||||
policy = Policy(bucket_count);
|
||||
}
|
||||
}
|
||||
catch(const std::length_error& ) {
|
||||
exception_thrown = true;
|
||||
BOOST_CHECK_EQUAL(bucket_count, policy.max_bucket_count());
|
||||
}
|
||||
|
||||
BOOST_CHECK(exception_thrown);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy_min_bucket_count, Policy, test_types) {
|
||||
// Check polcy when a bucket_count of 0 is asked.
|
||||
std::size_t bucket_count = 0;
|
||||
Policy policy(bucket_count);
|
||||
|
||||
BOOST_CHECK_EQUAL(policy.bucket_for_hash(0), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(test_policy_max_bucket_count, Policy, test_types) {
|
||||
// Test a bucket_count equals to the max_bucket_count limit and above
|
||||
std::size_t bucket_count = 0;
|
||||
Policy policy(bucket_count);
|
||||
|
||||
|
||||
bucket_count = policy.max_bucket_count();
|
||||
Policy policy2(bucket_count);
|
||||
|
||||
|
||||
bucket_count = std::numeric_limits<std::size_t>::max();
|
||||
BOOST_CHECK_THROW((Policy(bucket_count)), std::length_error);
|
||||
|
||||
|
||||
bucket_count = policy.max_bucket_count() + 1;
|
||||
BOOST_CHECK_THROW((Policy(bucket_count)), std::length_error);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
@ -38,8 +38,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <tsl/robin_map.h>
|
||||
#include "utils.h"
|
||||
#include "tsl/robin_map.h"
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_robin_map)
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "tsl/robin_set.h"
|
||||
#include <tsl/robin_set.h>
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
|
@ -86,7 +86,8 @@ public:
|
||||
* Return the maximum number of buckets supported by the policy.
|
||||
*/
|
||||
std::size_t max_bucket_count() const {
|
||||
return (std::numeric_limits<std::size_t>::max() / GrowthFactor) + 1;
|
||||
// Largest power of two.
|
||||
return (std::numeric_limits<std::size_t>::max() / 2) + 1;
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user