2006-05-21 17:14:11 +00:00
|
|
|
|
2009-03-09 20:56:23 +00:00
|
|
|
// Copyright 2006-2009 Daniel James.
|
2006-07-01 22:31:26 +00:00
|
|
|
// 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)
|
2006-05-21 17:14:11 +00:00
|
|
|
|
|
|
|
#include "./containers.hpp"
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2006-05-21 17:14:11 +00:00
|
|
|
#include "../helpers/invariants.hpp"
|
2017-02-19 13:05:17 +00:00
|
|
|
#include "../helpers/random_values.hpp"
|
2006-05-21 17:14:11 +00:00
|
|
|
#include "../helpers/strong.hpp"
|
2017-05-04 19:30:18 +01:00
|
|
|
#include "../helpers/tracker.hpp"
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <string>
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2012-05-07 10:57:35 +00:00
|
|
|
test::seed_t initialize_seed(3298597);
|
2007-12-06 11:42:28 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test_base : public test::exception_base
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::random_values<T> values;
|
|
|
|
unsigned int n;
|
|
|
|
rehash_test_base(unsigned int count = 100, unsigned int n_ = 0)
|
|
|
|
: values(count, test::limited_range), n(n_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef T data_type;
|
|
|
|
typedef test::strong<T> strong_type;
|
|
|
|
|
|
|
|
data_type init() const
|
|
|
|
{
|
|
|
|
T x(values.begin(), values.end(), n);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void check BOOST_PREVENT_MACRO_SUBSTITUTION(
|
|
|
|
T const& x, strong_type const& strong) const
|
|
|
|
{
|
|
|
|
std::string scope(test::scope);
|
|
|
|
|
|
|
|
if (scope.find("hash::operator()") == std::string::npos &&
|
|
|
|
scope.find("equal_to::operator()") == std::string::npos &&
|
|
|
|
scope != "operator==(object, object)")
|
|
|
|
strong.test(x);
|
|
|
|
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test0 : rehash_test_base<T>
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test0() : rehash_test_base<T>(0) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(0);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test1 : rehash_test_base<T>
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test1() : rehash_test_base<T>(0) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(200);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test2 : rehash_test_base<T>
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test2() : rehash_test_base<T>(0, 200) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(0);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test3 : rehash_test_base<T>
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test3() : rehash_test_base<T>(10, 0) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(200);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct rehash_test4 : rehash_test_base<T>
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test4() : rehash_test_base<T>(10, 200) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(0);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2017-05-04 19:30:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> struct rehash_test5 : rehash_test_base<T>
|
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
rehash_test5() : rehash_test_base<T>(200, 10) {}
|
|
|
|
void run(T& x) const
|
|
|
|
{
|
|
|
|
x.rehash(0);
|
|
|
|
|
|
|
|
DISABLE_EXCEPTIONS;
|
|
|
|
test::check_container(x, this->values);
|
|
|
|
test::check_equivalent_keys(x);
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
};
|
|
|
|
|
2017-10-09 12:34:47 +01:00
|
|
|
// clang-format off
|
|
|
|
EXCEPTION_TESTS(
|
|
|
|
(rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4)
|
|
|
|
(rehash_test5),
|
2017-06-11 20:55:59 +01:00
|
|
|
CONTAINER_SEQ)
|
2017-10-09 12:34:47 +01:00
|
|
|
// clang-format on
|
|
|
|
|
2012-12-07 17:05:36 +00:00
|
|
|
RUN_TESTS()
|