forked from boostorg/unordered
More tests for unordered associative containers.
[SVN r2959]
This commit is contained in:
1 parent
822b0c7ffd
commit
fbd37a946b
28 files changed
+1975
-86
No files matched your search
@@ -15,20 +15,38 @@
|
||||
namespace test
|
||||
{
|
||||
template <class T>
|
||||
bool equivalent(T const& x, T const& y) {
|
||||
bool equivalent_impl(T const& x, T const& y) {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool equivalent(boost::hash<T> const&, boost::hash<T> const&) {
|
||||
bool equivalent_impl(boost::hash<T> const&, boost::hash<T> const&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool equivalent(std::equal_to<T> const&, std::equal_to<T> const&) {
|
||||
bool equivalent_impl(std::equal_to<T> const&, std::equal_to<T> const&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T1, class T2, class T3, class T4>
|
||||
bool equivalent_impl(std::pair<T1, T2> const& x1,
|
||||
std::pair<T3, T4> const& x2) {
|
||||
return equivalent_impl(x1.first, x2.first) &&
|
||||
equivalent_impl(x1.second, x2.second);
|
||||
}
|
||||
|
||||
struct equivalent_type {
|
||||
template <class T1, class T2>
|
||||
bool operator()(T1 const& x, T2 const& y) {
|
||||
return equivalent_impl(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
equivalent_type equivalent;
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
class unordered_equivalence_tester
|
||||
{
|
||||
@@ -56,8 +74,8 @@ namespace test
|
||||
bool operator()(Container const& x) const
|
||||
{
|
||||
if(!((size_ == x.size()) &&
|
||||
(test::equivalent(hasher_, x.hash_function())) &&
|
||||
(test::equivalent(key_equal_, x.key_eq())) &&
|
||||
(test::equivalent_impl(hasher_, x.hash_function())) &&
|
||||
(test::equivalent_impl(key_equal_, x.key_eq())) &&
|
||||
(max_load_factor_ == x.max_load_factor()) &&
|
||||
(values_.size() == x.size()))) return false;
|
||||
|
||||
|
||||
+24
-17
@@ -51,23 +51,30 @@ namespace test
|
||||
if(x1.count(key) != count)
|
||||
BOOST_ERROR("Incorrect output of count.");
|
||||
|
||||
// Check that the keys are in the correct bucket and are adjacent in
|
||||
// the bucket.
|
||||
typename X::size_type bucket = x1.bucket(key);
|
||||
typename X::const_local_iterator lit = x1.begin(bucket), lend = x1.end(bucket);
|
||||
for(; lit != lend && !eq(get_key<X>(*lit), key); ++lit) continue;
|
||||
if(lit == lend)
|
||||
BOOST_ERROR("Unable to find element with a local_iterator");
|
||||
unsigned int count2 = 0;
|
||||
for(; lit != lend && eq(get_key<X>(*lit), key); ++lit) ++count2;
|
||||
if(count != count2)
|
||||
BOOST_ERROR("Element count doesn't match local_iterator.");
|
||||
for(; lit != lend; ++lit) {
|
||||
if(eq(get_key<X>(*lit), key)) {
|
||||
BOOST_ERROR("Non-adjacent element with equivalent key in bucket.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// I'm not bothering with the following test for now, as the
|
||||
// previous test is probably more enough to catch the kind of
|
||||
// errors that this would catch (if an element was in the wrong
|
||||
// bucket it not be found by the call to count, if elements are not
|
||||
// adjacent then they would be caught when checking against
|
||||
// found_.
|
||||
|
||||
// // Check that the keys are in the correct bucket and are
|
||||
// // adjacent in the bucket.
|
||||
// typename X::size_type bucket = x1.bucket(key);
|
||||
// typename X::const_local_iterator lit = x1.begin(bucket), lend = x1.end(bucket);
|
||||
// for(; lit != lend && !eq(get_key<X>(*lit), key); ++lit) continue;
|
||||
// if(lit == lend)
|
||||
// BOOST_ERROR("Unable to find element with a local_iterator");
|
||||
// unsigned int count2 = 0;
|
||||
// for(; lit != lend && eq(get_key<X>(*lit), key); ++lit) ++count2;
|
||||
// if(count != count2)
|
||||
// BOOST_ERROR("Element count doesn't match local_iterator.");
|
||||
// for(; lit != lend; ++lit) {
|
||||
// if(eq(get_key<X>(*lit), key)) {
|
||||
// BOOST_ERROR("Non-adjacent element with equivalent key in bucket.");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
// Finally, check that size matches up.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
// Copyright Daniel James 2005. Use, modification, and distribution are
|
||||
// Copyright Daniel James 2005-2006. Use, modification, and distribution are
|
||||
// subject to 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)
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
// Copyright Daniel James 2006. Use, modification, and distribution are
|
||||
// subject to 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)
|
||||
|
||||
#if !defined(BOOST_UNORDERED_TEST_HELPERS_STRONG_HEADER)
|
||||
#define BOOST_UNORDERED_TEST_HELPERS_STRONG_HEADER
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include "./metafunctions.hpp"
|
||||
#include "./equivalent.hpp"
|
||||
#include "../objects/exception.hpp"
|
||||
|
||||
namespace test
|
||||
{
|
||||
template <class X>
|
||||
class strong
|
||||
{
|
||||
typedef std::vector<typename non_const_value_type<X>::type> values_type;
|
||||
values_type values_;
|
||||
public:
|
||||
void store(X const& x) {
|
||||
// TODO: Well, I shouldn't be disabling exceptions here. Instead
|
||||
// the test runner should provide a method to the test which
|
||||
// disables exceptions and calls this.
|
||||
//
|
||||
// Actually, the test runner could also keep track of how many times
|
||||
// store is called in a run. Because it knows that in the next run
|
||||
// the first n-1 stores are unnecessary - since no exceptions will
|
||||
// be thrown for them.
|
||||
DISABLE_EXCEPTIONS;
|
||||
values_.clear();
|
||||
values_.reserve(x.size());
|
||||
std::copy(x.cbegin(), x.cend(), std::back_inserter(values_));
|
||||
}
|
||||
|
||||
void test(X const& x) const {
|
||||
if(!(x.size() == values_.size() &&
|
||||
std::equal(x.cbegin(), x.cend(), values_.begin(), test::equivalent)))
|
||||
BOOST_ERROR("Strong exception safety failure.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user