forked from boostorg/unordered
Add a test that unnecessary copies aren't made of objects inserted.
Make the exception tests track the allocator usage. Speed up the exception tests a bit. [SVN r3490]
This commit is contained in:
@@ -18,6 +18,7 @@ test-suite unordered-tests
|
||||
[ run copy_tests.cpp ]
|
||||
[ run assign_tests.cpp ]
|
||||
[ run insert_tests.cpp ]
|
||||
[ run unnecessary_copy_tests.cpp ]
|
||||
[ run erase_tests.cpp ]
|
||||
[ run erase_equiv_tests.cpp ]
|
||||
[ run find_tests.cpp ]
|
||||
|
||||
@@ -74,11 +74,10 @@ void swap_tests2(X* ptr = 0)
|
||||
X x(v.begin(), v.end(), 0, hasher(1), key_equal(1));
|
||||
X y(0, hasher(2), key_equal(2));
|
||||
swap_test_impl(x, y);
|
||||
swap_test_impl(x, y);
|
||||
}
|
||||
|
||||
{
|
||||
test::random_values<X> vx(1000), vy(1000);
|
||||
test::random_values<X> vx(100), vy(50);
|
||||
X x(vx.begin(), vx.end(), 0, hasher(1), key_equal(1));
|
||||
X y(vy.begin(), vy.end(), 0, hasher(2), key_equal(2));
|
||||
swap_test_impl(x, y);
|
||||
@@ -87,7 +86,7 @@ void swap_tests2(X* ptr = 0)
|
||||
|
||||
#if BOOST_UNORDERED_SWAP_METHOD == 1
|
||||
{
|
||||
test::random_values<X> vx(1000), vy(1000);
|
||||
test::random_values<X> vx(100), vy(50);
|
||||
X x(vx.begin(), vx.end(), 0, hasher(), key_equal(), allocator_type(1));
|
||||
X y(vy.begin(), vy.end(), 0, hasher(), key_equal(), allocator_type(2));
|
||||
try {
|
||||
@@ -97,15 +96,14 @@ void swap_tests2(X* ptr = 0)
|
||||
}
|
||||
#else
|
||||
{
|
||||
test::random_values<X> vx(1000), vy(1000);
|
||||
test::random_values<X> vx(50), vy(100);
|
||||
X x(vx.begin(), vx.end(), 0, hasher(), key_equal(), allocator_type(1));
|
||||
X y(vy.begin(), vy.end(), 0, hasher(), key_equal(), allocator_type(2));
|
||||
swap_test_impl(x, y);
|
||||
swap_test_impl(x, y);
|
||||
}
|
||||
|
||||
{
|
||||
test::random_values<X> vx(1000), vy(1000);
|
||||
test::random_values<X> vx(100), vy(100);
|
||||
X x(vx.begin(), vx.end(), 0, hasher(1), key_equal(1), allocator_type(1));
|
||||
X y(vy.begin(), vy.end(), 0, hasher(2), key_equal(2), allocator_type(2));
|
||||
swap_test_impl(x, y);
|
||||
|
||||
49
test/unordered/unnecessary_copy_tests.cpp
Normal file
49
test/unordered/unnecessary_copy_tests.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
// Copyright 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)
|
||||
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
struct count_copies
|
||||
{
|
||||
static int count;
|
||||
count_copies() { ++count; }
|
||||
count_copies(count_copies const& x) { ++count; }
|
||||
private:
|
||||
count_copies& operator=(count_copies const&);
|
||||
};
|
||||
|
||||
std::size_t hash_value(count_copies const& x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool operator==(count_copies const& x, count_copies const& y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int count_copies::count;
|
||||
|
||||
template <class T>
|
||||
void unnecessary_copy_test(T*)
|
||||
{
|
||||
count_copies::count = 0;
|
||||
T x;
|
||||
typename T::value_type a;
|
||||
BOOST_TEST(count_copies::count == 1);
|
||||
x.insert(a);
|
||||
BOOST_TEST(count_copies::count == 2);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
unnecessary_copy_test((boost::unordered_set<count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_multiset<count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_map<int, count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_multimap<int, count_copies>*) 0);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user