Boost logo

Boost-Commit :

From: danieljames_at_[hidden]
Date: 2007-07-17 19:17:22


Author: danieljames
Date: 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
New Revision: 7458
URL: http://svn.boost.org/trac/boost/changeset/7458

Log:
Improve the unordered tests support for some older compilers.
Better testing of elements with equivalent keys.

Text files modified:
   sandbox/unordered/libs/unordered/test/helpers/fwd.hpp | 1
   sandbox/unordered/libs/unordered/test/helpers/generators.hpp | 6 ++
   sandbox/unordered/libs/unordered/test/objects/exception.hpp | 11 ++--
   sandbox/unordered/libs/unordered/test/objects/test.hpp | 96 +++++++++++++++++++++++++++++++++++++++
   sandbox/unordered/libs/unordered/test/unordered/assign_tests.cpp | 9 ++
   sandbox/unordered/libs/unordered/test/unordered/constructor_tests.cpp | 18 +++++++
   sandbox/unordered/libs/unordered/test/unordered/copy_tests.cpp | 5 ++
   sandbox/unordered/libs/unordered/test/unordered/erase_equiv_tests.cpp | 24 +++++-----
   sandbox/unordered/libs/unordered/test/unordered/erase_tests.cpp | 9 +++
   sandbox/unordered/libs/unordered/test/unordered/find_tests.cpp | 5 ++
   sandbox/unordered/libs/unordered/test/unordered/insert_tests.cpp | 12 +++++
   11 files changed, 176 insertions(+), 20 deletions(-)

Modified: sandbox/unordered/libs/unordered/test/helpers/fwd.hpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/helpers/fwd.hpp (original)
+++ sandbox/unordered/libs/unordered/test/helpers/fwd.hpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -12,6 +12,7 @@
 {
     int generate(int const*);
     char generate(char const*);
+ signed char generate(signed char const*);
     std::string generate(std::string*);
     float generate(float const*);
     template <class T1, class T2>

Modified: sandbox/unordered/libs/unordered/test/helpers/generators.hpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/helpers/generators.hpp (original)
+++ sandbox/unordered/libs/unordered/test/helpers/generators.hpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -56,6 +56,12 @@
         return (rand() >> 1) % (128-32) + 32;
     }
 
+ inline signed char generate(signed char const*)
+ {
+ using namespace std;
+ return rand();
+ }
+
     inline std::string generate(std::string const*)
     {
         using namespace std;

Modified: sandbox/unordered/libs/unordered/test/objects/exception.hpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/objects/exception.hpp (original)
+++ sandbox/unordered/libs/unordered/test/objects/exception.hpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -624,13 +624,14 @@
             }
             return (std::numeric_limits<std::size_t>::max)();
         }
-
- friend void swap(allocator<T>& x, allocator<T>& y)
- {
- std::swap(x.tag_, y.tag_);
- }
     };
 
+ template <class T>
+ void swap(allocator<T>& x, allocator<T>& y)
+ {
+ std::swap(x.tag_, y.tag_);
+ }
+
     // It's pretty much impossible to write a compliant swap when these
     // two can throw. So they don't.
 

Modified: sandbox/unordered/libs/unordered/test/objects/test.hpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/objects/test.hpp (original)
+++ sandbox/unordered/libs/unordered/test/objects/test.hpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -50,7 +50,6 @@
                 (x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_);
         }
 
-
         friend object generate(object const*) {
             int* x = 0;
             return object(generate(x), generate(x));
@@ -62,6 +61,44 @@
         }
     };
 
+ // This object is usd to test how well the containers cope with equivalent keys.
+ class equivalent_object
+ {
+ friend class hash;
+ friend class equal_to;
+ friend class less;
+ int tag1_, tag2_;
+ public:
+ explicit equivalent_object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {}
+
+ ~equivalent_object() {
+ tag1_ = -1;
+ tag2_ = -1;
+ }
+
+ friend bool operator==(equivalent_object const& x1, equivalent_object const& x2) {
+ return x1.tag1_ == x2.tag1_;
+ }
+
+ friend bool operator!=(equivalent_object const& x1, equivalent_object const& x2) {
+ return x1.tag1_ != x2.tag1_;
+ }
+
+ friend bool operator<(equivalent_object const& x1, equivalent_object const& x2) {
+ return x1.tag1_ < x2.tag1_;
+ }
+
+ friend equivalent_object generate(equivalent_object const*) {
+ signed char* x = 0;
+ return equivalent_object(generate(x), generate(x));
+ }
+
+ friend std::ostream& operator<<(std::ostream& out, equivalent_object const& o)
+ {
+ return out<<"("<<o.tag1_<<","<<o.tag2_<<")";
+ }
+ };
+
     class hash
     {
         int type_;
@@ -79,6 +116,10 @@
             }
         }
 
+ std::size_t operator()(equivalent_object const& x) const {
+ return x.tag1_;
+ }
+
         std::size_t operator()(int x) const {
             return x;
         }
@@ -109,6 +150,10 @@
             }
         }
 
+ bool operator()(equivalent_object const& x1, equivalent_object const& x2) const {
+ return x1 < x2;
+ }
+
         std::size_t operator()(int x1, int x2) const {
             return x1 < x2;
         }
@@ -135,6 +180,10 @@
             }
         }
 
+ bool operator()(equivalent_object const& x1, equivalent_object const& x2) const {
+ return x1 == x2;
+ }
+
         std::size_t operator()(int x1, int x2) const {
             return x1 == x2;
         }
@@ -359,6 +408,51 @@
     bool equivalent_impl(allocator<T> const& x, allocator<T> const& y, test::derived_type) {
         return x == y;
     }
+
+#if BOOST_WORKAROUND(__GNUC__, < 3)
+ void swap(test::object& x, test::object& y) {
+ test::object tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ void swap(test::equivalent_object& x, test::equivalent_object& y) {
+ test::equivalent_object tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ void swap(test::hash& x, test::hash& y) {
+ test::hash tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ void swap(test::less& x, test::less& y) {
+ test::less tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ void swap(test::equal_to& x, test::equal_to& y) {
+ test::equal_to tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ template <class T>
+ void swap(test::allocator<T>& x, test::allocator<T>& y) {
+ test::allocator<T> tmp;
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+#endif
 }
 
 #endif

Modified: sandbox/unordered/libs/unordered/test/unordered/assign_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/assign_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/assign_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -95,9 +95,14 @@
     assign_tests1((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     assign_tests1((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ assign_tests1((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ assign_tests1((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ assign_tests1((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ assign_tests1((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     assign_tests2((boost::unordered_set<test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
- assign_tests2((boost::unordered_multiset<test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
- assign_tests2((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
+ assign_tests2((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ assign_tests2((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
     assign_tests2((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
     return boost::report_errors();

Modified: sandbox/unordered/libs/unordered/test/unordered/constructor_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/constructor_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/constructor_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -273,6 +273,15 @@
     std::cerr<<"Test1 unordered_multimap<test::object, test::object>\n";
     constructor_tests1((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ std::cerr<<"Test1 unordered_set<test::equivalent_object>\n";
+ constructor_tests1((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test1 unordered_multiset<test::equivalent_object>\n";
+ constructor_tests1((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test1 unordered_map<test::equivalent_object, test::equivalent_object>\n";
+ constructor_tests1((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test1 unordered_multimap<test::equivalent_object, test::equivalent_object>\n";
+ constructor_tests1((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     std::cerr<<"Test2 unordered_set<test::object>\n";
     constructor_tests2((boost::unordered_set<test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     std::cerr<<"Test2 unordered_multiset<test::object>\n";
@@ -282,6 +291,15 @@
     std::cerr<<"Test2 unordered_multimap<test::object, test::object>\n";
     constructor_tests2((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ std::cerr<<"Test2 unordered_set<test::equivalent_object>\n";
+ constructor_tests2((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test2 unordered_multiset<test::equivalent_object>\n";
+ constructor_tests2((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test2 unordered_map<test::equivalent_object, test::equivalent_object>\n";
+ constructor_tests2((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"Test2 unordered_multimap<test::equivalent_object, test::equivalent_object>\n";
+ constructor_tests2((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     std::cerr<<"Map Test unordered_map<test::object, test::object>\n";
     map_constructor_test((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     std::cerr<<"Map Test unordered_multimap<test::object, test::object>\n";

Modified: sandbox/unordered/libs/unordered/test/unordered/copy_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/copy_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/copy_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -100,5 +100,10 @@
     copy_construct_tests2((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     copy_construct_tests2((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ copy_construct_tests2((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ copy_construct_tests2((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ copy_construct_tests2((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ copy_construct_tests2((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     return boost::report_errors();
 }

Modified: sandbox/unordered/libs/unordered/test/unordered/erase_equiv_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/erase_equiv_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/erase_equiv_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -49,8 +49,8 @@
 typedef boost::unordered_multimap<int, int,
     collision2_hash, std::equal_to<int>,
     test::allocator<std::pair<int const, int> > > collide_map2;
-typedef collide_map::value_type pair;
-typedef std::list<pair> list;
+typedef collide_map::value_type collide_value;
+typedef std::list<collide_value> collide_list;
 
 
 void empty_range_tests()
@@ -63,8 +63,8 @@
 
 void single_item_tests()
 {
- list init;
- init.push_back(pair(1,1));
+ collide_list init;
+ init.push_back(collide_value(1,1));
 
     collide_map x(init.begin(), init.end());
     x.erase(x.begin(), x.begin());
@@ -77,9 +77,9 @@
 
 void two_equivalent_item_tests()
 {
- list init;
- init.push_back(pair(1,1));
- init.push_back(pair(1,2));
+ collide_list init;
+ init.push_back(collide_value(1,1));
+ init.push_back(collide_value(1,2));
 
     {
         collide_map x(init.begin(), init.end());
@@ -109,8 +109,8 @@
 template<class Range1, class Range2>
 bool compare(Range1 const& x, Range2 const& y)
 {
- list a;
- list b;
+ collide_list a;
+ collide_list b;
     std::copy(x.begin(), x.end(), std::back_inserter(a));
     std::copy(y.begin(), y.end(), std::back_inserter(b));
     a.sort();
@@ -121,7 +121,7 @@
 template <class Container>
 bool general_erase_range_test(Container& x, int start, int end)
 {
- list l;
+ collide_list l;
     std::copy(x.begin(), x.end(), std::back_inserter(l));
     l.erase(boost::next(l.begin(), start), boost::next(l.begin(), end));
     x.erase(boost::next(x.begin(), start), boost::next(x.begin(), end));
@@ -134,7 +134,7 @@
     for(std::size_t length = 0; length < x.size(); ++length) {
         for(std::size_t position = 0; position < x.size() - length; ++position) {
             Container y(x);
- list init;
+ collide_list init;
             std::copy(y.begin(), y.end(), std::back_inserter(init));
             if(!general_erase_range_test(y, position, position + length)) {
                 BOOST_ERROR("general_erase_range_test failed.");
@@ -153,7 +153,7 @@
 
     for(int i = 0; i < values; ++i) {
         for(int j = 0; j < duplicates; ++j) {
- y.insert(pair(i, j));
+ y.insert(collide_value(i, j));
         }
     }
 

Modified: sandbox/unordered/libs/unordered/test/unordered/erase_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/erase_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/erase_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -135,5 +135,14 @@
     std::cerr<<"\nErase unordered_multimap<test::object,..>.\n";
     erase_tests1((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ std::cerr<<"\nErase unordered_set<test::equivalent_object,..>.\n";
+ erase_tests1((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"\nErase unordered_multiset<test::equivalent_object,..>.\n";
+ erase_tests1((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"\nErase unordered_map<test::equivalent_object,..>.\n";
+ erase_tests1((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ std::cerr<<"\nErase unordered_multimap<test::equivalent_object,..>.\n";
+ erase_tests1((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     return boost::report_errors();
 }

Modified: sandbox/unordered/libs/unordered/test/unordered/find_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/find_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/find_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -88,5 +88,10 @@
     find_tests1((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     find_tests1((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ find_tests1((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ find_tests1((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ find_tests1((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ find_tests1((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     return 0;
 }

Modified: sandbox/unordered/libs/unordered/test/unordered/insert_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/insert_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/insert_tests.cpp 2007-07-17 19:17:21 EDT (Tue, 17 Jul 2007)
@@ -269,6 +269,11 @@
     unique_insert_tests1((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     equivalent_insert_tests1((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ unique_insert_tests1((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ equivalent_insert_tests1((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ unique_insert_tests1((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ equivalent_insert_tests1((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     insert_tests2((boost::unordered_set<int>*) 0);
     insert_tests2((boost::unordered_multiset<int>*) 0);
     insert_tests2((boost::unordered_map<int, int>*) 0);
@@ -279,11 +284,18 @@
     insert_tests2((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     insert_tests2((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
 
+ insert_tests2((boost::unordered_set<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ insert_tests2((boost::unordered_multiset<test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ insert_tests2((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+ insert_tests2((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
+
     map_tests((boost::unordered_map<int, int>*) 0);
     map_tests((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
+ map_tests((boost::unordered_map<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
 
     associative_insert_range_test((boost::unordered_map<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
     associative_insert_range_test((boost::unordered_multimap<test::object, test::object, test::hash, test::equal_to, test::allocator<test::object> >*) 0);
+ associative_insert_range_test((boost::unordered_multimap<test::equivalent_object, test::equivalent_object, test::hash, test::equal_to, test::allocator<test::equivalent_object> >*) 0);
 
     return boost::report_errors();
 }


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