Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49924 - trunk/libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2008-11-24 17:55:14


Author: danieljames
Date: 2008-11-24 17:55:14 EST (Mon, 24 Nov 2008)
New Revision: 49924
URL: http://svn.boost.org/trac/boost/changeset/49924

Log:
Extra tests for equality with different hash functions.
Text files modified:
   trunk/libs/unordered/test/unordered/equality_tests.cpp | 25 ++++++++++++++++++++++++-
   1 files changed, 24 insertions(+), 1 deletions(-)

Modified: trunk/libs/unordered/test/unordered/equality_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/equality_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/equality_tests.cpp 2008-11-24 17:55:14 EST (Mon, 24 Nov 2008)
@@ -13,6 +13,10 @@
 {
     struct mod_compare
     {
+ bool alt_hash_;
+
+ explicit mod_compare(bool alt_hash = false) : alt_hash_(alt_hash) {}
+
         bool operator()(int x, int y) const
         {
             return x % 1000 == y % 1000;
@@ -20,7 +24,7 @@
 
         int operator()(int x) const
         {
- return x % 250;
+ return alt_hash_ ? x % 250 : (x + 5) % 250;
         }
     };
 
@@ -138,6 +142,25 @@
             ((1)(2))((1001)(1)), ==, ((1001)(2))((1)(1)));
     }
 
+ // Test that equality still works when the two containers have
+ // different hash functions but the same equality predicate.
+
+ UNORDERED_AUTO_TEST(equality_different_hash_test)
+ {
+ typedef boost::unordered_set<int, mod_compare, mod_compare> set;
+ set set1(0, mod_compare(false), mod_compare(false));
+ set set2(0, mod_compare(true), mod_compare(true));
+ BOOST_CHECK(set1 == set2);
+ set1.insert(1); set2.insert(2);
+ BOOST_CHECK(set1 != set2);
+ set1.insert(2); set2.insert(1);
+ BOOST_CHECK(set1 == set2);
+ set1.insert(10); set2.insert(20);
+ BOOST_CHECK(set1 != set2);
+ set1.insert(20); set2.insert(10);
+ BOOST_CHECK(set1 == set2);
+ }
+
 }
 
 RUN_TESTS()


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