forked from boostorg/unordered
Test inserting and constructing from input iterators.
Check thrown exception types properly. Return by reference from 'get_key' so that the keys aren't copied. [SVN r3115]
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/test/exception_safety.hpp>
|
#include <boost/test/exception_safety.hpp>
|
||||||
#include "../helpers/random_values.hpp"
|
#include "../helpers/random_values.hpp"
|
||||||
|
#include "../helpers/input_iterator.hpp"
|
||||||
|
|
||||||
struct objects
|
struct objects
|
||||||
{
|
{
|
||||||
@@ -111,9 +112,20 @@ struct range_construct_test5 : public range<T>, objects
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Write a test using an input iterator.
|
template <class T>
|
||||||
|
struct input_range_construct_test : public range<T>, objects
|
||||||
|
{
|
||||||
|
input_range_construct_test() : range<T>(60) {}
|
||||||
|
|
||||||
|
void run() const {
|
||||||
|
T x(test::input_iterator(this->values.begin()),
|
||||||
|
test::input_iterator(this->values.end()),
|
||||||
|
0, hash, equal_to, allocator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
RUN_EXCEPTION_TESTS(
|
RUN_EXCEPTION_TESTS(
|
||||||
(construct_test1)(construct_test2)(construct_test3)(construct_test4)(construct_test5)
|
(construct_test1)(construct_test2)(construct_test3)(construct_test4)(construct_test5)
|
||||||
(range_construct_test1)(range_construct_test2)(range_construct_test3)(range_construct_test4)(range_construct_test5),
|
(range_construct_test1)(range_construct_test2)(range_construct_test3)(range_construct_test4)(range_construct_test5)
|
||||||
|
(input_range_construct_test),
|
||||||
CONTAINER_SEQ)
|
CONTAINER_SEQ)
|
||||||
|
@@ -25,7 +25,14 @@ struct erase_test_base : public test::exception_base
|
|||||||
}
|
}
|
||||||
|
|
||||||
void check(T const& x) const {
|
void check(T const& x) const {
|
||||||
// TODO: Check that exception was thrown by hash or predicate object?
|
std::string scope(test::scope);
|
||||||
|
|
||||||
|
// TODO: Instead of checking for 'operator==', I should check against
|
||||||
|
// a scope stack.
|
||||||
|
BOOST_CHECK(scope.find("hash::") != std::string::npos ||
|
||||||
|
scope.find("equal_to::") != std::string::npos ||
|
||||||
|
scope == "operator==(object, object)");
|
||||||
|
|
||||||
test::check_equivalent_keys(x);
|
test::check_equivalent_keys(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include "../helpers/random_values.hpp"
|
#include "../helpers/random_values.hpp"
|
||||||
#include "../helpers/invariants.hpp"
|
#include "../helpers/invariants.hpp"
|
||||||
#include "../helpers/strong.hpp"
|
#include "../helpers/strong.hpp"
|
||||||
|
#include "../helpers/input_iterator.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ struct insert_test_base : public test::exception_base
|
|||||||
void check(T const& x, strong_type const& strong) const {
|
void check(T const& x, strong_type const& strong) const {
|
||||||
std::string scope(test::scope);
|
std::string scope(test::scope);
|
||||||
|
|
||||||
if(scope.find_first_of("hash::operator()") == std::string::npos)
|
if(scope.find("hash::operator()") == std::string::npos)
|
||||||
strong.test(x);
|
strong.test(x);
|
||||||
test::check_equivalent_keys(x);
|
test::check_equivalent_keys(x);
|
||||||
}
|
}
|
||||||
|
@@ -33,9 +33,13 @@ struct rehash_test_base : public test::exception_base
|
|||||||
void check(T const& x, strong_type const& strong) const {
|
void check(T const& x, strong_type const& strong) const {
|
||||||
std::string scope(test::scope);
|
std::string scope(test::scope);
|
||||||
|
|
||||||
if(scope.find_first_of("hash::operator()") == std::string::npos &&
|
// TODO: Instead of checking for 'operator==', I should check against
|
||||||
scope.find_first_of("equal_to::operator()") == std::string::npos)
|
// a scope stack.
|
||||||
|
if(scope.find("hash::operator()") == std::string::npos &&
|
||||||
|
scope.find("equal_to::operator()") == std::string::npos &&
|
||||||
|
scope != "operator==(object, object)")
|
||||||
strong.test(x);
|
strong.test(x);
|
||||||
|
|
||||||
test::check_equivalent_keys(x);
|
test::check_equivalent_keys(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -78,3 +82,4 @@ struct rehash_test4 : rehash_test_base<T>
|
|||||||
RUN_EXCEPTION_TESTS(
|
RUN_EXCEPTION_TESTS(
|
||||||
(rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4),
|
(rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4),
|
||||||
CONTAINER_SEQ)
|
CONTAINER_SEQ)
|
||||||
|
|
||||||
|
@@ -13,26 +13,26 @@ namespace test
|
|||||||
{
|
{
|
||||||
typedef typename Container::key_type key_type;
|
typedef typename Container::key_type key_type;
|
||||||
|
|
||||||
static key_type get_key(key_type const& x)
|
static key_type const& get_key(key_type const& x)
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static key_type get_key(std::pair<key_type, T> const& x, char = 0)
|
static key_type const& get_key(std::pair<key_type, T> const& x, char = 0)
|
||||||
{
|
{
|
||||||
return x.first;
|
return x.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static key_type get_key(std::pair<key_type const, T> const& x, unsigned char = 0)
|
static key_type const& get_key(std::pair<key_type const, T> const& x, unsigned char = 0)
|
||||||
{
|
{
|
||||||
return x.first;
|
return x.first;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Container, class T>
|
template <class Container, class T>
|
||||||
inline typename Container::key_type get_key(T const& x)
|
inline typename Container::key_type const& get_key(T const& x)
|
||||||
{
|
{
|
||||||
return get_key_impl<Container>::get_key(x);
|
return get_key_impl<Container>::get_key(x);
|
||||||
}
|
}
|
||||||
|
37
test/helpers/input_iterator.hpp
Normal file
37
test/helpers/input_iterator.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
// Copyright 2005-2006 Daniel James.
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
#if !defined(BOOST_UNORDERED_TEST_HELPERS_INPUT_ITERATOR_HEADER)
|
||||||
|
#define BOOST_UNORDERED_TEST_HELPERS_INPUT_ITERATOR_HEADER
|
||||||
|
|
||||||
|
#include <boost/iterator_adaptors.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
namespace test
|
||||||
|
{
|
||||||
|
// TODO: Make this a stricter input iterator.
|
||||||
|
template <class Iterator>
|
||||||
|
struct input_iterator_adaptor
|
||||||
|
: boost::iterator_adaptor<
|
||||||
|
input_iterator_adaptor<Iterator>, Iterator,
|
||||||
|
boost::use_default, std::input_iterator_tag>
|
||||||
|
{
|
||||||
|
typedef boost::iterator_adaptor<
|
||||||
|
input_iterator_adaptor<Iterator>, Iterator,
|
||||||
|
boost::use_default, std::input_iterator_tag> base;
|
||||||
|
|
||||||
|
explicit input_iterator_adaptor(Iterator it = Iterator())
|
||||||
|
: base(it) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Iterator>
|
||||||
|
input_iterator_adaptor<Iterator> input_iterator(Iterator it)
|
||||||
|
{
|
||||||
|
return input_iterator_adaptor<Iterator>(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@@ -10,6 +10,7 @@
|
|||||||
#include "../helpers/random_values.hpp"
|
#include "../helpers/random_values.hpp"
|
||||||
#include "../helpers/tracker.hpp"
|
#include "../helpers/tracker.hpp"
|
||||||
#include "../helpers/equivalent.hpp"
|
#include "../helpers/equivalent.hpp"
|
||||||
|
#include "../helpers/input_iterator.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -204,6 +205,15 @@ void constructor_tests2(T* = 0)
|
|||||||
test::check_container(x, v);
|
test::check_container(x, v);
|
||||||
test::check_container(y, x);
|
test::check_container(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr<<"Construct 8 - from input iterator\n";
|
||||||
|
{
|
||||||
|
test::random_values<T> v(100);
|
||||||
|
T x(test::input_iterator(v.begin()), test::input_iterator(v.end()), 0, hf1, eq1);
|
||||||
|
T y(test::input_iterator(x.begin()), test::input_iterator(x.end()), 0, hf2, eq2);
|
||||||
|
test::check_container(x, v);
|
||||||
|
test::check_container(y, x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@@ -78,7 +78,6 @@ void erase_tests1(Container* = 0)
|
|||||||
BOOST_TEST(next ==
|
BOOST_TEST(next ==
|
||||||
(index == 0 ? x.begin() : boost::next(prev)));
|
(index == 0 ? x.begin() : boost::next(prev)));
|
||||||
BOOST_TEST(x.count(key) == count - 1);
|
BOOST_TEST(x.count(key) == count - 1);
|
||||||
std::cerr<<x.count(key)<<"/"<<(count - 1)<<"\n";
|
|
||||||
BOOST_TEST(x.size() == size);
|
BOOST_TEST(x.size() == size);
|
||||||
}
|
}
|
||||||
BOOST_TEST(x.empty());
|
BOOST_TEST(x.empty());
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include "../helpers/tracker.hpp"
|
#include "../helpers/tracker.hpp"
|
||||||
#include "../helpers/equivalent.hpp"
|
#include "../helpers/equivalent.hpp"
|
||||||
#include "../helpers/invariants.hpp"
|
#include "../helpers/invariants.hpp"
|
||||||
|
#include "../helpers/input_iterator.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -199,6 +200,19 @@ void insert_tests2(X* = 0)
|
|||||||
|
|
||||||
test::check_equivalent_keys(x);
|
test::check_equivalent_keys(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr<<"insert input iterator range tests.\n";
|
||||||
|
|
||||||
|
{
|
||||||
|
X x;
|
||||||
|
const_iterator pos = x.begin();
|
||||||
|
|
||||||
|
test::random_values<X> v(1000);
|
||||||
|
x.insert(test::input_iterator(v.begin()), test::input_iterator(v.end()));
|
||||||
|
test::check_container(x, v);
|
||||||
|
|
||||||
|
test::check_equivalent_keys(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
|
Reference in New Issue
Block a user