Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80227 - in trunk/libs/unordered/test: exception unordered
From: dnljms_at_[hidden]
Date: 2012-08-25 17:55:47


Author: danieljames
Date: 2012-08-25 17:55:46 EDT (Sat, 25 Aug 2012)
New Revision: 80227
URL: http://svn.boost.org/trac/boost/changeset/80227

Log:
Unordered: Stronger assign testing.
Text files modified:
   trunk/libs/unordered/test/exception/assign_exception_tests.cpp | 30 ++++++++++++++--
   trunk/libs/unordered/test/unordered/assign_tests.cpp | 71 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 96 insertions(+), 5 deletions(-)

Modified: trunk/libs/unordered/test/exception/assign_exception_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/exception/assign_exception_tests.cpp (original)
+++ trunk/libs/unordered/test/exception/assign_exception_tests.cpp 2012-08-25 17:55:46 EDT (Sat, 25 Aug 2012)
@@ -39,26 +39,40 @@
 struct assign_base : public test::exception_base
 {
     const test::random_values<T> x_values, y_values;
- const T x,y;
+ T x,y;
 
     typedef BOOST_DEDUCED_TYPENAME T::hasher hasher;
     typedef BOOST_DEDUCED_TYPENAME T::key_equal key_equal;
     typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type;
 
- assign_base(unsigned int count1, unsigned int count2, int tag1, int tag2) :
+ assign_base(unsigned int count1, unsigned int count2, int tag1, int tag2,
+ float mlf1 = 1.0, float mlf2 = 1.0) :
         x_values(count1),
         y_values(count2),
         x(x_values.begin(), x_values.end(), 0, hasher(tag1), key_equal(tag1),
             allocator_type(tag1)),
         y(y_values.begin(), y_values.end(), 0, hasher(tag2), key_equal(tag2),
             allocator_type(tag2))
- {}
+ {
+ x.max_load_factor(mlf1);
+ y.max_load_factor(mlf2);
+ }
 
     typedef T data_type;
     T init() const { return T(x); }
     void run(T& x1) const { x1 = y; }
     void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x1) const
- { test::check_equivalent_keys(x1); }
+ {
+ test::check_equivalent_keys(x1);
+
+ // If the container is empty at the point of the exception, the
+ // internal structure is hidden, this exposes it.
+ T& y = const_cast<T&>(x1);
+ if (x_values.size()) {
+ y.emplace(*x_values.begin());
+ test::check_equivalent_keys(y);
+ }
+ }
 };
 
 template <class T>
@@ -85,7 +99,13 @@
     assign_test4() : assign_base<T>(10, 10, 1, 2) {}
 };
 
+template <class T>
+struct assign_test5 : assign_base<T>
+{
+ assign_test5() : assign_base<T>(5, 60, 0, 0, 1.0, 0.1) {}
+};
+
 RUN_EXCEPTION_TESTS(
     (self_assign_test1)(self_assign_test2)
- (assign_test1)(assign_test2)(assign_test3)(assign_test4),
+ (assign_test1)(assign_test2)(assign_test3)(assign_test4)(assign_test5),
     CONTAINER_SEQ)

Modified: trunk/libs/unordered/test/unordered/assign_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/assign_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/assign_tests.cpp 2012-08-25 17:55:46 EDT (Sat, 25 Aug 2012)
@@ -63,6 +63,7 @@
         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());
     }
 }
 
@@ -87,9 +88,31 @@
         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());
+ }
+
+ std::cerr<<"assign_tests2.1a\n";
+ {
+ 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());
     }
 
     std::cerr<<"assign_tests2.2\n";
@@ -110,7 +133,55 @@
             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());
+ }
+
+ std::cerr<<"assign_tests2.3\n";
+ {
+ 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());
+ }
+
+ std::cerr<<"assign_tests2.4\n";
+ {
+ 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());
     }
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk