2006-05-17 17:19:16 +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-17 17:19:16 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format off
|
2009-11-26 23:15:30 +00:00
|
|
|
#include "../helpers/prefix.hpp"
|
2006-05-17 17:19:16 +00:00
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
2012-04-08 15:29:15 +00:00
|
|
|
#include "../helpers/postfix.hpp"
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format on
|
|
|
|
|
2008-03-24 17:03:15 +00:00
|
|
|
#include "../helpers/test.hpp"
|
2006-05-17 17:19:16 +00:00
|
|
|
#include "../objects/test.hpp"
|
2011-08-14 18:53:29 +00:00
|
|
|
#include "../objects/cxx11_allocator.hpp"
|
2006-05-17 17:19:16 +00:00
|
|
|
#include "../helpers/random_values.hpp"
|
|
|
|
#include "../helpers/tracker.hpp"
|
|
|
|
#include "../helpers/equivalent.hpp"
|
|
|
|
|
2011-08-14 21:03:18 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
2017-02-19 13:05:17 +00:00
|
|
|
#pragma warning(disable : 4127) // conditional expression is constant
|
2011-08-14 21:03:18 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-11 10:19:33 -08:00
|
|
|
#if defined(__clang__) && defined(__has_warning)
|
|
|
|
#if __has_warning("-Wself-assign-overloaded")
|
|
|
|
#pragma clang diagnostic ignored "-Wself-assign-overloaded"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-03-24 17:03:15 +00:00
|
|
|
namespace assign_tests {
|
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
test::seed_t initialize_seed(96785);
|
2007-12-06 11:42:28 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
template <class T> void assign_tests1(T*, test::random_generator generator)
|
|
|
|
{
|
2018-01-27 09:39:59 +00:00
|
|
|
typename T::hasher hf;
|
|
|
|
typename T::key_equal eq;
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests1.1\n";
|
2006-05-17 17:19:16 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
2011-08-14 18:52:43 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
T x;
|
|
|
|
x = x;
|
|
|
|
BOOST_TEST(x.empty());
|
|
|
|
BOOST_TEST(test::equivalent(x.hash_function(), hf));
|
|
|
|
BOOST_TEST(test::equivalent(x.key_eq(), eq));
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests1.2\n";
|
2006-05-17 17:19:16 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v(1000, generator);
|
|
|
|
T x(v.begin(), v.end());
|
|
|
|
|
|
|
|
test::ordered<T> tracker = test::create_ordered(x);
|
|
|
|
tracker.insert_range(v.begin(), v.end());
|
|
|
|
|
|
|
|
x = x;
|
|
|
|
tracker.compare(x);
|
|
|
|
|
|
|
|
T y;
|
|
|
|
y.max_load_factor(x.max_load_factor() / 20);
|
|
|
|
float mlf = x.max_load_factor();
|
|
|
|
y = x;
|
|
|
|
tracker.compare(x);
|
|
|
|
tracker.compare(y);
|
|
|
|
BOOST_TEST(x.max_load_factor() == mlf);
|
|
|
|
BOOST_TEST(y.max_load_factor() == mlf);
|
|
|
|
BOOST_TEST(y.load_factor() <= y.max_load_factor());
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
template <class T> void assign_tests2(T*, test::random_generator generator)
|
|
|
|
{
|
2018-01-27 09:39:59 +00:00
|
|
|
typename T::hasher hf1(1);
|
|
|
|
typename T::hasher hf2(2);
|
|
|
|
typename T::key_equal eq1(1);
|
|
|
|
typename T::key_equal eq2(2);
|
|
|
|
typename T::allocator_type al1(1);
|
|
|
|
typename T::allocator_type al2(2);
|
|
|
|
|
|
|
|
typedef typename T::allocator_type allocator_type;
|
2016-11-21 10:24:51 +00:00
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.0 - empty container\n";
|
2016-11-21 10:24:51 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
T x1(0, hf1, eq1);
|
|
|
|
T x2(0, hf2, eq2);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x1.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x1.key_eq(), eq1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
|
|
|
test::check_container(x1, x2);
|
2016-11-21 10:24:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.1\n";
|
2006-05-17 17:19:16 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v(1000, generator);
|
|
|
|
T x1(v.begin(), v.end(), 0, hf1, eq1);
|
|
|
|
T x2(0, hf2, eq2);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x1.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x1.key_eq(), eq1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
|
|
|
test::check_container(x1, v);
|
|
|
|
test::check_container(x2, v);
|
|
|
|
BOOST_TEST(x2.load_factor() <= x2.max_load_factor());
|
2012-08-25 21:55:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.1a\n";
|
2012-08-25 21:55:46 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v1(0, generator);
|
|
|
|
test::random_values<T> v2(1000, generator);
|
|
|
|
T x1(0, hf2, eq2);
|
|
|
|
T x2(v2.begin(), v2.end(), 0, hf1, eq1);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x1.hash_function(), hf2));
|
|
|
|
BOOST_TEST(test::equivalent(x1.key_eq(), eq2));
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf2));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq2));
|
|
|
|
test::check_container(x1, v1);
|
|
|
|
test::check_container(x2, v1);
|
|
|
|
BOOST_TEST(x2.load_factor() <= x2.max_load_factor());
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.2\n";
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v1(100, generator), v2(100, generator);
|
|
|
|
T x1(v1.begin(), v1.end(), 0, hf1, eq1, al1);
|
|
|
|
T x2(v2.begin(), v2.end(), 0, hf2, eq2, al2);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
|
|
|
if (allocator_type::is_propagate_on_assign) {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al1));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al2));
|
|
|
|
} else {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al2));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al1));
|
|
|
|
}
|
|
|
|
test::check_container(x1, v1);
|
|
|
|
test::check_container(x2, v1);
|
|
|
|
BOOST_TEST(x2.load_factor() <= x2.max_load_factor());
|
2012-08-25 21:55:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.3\n";
|
2012-08-25 21:55:46 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v1(100, generator), v2(1000, generator);
|
|
|
|
T x1(v1.begin(), v1.end(), 0, hf1, eq1, al1);
|
|
|
|
T x2(v2.begin(), v2.end(), 0, hf2, eq2, al2);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
|
|
|
if (allocator_type::is_propagate_on_assign) {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al1));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al2));
|
|
|
|
} else {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al2));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al1));
|
|
|
|
}
|
|
|
|
test::check_container(x1, v1);
|
|
|
|
test::check_container(x2, v1);
|
|
|
|
BOOST_TEST(x2.load_factor() <= x2.max_load_factor());
|
2012-08-25 21:55:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests2.4\n";
|
2012-08-25 21:55:46 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
|
|
test::random_values<T> v1(1000, generator), v2(100, generator);
|
|
|
|
T x1(v1.begin(), v1.end(), 0, hf1, eq1, al1);
|
|
|
|
T x2(v2.begin(), v2.end(), 0, hf2, eq2, al2);
|
|
|
|
x2 = x1;
|
|
|
|
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
|
|
|
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
|
|
|
if (allocator_type::is_propagate_on_assign) {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al1));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al2));
|
|
|
|
} else {
|
|
|
|
BOOST_TEST(test::equivalent(x2.get_allocator(), al2));
|
|
|
|
BOOST_TEST(!test::equivalent(x2.get_allocator(), al1));
|
|
|
|
}
|
|
|
|
test::check_container(x1, v1);
|
|
|
|
test::check_container(x2, v1);
|
|
|
|
BOOST_TEST(x2.load_factor() <= x2.max_load_factor());
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
std::allocator<test::object> >* test_map_std_alloc;
|
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_set<test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator1<test::object> >* test_set;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multiset<test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator2<test::object> >* test_multiset;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator2<test::object> >* test_map;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multimap<test::object, test::object, test::hash,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::equal_to, test::allocator1<test::object> >* test_multimap;
|
2008-03-24 17:03:15 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_set<test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_set_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multiset<test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_multiset_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_map_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multimap<test::object, test::object, test::hash,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::equal_to,
|
|
|
|
test::cxx11_allocator<test::object, test::propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_multimap_prop_assign;
|
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_set<test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::no_propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_set_no_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multiset<test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::no_propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_multiset_no_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::cxx11_allocator<test::object, test::no_propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_map_no_prop_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multimap<test::object, test::object, test::hash,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::equal_to,
|
|
|
|
test::cxx11_allocator<test::object, test::no_propagate_assign> >*
|
2011-08-14 18:53:29 +00:00
|
|
|
test_multimap_no_prop_assign;
|
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
using test::default_generator;
|
|
|
|
using test::generate_collisions;
|
|
|
|
using test::limited_range;
|
2008-03-24 17:03:15 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
template <typename T> bool is_propagate(T*)
|
|
|
|
{
|
2011-08-15 20:23:29 +00:00
|
|
|
return T::allocator_type::is_propagate_on_assign;
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2011-08-15 20:23:29 +00:00
|
|
|
|
2017-10-09 12:34:47 +01:00
|
|
|
UNORDERED_AUTO_TEST (check_traits) {
|
2011-08-15 20:23:29 +00:00
|
|
|
BOOST_TEST(!is_propagate(test_set));
|
|
|
|
BOOST_TEST(is_propagate(test_set_prop_assign));
|
|
|
|
BOOST_TEST(!is_propagate(test_set_no_prop_assign));
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2011-08-15 20:23:29 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
UNORDERED_TEST(assign_tests1,
|
2017-02-19 13:05:17 +00:00
|
|
|
((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)(
|
2017-06-11 20:55:59 +01:00
|
|
|
test_set_prop_assign)(test_multiset_prop_assign)(test_map_prop_assign)(
|
|
|
|
test_multimap_prop_assign)(test_set_no_prop_assign)(
|
|
|
|
test_multiset_no_prop_assign)(test_map_no_prop_assign)(
|
|
|
|
test_multimap_no_prop_assign))(
|
2017-10-05 10:54:22 +01:00
|
|
|
(default_generator)(generate_collisions)(limited_range)))
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
UNORDERED_TEST(
|
2017-02-19 13:05:17 +00:00
|
|
|
assign_tests2, ((test_set)(test_multiset)(test_map)(test_multimap)(
|
2017-06-11 20:55:59 +01:00
|
|
|
test_set_prop_assign)(test_multiset_prop_assign)(
|
|
|
|
test_map_prop_assign)(test_multimap_prop_assign)(
|
|
|
|
test_set_no_prop_assign)(test_multiset_no_prop_assign)(
|
|
|
|
test_map_no_prop_assign)(test_multimap_no_prop_assign))(
|
|
|
|
(default_generator)(generate_collisions)(limited_range)))
|
2008-03-24 17:03:15 +00:00
|
|
|
|
2012-07-09 22:08:01 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
2008-12-04 21:30:19 +00:00
|
|
|
|
2017-10-09 12:34:47 +01:00
|
|
|
UNORDERED_AUTO_TEST (assign_default_initializer_list) {
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Initializer List Tests\n";
|
2009-06-01 19:17:49 +00:00
|
|
|
std::initializer_list<std::pair<int const, int> > init;
|
2009-06-01 06:50:37 +00:00
|
|
|
boost::unordered_map<int, int> x1;
|
|
|
|
x1[25] = 3;
|
|
|
|
x1[16] = 10;
|
|
|
|
BOOST_TEST(!x1.empty());
|
|
|
|
x1 = init;
|
|
|
|
BOOST_TEST(x1.empty());
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2009-06-01 06:50:37 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-07-09 22:08:01 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
2017-10-09 12:34:47 +01:00
|
|
|
UNORDERED_AUTO_TEST (assign_initializer_list) {
|
2017-05-10 19:02:47 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Initializer List Tests\n";
|
2008-12-04 21:30:19 +00:00
|
|
|
|
|
|
|
boost::unordered_set<int> x;
|
|
|
|
x.insert(10);
|
|
|
|
x.insert(20);
|
2017-02-19 13:05:17 +00:00
|
|
|
x = {1, 2, -10};
|
2009-05-27 17:44:09 +00:00
|
|
|
BOOST_TEST(x.find(10) == x.end());
|
|
|
|
BOOST_TEST(x.find(-10) != x.end());
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2008-12-04 21:30:19 +00:00
|
|
|
|
|
|
|
#endif
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
2008-03-24 17:03:15 +00:00
|
|
|
|
|
|
|
RUN_TESTS()
|