diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 deleted file mode 100644 index 7704f38c..00000000 --- a/test/Jamfile.v2 +++ /dev/null @@ -1,63 +0,0 @@ - -# Copyright Daniel James 2005. 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) - -import testing ; - -project unordered-test - : requirements - intel-linux:"-strict_ansi -cxxlib-icc" - # off - # TODO: Make this an option: - REDUCED_TESTS - ; - -lib helpers - : - [ glob helpers/*.cpp ] - ; - -framework = helpers/static /boost/test//boost_unit_test_framework ; - -test-suite helpers-test - : - [ run-fail helpers-test/simple_test.cpp $(framework) ] - [ run-fail helpers-test/allocator_test.cpp $(framework) ] - [ run helpers-test/exception_test.cpp $(framework) ] - ; - -test-suite compile-tests - : - [ compile-fail const_local_iterator_fail_test.cpp ] - [ compile-fail const_iterator_fail_test.cpp ] - [ compile-fail set_assign_fail_test.cpp ] - [ compile type_tests.cpp ] - [ run concept_test.cpp ] - ; - -test-suite basic-tests - : - [ run container_tests.cpp $(framework) ] - [ run iterator_tests.cpp $(framework) ] - [ run next_prime_tests.cpp $(framework) ] - [ run max_load_factor_test.cpp $(framework) ] - ; - -test-suite less-base-tests - : - [ run construct_tests.cpp $(framework) ] - [ run find_tests.cpp $(framework) ] - [ run count_tests.cpp $(framework) ] - [ run equal_range_tests.cpp $(framework) ] - [ run copy_construct_tests.cpp $(framework) ] - [ run swap_tests1.cpp $(framework) ] - [ run swap_tests2.cpp $(framework) ] - [ run swap_tests3.cpp $(framework) ] - [ run assign_tests.cpp $(framework) ] - [ run clear_tests.cpp $(framework) ] - [ run erase_tests.cpp $(framework) ] - [ run insert_tests.cpp $(framework) ] - [ run map_operator_tests.cpp $(framework) ] - ; - diff --git a/test/assign_tests.cpp b/test/assign_tests.cpp deleted file mode 100644 index 8d3e45ae..00000000 --- a/test/assign_tests.cpp +++ /dev/null @@ -1,86 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./helpers/constructors.hpp" -#include "./helpers/equivalent.hpp" -#include "./invariant.hpp" - -const int num_values = 50; - -META_FUNC_TEST_CASE(assign_test1, Container) -{ - test::constructors constructor; - - test::random_values values(num_values); - Container x(values.begin(), values.end(), 0, - constructor.hasher(55), constructor.key_equal(55), - constructor.allocator(10)); - x.max_load_factor(0.1); - - EXCEPTION_TEST(10000) - { - DEACTIVATE_EXCEPTIONS; - Container y; - INVARIANT_CHECK(y); - ACTIVATE_EXCEPTIONS; - - BOOST_CHECKPOINT("y = x"); - y = x; - - { - DEACTIVATE_EXCEPTIONS; - BOOST_CHECK_EQUAL(y.size(), x.size()); - BOOST_CHECK(test::equivalent(y.hash_function(), x.hash_function())); - BOOST_CHECK(test::equivalent(y.key_eq(), x.key_eq())); - BOOST_CHECK_EQUAL(y.max_load_factor(), x.max_load_factor()); - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator())); - BOOST_CHECK(y.load_factor() <= y.max_load_factor()); - test::check_invariants(); - } - - BOOST_CHECKPOINT("y = y"); - y = y; - - { - DEACTIVATE_EXCEPTIONS; - BOOST_CHECK_EQUAL(y.size(), x.size()); - BOOST_CHECK(test::equivalent(y.hash_function(), x.hash_function())); - BOOST_CHECK(test::equivalent(y.key_eq(), x.key_eq())); - BOOST_CHECK_EQUAL(y.max_load_factor(), x.max_load_factor()); - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator())); - BOOST_CHECK(y.load_factor() <= y.max_load_factor()); - test::check_invariants(); - } - - BOOST_CHECKPOINT("y = Container(values.begin(), values.end())"); - y = Container(values.begin(), values.end()); - - { - DEACTIVATE_EXCEPTIONS; - BOOST_CHECK_EQUAL(y.size(), x.size()); - BOOST_CHECK(test::equivalent(y.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(y.key_eq(), constructor.key_equal())); - BOOST_CHECK_EQUAL(y.max_load_factor(), 1.0); - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator())); - BOOST_CHECK(y.load_factor() <= 1.0); - test::check_invariants(); - } - } - EXCEPTION_TEST_END -} - -AUTO_META_TESTS( - (assign_test1), - CONTAINER_SEQ -) diff --git a/test/basic_tests.cpp b/test/basic_tests.cpp deleted file mode 100644 index 177edbcb..00000000 --- a/test/basic_tests.cpp +++ /dev/null @@ -1,207 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include -#include -#include -#include -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" - -typedef double comparison_type; - -template -struct check_return_type -{ - template - static void equals(T2) - { - BOOST_MPL_ASSERT((boost::is_same)); - } - - template - static void equals_ref(T2&) - { - BOOST_MPL_ASSERT((boost::is_same)); - } - - template - static void convertible(T2) - { - BOOST_MPL_ASSERT((boost::is_convertible)); - } -}; - -// 23.1.5 -template -void container_tests(X*, T*) -{ - typedef typename X::iterator iterator; - typedef typename X::const_iterator const_iterator; - typedef typename X::difference_type difference_type; - typedef typename X::size_type size_type; - - BOOST_MPL_ASSERT((boost::is_same)); - // TODO: Actually 'lvalue of T' - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - // TODO: Iterator checks. - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT_NOT((boost::is_same, std::output_iterator_tag>)); - BOOST_MPL_ASSERT((boost::is_convertible)); - - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT_NOT((boost::is_same, std::output_iterator_tag>)); - - BOOST_MPL_ASSERT((boost::mpl::bool_::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_::is_integer>)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - BOOST_MPL_ASSERT_NOT((boost::mpl::bool_::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_::is_integer>)); - BOOST_CHECK((comparison_type)(std::numeric_limits::max)() - > (comparison_type)(std::numeric_limits::max)()); - - { - X u; - BOOST_CHECK(u.size() == 0); - } -} - -template -void container_tests2(X& a) -{ - typedef typename X::iterator iterator; - typedef typename X::const_iterator const_iterator; - typedef typename X::difference_type difference_type; - typedef typename X::size_type size_type; - - { - X u(a); - // BOOST_CHECK_EQUAL(a, u); - } - - { - X u = a; - // BOOST_CHECK_EQUAL(a, u); - } - - // Test that destructor destructs all elements - - { - X const a_const = a; - - check_return_type::equals(a.begin()); - check_return_type::equals(a_const.begin()); - check_return_type::equals(a.end()); - check_return_type::equals(a_const.end()); - } - - // No tests for ==, != since they're not required for unordered containers. - - { - X b; - a.swap(b); - a.swap(b); - } - - { - X u; - X& r = u; - - check_return_type::equals_ref(r = a); - } - - { - check_return_type::equals(a.size()); - BOOST_CHECK_EQUAL(a.size(), (size_type) std::distance(a.begin(), a.end())); - } - - { - check_return_type::equals(a.max_size()); - } - - { - check_return_type::convertible(a.empty()); - BOOST_CHECK_EQUAL(a.empty(), a.size() == 0); - } - - // TODO: member function size return number of elements. - // Semantics determined by constructors/inserts/erases. - // ie. will be tested in their tests. - - // begin() returns first element. - // end() return past the end iterator. - // Can't really test this for unordered containers. - - { - if(a.empty()) - BOOST_CHECK(a.begin() == a.end()); - } - - // TODO: test that const_iterator can replace iterator in comparisons. - - // TODO: test allocators - - // No need to test reversible. - - // Exceptions: - // No copy constructor or assignment operator of a returned iterator throws an exception. - - // No swap() function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. - // Unless otherwise specified, iterators are not invalidated, and the values of objects aren't changed. -} - -BOOST_AUTO_UNIT_TEST(basic_tests) -{ - // I don't use the normal template mechanism here, as I want to specify the - // member type explicitly. - container_tests((boost::unordered_set*) 0, (int*) 0); - container_tests((boost::unordered_map*) 0, (std::pair*) 0); - container_tests((boost::unordered_multiset*) 0, (std::string*) 0); - container_tests((boost::unordered_multimap*) 0, - (std::pair*) 0); -} - -struct test_structure { int* x; }; - -META_FUNC_TEST_CASE(basic_tests_2, Container) -{ - - Container a; - container_tests2(a); - - { - test::random_values values1((std::min)(10u, a.max_size())); - Container b(values1.begin(), values1.end()); - container_tests2(b); - } - - { - test::random_values values2((std::min)(1000u, a.max_size())); - Container c(values2.begin(), values2.end()); - container_tests2(c); - } - - { - test::random_values values3((std::min)(100000u, a.max_size())); - Container d(values3.begin(), values3.end()); - container_tests2(d); - } -} - -AUTO_META_TESTS( - (basic_tests_2), - CONTAINER_SEQ -) diff --git a/test/check_return_type.hpp b/test/check_return_type.hpp deleted file mode 100644 index a201e75d..00000000 --- a/test/check_return_type.hpp +++ /dev/null @@ -1,36 +0,0 @@ - -// Copyright Daniel James 2005. 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_TESTS_CHECK_RETURN_TYPE_HEADER) -#define BOOST_UNORDERED_TESTS_CHECK_RETURN_TYPE_HEADER - -#include - -template -struct check_return_type -{ - template - static int equals(T2) - { - BOOST_MPL_ASSERT((boost::is_same)); - return 0; - } - - template - static int equals_ref(T2&) - { - BOOST_MPL_ASSERT((boost::is_same)); - return 0; - } - - template - static int convertible(T2) - { - BOOST_MPL_ASSERT((boost::is_convertible)); - return 0; - } -}; - -#endif diff --git a/test/clear_tests.cpp b/test/clear_tests.cpp deleted file mode 100644 index 558ed539..00000000 --- a/test/clear_tests.cpp +++ /dev/null @@ -1,32 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(clear_test, Container) -{ - test::constructors constructor; - test::random_values values(100); - Container x(values.begin(), values.end(), 0, - constructor.hasher(55), constructor.key_equal(55), - constructor.allocator(10)); - - x.clear(); - BOOST_CHECK(x.empty()); - test::invariant_check(x); -} - -AUTO_META_TESTS( - (clear_test), - CONTAINER_SEQ -) diff --git a/test/concept_test.cpp b/test/concept_test.cpp deleted file mode 100644 index ddd98845..00000000 --- a/test/concept_test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -#include -#include - -int main() -{ - using namespace boost; - - typedef boost::unordered_set UnorderedSet; - typedef boost::unordered_multiset UnorderedMultiSet; - typedef boost::unordered_map UnorderedMap; - typedef boost::unordered_multimap UnorderedMultiMap; - - function_requires< UnorderedAssociativeContainerConcept >(); - function_requires< SimpleAssociativeContainerConcept >(); - function_requires< UniqueAssociativeContainerConcept >(); - - function_requires< UnorderedAssociativeContainerConcept >(); - function_requires< SimpleAssociativeContainerConcept >(); - function_requires< MultipleAssociativeContainerConcept >(); - - function_requires< UnorderedAssociativeContainerConcept >(); - function_requires< UniqueAssociativeContainerConcept >(); - function_requires< PairAssociativeContainerConcept >(); - - function_requires< UnorderedAssociativeContainerConcept >(); - function_requires< MultipleAssociativeContainerConcept >(); - function_requires< PairAssociativeContainerConcept >(); - - return 0; -} diff --git a/test/const_iterator_fail_test.cpp b/test/const_iterator_fail_test.cpp deleted file mode 100644 index fcd7b82a..00000000 --- a/test/const_iterator_fail_test.cpp +++ /dev/null @@ -1,16 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include - -void func() -{ - typedef boost::unordered_map map; - typedef map::iterator iterator; - typedef map::const_iterator const_iterator; - - const_iterator x; - iterator y(x); -} diff --git a/test/const_local_iterator_fail_test.cpp b/test/const_local_iterator_fail_test.cpp deleted file mode 100644 index 348c9b5b..00000000 --- a/test/const_local_iterator_fail_test.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include - -void func() -{ - // This is only required to fail for unordered maps & multimaps as for sets - // and multisets both iterator and const_iterator are const. - typedef boost::unordered_map map; - typedef map::local_iterator local_iterator; - typedef map::const_local_iterator const_local_iterator; - - const_local_iterator x; - local_iterator y(x); -} diff --git a/test/construct_tests.cpp b/test/construct_tests.cpp deleted file mode 100644 index 2c9cfb99..00000000 --- a/test/construct_tests.cpp +++ /dev/null @@ -1,273 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/input_iterator_adaptor.hpp" -#include "./helpers/constructors.hpp" -#include "./helpers/equivalent.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(empty_construct_test1, Container) -{ - test::constructors constructor; - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 4 - Container x(100, constructor.hasher(55), constructor.key_equal(55)); - BOOST_CHECK(x.bucket_count() >= 100); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(empty_construct_test2, Container) -{ - test::constructors constructor; - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 5 - - // I can only use the default hasher here - as it'll match the default - // key_equal. - Container x(100, constructor.hasher()); - BOOST_CHECK(x.empty()); - BOOST_CHECK(x.bucket_count() >= 100); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(empty_construct_test3, Container) -{ - test::constructors constructor; - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 6 - - Container x(200); - BOOST_CHECK(x.empty()); - BOOST_CHECK(x.bucket_count() >= 200); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(empty_construct_test4, Container) -{ - test::constructors constructor; - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 7 - - Container x; - BOOST_CHECK(x.empty()); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(empty_construct_test5, Container) -{ - test::constructors constructor; - - EXCEPTION_TEST(1000) - { - // TODO: Where? - Container x(100, constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - BOOST_CHECK(x.empty()); - BOOST_CHECK(x.bucket_count() >= 100); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_construct_test1, Container) -{ - test::constructors constructor; - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 8 - - Container x(values.begin(), values.end(), 100, - constructor.hasher(55), constructor.key_equal(55)); - BOOST_CHECK(x.bucket_count() >= 100); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - // TODO: Check that values are in container. - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_construct_test2, Container) -{ - test::constructors constructor; - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 9 - - Container x(values.begin(), values.end(), 100, constructor.hasher()); - BOOST_CHECK(x.bucket_count() >= 100); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - // TODO: Check that values are in container. - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_construct_test3, Container) -{ - test::constructors constructor; - test::random_values values(20); - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 10 - - Container x(values.begin(), values.end(), 10); - BOOST_CHECK(x.bucket_count() >= 10); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - // TODO: Check that values are in container. - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_construct_test4, Container) -{ - test::constructors constructor; - test::random_values values(20); - - EXCEPTION_TEST(1000) - { - // TR1 6.3.1/9 row 11 - - Container x(values.begin(), values.end()); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher())); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal())); - // TODO: Check that values are in container. - - // TODO: Where? - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator())); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_construct_test5, Container) -{ - test::constructors constructor; - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - // TODO: Where? - Container x(values.begin(), values.end(), 10, - constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - BOOST_CHECK(x.bucket_count() >= 10); - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END -} - -// TODO: I should probably just make all the tests run from an input iterator. -META_FUNC_TEST_CASE(input_iterator_construct_test1, Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - Container x( - test::make_input_iterator(values.begin()), - test::make_input_iterator(values.end()) - ); - BOOST_CHECK_EQUAL(x.max_load_factor(), 1.0); - - test::invariant_check(x); - } - EXCEPTION_TEST_END - -} - -AUTO_META_TESTS( - (empty_construct_test1)(empty_construct_test2)(empty_construct_test3) - (empty_construct_test4)(empty_construct_test5) - (range_construct_test1)(range_construct_test2)(range_construct_test3) - (range_construct_test4)(range_construct_test5) - (input_iterator_construct_test1), - CONTAINER_SEQ -) diff --git a/test/container_tests.cpp b/test/container_tests.cpp deleted file mode 100644 index dd4fd8f1..00000000 --- a/test/container_tests.cpp +++ /dev/null @@ -1,238 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include -#include -#include -#include -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" -#include "./equivalent.hpp" -#include "./check_return_type.hpp" - -typedef double comparison_type; - -// 23.1/5 -template -void container_tests(X*, T*) -{ - typedef typename X::iterator iterator; - typedef typename X::const_iterator const_iterator; - typedef typename X::difference_type difference_type; - typedef typename X::size_type size_type; - - typedef typename iterator::value_type iterator_value_type; - typedef typename const_iterator::value_type const_iterator_value_type; - typedef typename iterator::difference_type iterator_difference_type; - typedef typename const_iterator::difference_type const_iterator_difference_type; - - typedef typename X::value_type value_type; - typedef typename X::reference reference; - typedef typename X::const_reference const_reference; - - BOOST_MPL_ASSERT((boost::is_same)); - // TODO: Actually 'lvalue of T'/'const lvalue of T' - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - // TODO: Iterator checks. - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT_NOT((boost::is_same, std::output_iterator_tag>)); - BOOST_MPL_ASSERT((boost::is_convertible)); - - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT_NOT((boost::is_same, std::output_iterator_tag>)); - - BOOST_MPL_ASSERT((boost::mpl::bool_::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_::is_integer>)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - BOOST_MPL_ASSERT_NOT((boost::mpl::bool_::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_::is_integer>)); - BOOST_CHECK((comparison_type)(std::numeric_limits::max)() - > (comparison_type)(std::numeric_limits::max)()); - - { - X u; - BOOST_CHECK(u.size() == 0); - BOOST_CHECK(X().size() == 0); - } -} - -template -void container_tests2(X& a) -{ - // 23.1/5 continued - typedef typename X::iterator iterator; - typedef typename X::const_iterator const_iterator; - typedef typename X::difference_type difference_type; - typedef typename X::size_type size_type; - typedef typename X::allocator_type allocator_type; - - test::unordered_equivalence_tester equivalent(a); - - { - X u(a); - equivalent.test(u); - } - - { - X u = a; - equivalent.test(u); - } - - // Test that destructor destructs all elements (already done by test::allocator/test::member?). - - { - X const& a_const = a; - - check_return_type::equals(a.begin()); - check_return_type::equals(a_const.begin()); - check_return_type::equals(a.end()); - check_return_type::equals(a_const.end()); - } - - // No tests for ==, != since they're not required for unordered containers. - - { - X b; - a.swap(b); - BOOST_CHECK(a.empty()); - equivalent.test(b); - a.swap(b); - equivalent.test(a); - BOOST_CHECK(b.empty()); - } - - { - X u; - X& r = u; - - check_return_type::equals_ref(r = a); - equivalent.test(r); - } - - { - check_return_type::equals(a.size()); - BOOST_CHECK_EQUAL(a.size(), (size_type) std::distance(a.begin(), a.end())); - } - - { - check_return_type::equals(a.max_size()); - // TODO: Check that a.max_size() == size of the largest possible container - // How do I do that? test::allocator checks that allocations don't exceed - // that allocator's maximum size. Could check that max_size() works, and - // that max_size() + 1 doesn't. Only practicle for small max_size though - - // and it might be possible to implement unordered containers such that - // max_size() > alloc.max_size(). Or is it? - } - - { - check_return_type::convertible(a.empty()); - BOOST_CHECK_EQUAL(a.empty(), a.size() == 0); - } - - // 23.1/7 - { - if(a.empty()) - BOOST_CHECK(a.begin() == a.end()); - } - - // 23.1/8 - { - iterator i = a.begin(), j = a.end(); - const_iterator ci = a.begin(), cj = a.end(); - - if(a.empty()) { - BOOST_CHECK(i == j); - BOOST_CHECK(i == cj); - BOOST_CHECK(ci == j); - BOOST_CHECK(ci == cj); - - BOOST_CHECK(!(i != j)); - BOOST_CHECK(!(i != cj)); - BOOST_CHECK(!(ci != j)); - BOOST_CHECK(!(ci != cj)); - } - else { - BOOST_CHECK(!(i == j)); - BOOST_CHECK(!(i == cj)); - BOOST_CHECK(!(ci == j)); - BOOST_CHECK(!(ci == cj)); - - BOOST_CHECK(i != j); - BOOST_CHECK(i != cj); - BOOST_CHECK(ci != j); - BOOST_CHECK(ci != cj); - } - } - - // TODO: 23.1/9 - Make sure this is checked for all constructors. - { - check_return_type::equals(a.get_allocator()); - } - - // TODO: 23.1/11 - Exception safety: - // No erase function throws an exception. - // No copy constructor or assignment operator of a returned iterator throws an exception. - - // No swap() function throws an exception unless that exception is thrown by the copy constructor of assignment operator of the container's Compare object. - // No swap() function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. - // - // TODO: 21.1/12 - // - // Unless otherwise specified - iterators not invalidated, values not changed. -} - -BOOST_AUTO_UNIT_TEST(basic_tests) -{ - // I don't use the normal template mechanism here, as I want to specify the - // member type explicitly. - container_tests((boost::unordered_set*) 0, (int*) 0); - container_tests((boost::unordered_map*) 0, (std::pair*) 0); - container_tests((boost::unordered_multiset*) 0, (std::string*) 0); - container_tests((boost::unordered_multimap*) 0, - (std::pair*) 0); -} - -struct test_structure { int* x; }; - -META_FUNC_TEST_CASE(basic_tests_2, Container) -{ - - Container a; - container_tests2(a); - - { - test::random_values values1((std::min)(10u, a.max_size())); - Container b(values1.begin(), values1.end()); - container_tests2(b); - } - - { - test::random_values values2((std::min)(1000u, a.max_size())); - Container c(values2.begin(), values2.end()); - container_tests2(c); - } - - { - test::random_values values3((std::min)(100000u, a.max_size())); - Container d(values3.begin(), values3.end()); - container_tests2(d); - } -} - -AUTO_META_TESTS( - (basic_tests_2), - CONTAINER_SEQ -) diff --git a/test/containers.hpp b/test/containers.hpp deleted file mode 100644 index 674fe743..00000000 --- a/test/containers.hpp +++ /dev/null @@ -1,76 +0,0 @@ - -// Copyright Daniel James 2005. 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_TESTS_CONTAINERS_HEADER) -#define BOOST_UNORDERED_TESTS_CONTAINERS_HEADER - -#include -#include -#include -#include -#include "./helpers/allocator.hpp" -#include "./helpers/functional.hpp" -#include "./helpers/member.hpp" - -typedef boost::unordered_set< - test::member - > test_set; -typedef boost::unordered_multiset< - test::member, test::hash, test::equals, - test::allocator - > test_multiset; -typedef boost::unordered_map< - test::member, test::member, test::hash, test::equals, - test::allocator > - > test_map; -typedef boost::unordered_multimap< - test::member, test::member, test::hash, test::equals, - test::minimal_allocator > - > test_multimap; - -typedef boost::unordered_set< - int, test::hash, test::equals, - test::allocator - > set_int; -typedef boost::unordered_multiset< - std::string, test::hash, test::equals, - test::allocator - > multiset_string; -typedef boost::unordered_map< - test::member, std::string, test::hash, test::equals, - test::allocator > - > map_member_string; -typedef boost::unordered_multimap< - int, test::member, test::hash, test::equals, - test::allocator > - > multimap_int_member; -typedef boost::unordered_map< - char, test::member, test::hash, test::equals, - test::allocator > - > map_char_member; -typedef boost::unordered_multiset< - char, test::hash, test::equals, - test::allocator - > multiset_char; - -typedef std::pair pair1; -typedef std::pair pair2; -typedef std::pair pair3; -BOOST_TT_BROKEN_COMPILER_SPEC(std::string) -BOOST_TT_BROKEN_COMPILER_SPEC(pair1) -BOOST_TT_BROKEN_COMPILER_SPEC(pair2) -BOOST_TT_BROKEN_COMPILER_SPEC(pair3) -BOOST_TT_BROKEN_COMPILER_SPEC(test::member) - -#ifdef REDUCED_TESTS -#define CONTAINER_SEQ \ - (test_set)(test_multiset)(test_map)(test_multimap) -#else -#define CONTAINER_SEQ \ - (set_int)(multiset_string)(map_member_string) \ - (multimap_int_member)(map_char_member)(multiset_char) -#endif - -#endif diff --git a/test/copy_construct_tests.cpp b/test/copy_construct_tests.cpp deleted file mode 100644 index 2bedd4e8..00000000 --- a/test/copy_construct_tests.cpp +++ /dev/null @@ -1,119 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./equivalent.hpp" -#include "./invariant.hpp" - -// 23.1/5 + TR1 6.3.1/9 row 12 -META_FUNC_TEST_CASE(empty_copy_test1, X) -{ - X x; - test::unordered_equivalence_tester equivalent(x); - - EXCEPTION_TEST(1000) - { - X y(x); - equivalent.test(y); - test::invariant_check(y); - } - EXCEPTION_TEST_END - - test::invariant_check(x); -} - -META_FUNC_TEST_CASE(empty_copy_test2, X) -{ - test::constructors constructor; - X x(100, constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - x.max_load_factor(4.0); - test::unordered_equivalence_tester equivalent(x); - - EXCEPTION_TEST(1000) - { - X y(x); - equivalent.test(y); - test::invariant_check(y); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(range_copy_construct,X) -{ - test::constructors constructor; - test::random_values values(10); - - X x(values.begin(), values.end(), 100, - constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - x.max_load_factor(4.0); - test::unordered_equivalence_tester equivalent(x); - - EXCEPTION_TEST(1000) - { - X y(x); - equivalent.test(y); - test::invariant_check(y); - } - EXCEPTION_TEST_END -} - -template -void check_container(X const& x, test::unordered_equivalence_tester const& equivalent) -{ - equivalent.test(x); - test::invariant_check(x); -} - -META_FUNC_TEST_CASE(anon_copy_construct, X) -{ - test::constructors constructor; - test::random_values values(10); - - X x(values.begin(), values.end(), 100, - constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - x.max_load_factor(4.0); - test::unordered_equivalence_tester equivalent(x); - - EXCEPTION_TEST(1000) - { - check_container(X(x), equivalent); - } - EXCEPTION_TEST_END -} - -template -X return_container(X const& x) -{ - return x; -} - -META_FUNC_TEST_CASE(copy_from_return,X) -{ - test::random_values values(10); - X x(values.begin(), values.end()); - test::unordered_equivalence_tester equivalent(x); - - EXCEPTION_TEST(1000) - { - X y(return_container(x)); - equivalent.test(y); - test::invariant_check(y); - } - EXCEPTION_TEST_END -} - -AUTO_META_TESTS( - (empty_copy_test1)(empty_copy_test2)(range_copy_construct) - (anon_copy_construct)(copy_from_return), - CONTAINER_SEQ -) diff --git a/test/count_tests.cpp b/test/count_tests.cpp deleted file mode 100644 index b900556c..00000000 --- a/test/count_tests.cpp +++ /dev/null @@ -1,65 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" - -META_FUNC_TEST_CASE(count_const_test, Container) -{ - test::random_values values(500); - typedef typename test::random_values::iterator iterator; - - Container const x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - BOOST_CHECK_EQUAL(x.count(values.get_key(*it)), values.key_count(*it)); - } - - typedef typename test::random_values::value_type value_type; - test::generator generator; - - for(int i = 0; i < 500; ++i) - { - value_type value = generator(); - BOOST_CHECK_EQUAL(x.count(values.get_key(value)), values.key_count(value)); - } -} - -META_FUNC_TEST_CASE(count_nonconst_test, Container) -{ - test::random_values values(500); - typedef typename test::random_values::iterator iterator; - - Container x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - BOOST_CHECK_EQUAL(x.count(values.get_key(*it)), values.key_count(*it)); - } -} - -META_FUNC_TEST_CASE(empty_test, Container) -{ - typedef test::random_values random_values; - typedef typename random_values::value_type value_type; - test::generator generator; - Container x; - - for(int i = 0; i < 500; ++i) - { - BOOST_CHECK_EQUAL(x.count(random_values::get_key(generator())), 0u); - } -} - -AUTO_META_TESTS( - (count_const_test)(count_nonconst_test)(empty_test), - CONTAINER_SEQ -) diff --git a/test/equal_range_tests.cpp b/test/equal_range_tests.cpp deleted file mode 100644 index 0f1fedbf..00000000 --- a/test/equal_range_tests.cpp +++ /dev/null @@ -1,100 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" - -template -OutputIt copy_if(InputIt begin, InputIt end, OutputIt out, Condition cond) -{ - for(;begin != end; ++begin) - { - if(cond(*begin)) { - *out = *begin; - ++out; - } - } - - return out; -} - -template -void compare(std::pair const& range, - RandomValues const& values, Value const& v) -{ - typedef typename RandomValues::value_type value_type; - typedef std::vector value_container; - value_container range_values(range.first, range.second); - value_container orig_values; - copy_if(values.begin(), values.end(), std::back_inserter(orig_values), - values.key_match(v)); - - if(values.is_unique()) { - if(orig_values.empty()) { - BOOST_CHECK_EQUAL(range_values.size(), 0u); - } - else { - BOOST_CHECK_EQUAL(range_values.size(), 1u); - BOOST_CHECK(orig_values.front() == *range_values.begin()); - } - } - else { - std::sort(range_values.begin(), range_values.end()); - std::sort(orig_values.begin(), orig_values.end()); - BOOST_CHECK_EQUAL(range_values.size(), orig_values.size()); - if(range_values.size() == orig_values.size()) - BOOST_CHECK(std::equal(range_values.begin(), range_values.end(), - orig_values.begin())); - } -} - -META_FUNC_TEST_CASE(const_test, Container) -{ - test::random_values values(500); - typedef test::random_values random_values; - typedef typename random_values::iterator iterator; - - Container const x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - compare(x.equal_range(values.get_key(*it)), - values, values.get_key(*it)); - } - - typedef typename random_values::value_type value_type; - test::generator generator; - - for(int i = 0; i < 500; ++i) - { - value_type v = generator(); - compare(x.equal_range(values.get_key(v)), - values, values.get_key(v)); - } -} - -META_FUNC_TEST_CASE(nonconst_test, Container) -{ - test::random_values values(500); - typedef typename test::random_values::iterator iterator; - - Container const x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - compare(x.equal_range(values.get_key(*it)), - values, values.get_key(*it)); - } -} - -AUTO_META_TESTS( - (const_test)(nonconst_test), - CONTAINER_SEQ -) diff --git a/test/equivalent.hpp b/test/equivalent.hpp deleted file mode 100644 index ce8808a3..00000000 --- a/test/equivalent.hpp +++ /dev/null @@ -1,112 +0,0 @@ - -// Copyright Daniel James 2005. 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_TESTS_EQUIVALENT_HEADER) -#define BOOST_UNORDERED_TESTS_EQUIVALENT_HEADER - -#include "./helpers/strong.hpp" -#include "./helpers/equivalent.hpp" -#include "./helpers/metafunctions.hpp" -#include "./helpers/less.hpp" -#include -#include -#include -#include - -namespace test -{ - struct equals2_t - { - template - bool operator()(X const& x, Y const& y) - { - return x == y; - } - - template - bool operator()(std::pair const& x, std::pair const& y) - { - return x.first == y.first && x.second == y.second; - } - } equals2; - - template - class unordered_equivalence_tester - { - typename Container::size_type size_; - typename Container::hasher hasher_; - typename Container::key_equal key_equal_; - float max_load_factor_; - std::vector::type> values_; - public: - unordered_equivalence_tester(Container const &x) - : size_(x.size()), - hasher_(x.hash_function()), key_equal_(x.key_eq()), - max_load_factor_(x.max_load_factor()), - values_(x.begin(), x.end()) - { - std::sort(values_.begin(), values_.end(), - test::compare()); - } - - void test(Container const& x) const - { - BOOST_CHECK(size_ == x.size()); - BOOST_CHECK(test::equivalent(hasher_, x.hash_function())); - BOOST_CHECK(test::equivalent(key_equal_, x.key_eq())); - BOOST_CHECK(max_load_factor_ == x.max_load_factor()); - BOOST_CHECK(values_.size() == x.size()); - if(values_.size() == x.size()) { - std::vector::type> - copy(x.begin(), x.end()); - std::sort(copy.begin(), copy.end(), test::compare()); - BOOST_CHECK( - std::equal(values_.begin(), values_.end(), copy.begin(), - equals2)); - } - } - private: - unordered_equivalence_tester(); - }; -} - -#if 0 -namespace boost -{ - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_set const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_set >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_multiset const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_multiset >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_map const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_map >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_multimap const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_multimap >(x)); - } -} -#endif - -#endif diff --git a/test/erase_tests.cpp b/test/erase_tests.cpp deleted file mode 100644 index 306ef5e9..00000000 --- a/test/erase_tests.cpp +++ /dev/null @@ -1,190 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(range_erase_test,Container) -{ - test::constructors constructor; - - test::random_values values(100); - typedef typename Container::iterator iterator; - - { - Container x(values.begin(), values.end(), 0, - constructor.hasher(55), - constructor.key_equal(55), - constructor.allocator(10)); - const std::size_t size = x.size(); - INVARIANT_CHECK(x); - iterator pos; - - // Should be no throw. - ACTIVATE_EXCEPTIONS; - - BOOST_CHECKPOINT("Erase nothing from the beginning"); - BOOST_CHECK(x.begin() == x.erase(x.begin(), x.begin())); - BOOST_CHECK_EQUAL(x.size(), size); - test::check_invariants(); - - BOOST_CHECKPOINT("Erase nothing from the end"); - BOOST_CHECK(x.end() == x.erase(x.end(), x.end())); - BOOST_CHECK_EQUAL(x.size(), size); - test::check_invariants(); - - BOOST_CHECKPOINT("Erase nothing from the middle"); - BOOST_CHECK(boost::next(x.begin(), 4) == x.erase( - boost::next(x.begin(), 4), - boost::next(x.begin(), 4))); - BOOST_CHECK_EQUAL(x.size(), size); - test::check_invariants(); - - BOOST_CHECKPOINT("Erase 3 from the middle"); - pos = x.erase(boost::next(x.begin(), 1), boost::next(x.begin(), 4)); - BOOST_CHECK(boost::next(x.begin(), 1) == pos); - BOOST_CHECK_EQUAL(x.size(), size - 3); - test::check_invariants(); - - BOOST_CHECKPOINT("Erase all but the first 1"); - pos = x.erase(boost::next(x.begin(), 1), x.end()); - BOOST_CHECK(x.end() == pos); - BOOST_CHECK_EQUAL(x.size(), 1u); - test::check_invariants(); - } - - { - Container x(values.begin(), values.end()); - const std::size_t size = x.size(); - INVARIANT_CHECK(x); - iterator pos; - - // Should be no throw. - ACTIVATE_EXCEPTIONS; - - BOOST_CHECKPOINT("Erase first 2"); - pos = x.erase(x.begin(), boost::next(x.begin(), 2)); - BOOST_CHECK(x.begin() == pos); - BOOST_CHECK_EQUAL(x.size(), size - 2); - test::check_invariants(); - } - - { - Container x(values.begin(), values.end()); - INVARIANT_CHECK(x); - iterator pos; - - // Should be no throw. - ACTIVATE_EXCEPTIONS; - - BOOST_CHECKPOINT("Erase all"); - pos = x.erase(x.begin(), x.end()); - BOOST_CHECK(x.begin() == pos && x.end() == pos); - BOOST_CHECK(x.empty()); - test::check_invariants(); - } -} - -META_FUNC_TEST_CASE(erase_by_key_test,Container) -{ - test::constructors constructor; - test::sorted_random_values values(10); - - // Exceptions only from the hash function. - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x(values.begin(), values.end(), 0, - constructor.hasher(55), - constructor.key_equal(55), - constructor.allocator(10)); - INVARIANT_CHECK(x); - - for(int i = 0; i < 10; i += values.count(values[i])) { - std::size_t key_count = values.key_count(values[i]); - { - ACTIVATE_EXCEPTIONS; - BOOST_CHECK_EQUAL(key_count, - x.erase(values.get_key(values[i]))); - } - BOOST_CHECK(x.find(values.get_key(values[i])) == x.end()); - BOOST_CHECK_EQUAL(0u, x.erase(values.get_key(values[i]))); - } - - BOOST_CHECK(x.empty()); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(erase_subrange_test,Container) -{ - test::random_values values(100); - Container x(values.begin(), values.end()); - - // Should be no throw. - ACTIVATE_EXCEPTIONS; - - typedef typename Container::const_iterator const_iterator; - typedef typename Container::iterator iterator; - - std::size_t length = x.size(); - std::size_t begin_index = length / 2; - std::size_t end_index = (length + begin_index) / 2; - std::size_t sub_begin_index = (end_index - begin_index) / 4; - std::size_t sub_end_index = sub_begin_index * 3; - - const_iterator begin = boost::next(x.begin(), begin_index); - const_iterator end = boost::next(x.begin(), end_index); - - iterator pos = x.erase(boost::next(begin, sub_begin_index), - boost::next(begin, sub_end_index)); - - BOOST_CHECK(pos == boost::next(x.begin(), begin_index + sub_begin_index)); - BOOST_CHECK(pos == boost::next(begin, sub_begin_index)); - BOOST_CHECK_EQUAL( - (end_index - begin_index) - (sub_end_index - sub_begin_index), - static_cast(std::distance(begin, end))); - - test::invariant_check(x); -} - -META_FUNC_TEST_CASE(erase_by_iterator_test,Container) -{ - test::random_values values(100); - Container x(values.begin(), values.end()); - INVARIANT_CHECK(x); - std::size_t size = x.size(); - - typedef typename Container::iterator iterator; - - // Should be no throw. - ACTIVATE_EXCEPTIONS; - - while(!x.empty()) { - using namespace std; - int index = rand() % x.size(); - iterator pos = x.erase(boost::next(x.begin(), index)); - --size; - BOOST_CHECK_EQUAL(size, x.size()); - - BOOST_CHECK(boost::next(x.begin(), index) == pos); - test::check_invariants(); - } -} - -AUTO_META_TESTS( - (range_erase_test)(erase_by_key_test)(erase_subrange_test) - (erase_by_iterator_test), - CONTAINER_SEQ -) diff --git a/test/find_tests.cpp b/test/find_tests.cpp deleted file mode 100644 index cab61bd9..00000000 --- a/test/find_tests.cpp +++ /dev/null @@ -1,78 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include "./helpers/unit_test.hpp" -#include "./helpers/random_values.hpp" - -META_FUNC_TEST_CASE(find_const_test,Container) -{ - test::random_values values(500); - typedef typename test::random_values::iterator iterator; - - Container const x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - typename Container::const_iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end()); - BOOST_CHECK(values.get_key(*pos) == values.get_key(*it)); - } -} - -META_FUNC_TEST_CASE(find_nonconst_test,Container) -{ - test::random_values values(500); - typedef typename test::random_values::iterator iterator; - - Container x(values.begin(), values.end()); - - for(iterator it = values.begin(); it != values.end(); ++it) - { - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end()); - BOOST_CHECK(values.get_key(*pos) == values.get_key(*it)); - } -} - -META_FUNC_TEST_CASE(missing_test,Container) -{ - test::random_values values(10); - Container x(values.begin(), values.end()); - - typedef typename test::random_values::value_type value_type; - test::generator generator; - - for(int i = 0; i < 500; ++i) - { - value_type const value = generator(); - bool const present_in_values = values.find(value) != values.end(); - bool const present_in_container = x.find(values.get_key(value)) - != x.end(); - BOOST_CHECK(present_in_values == present_in_container); - } -} - -META_FUNC_TEST_CASE(empty_test,Container) -{ - typedef test::random_values random_values; - typedef typename random_values::value_type value_type; - test::generator generator; - Container x; - - for(int i = 0; i < 500; ++i) - { - BOOST_CHECK(x.find(random_values::get_key(generator())) == x.end()); - } -} - -AUTO_META_TESTS( - (find_const_test)(find_nonconst_test)(missing_test)(empty_test), - CONTAINER_SEQ -) diff --git a/test/insert_tests.cpp b/test/insert_tests.cpp deleted file mode 100644 index 8166349e..00000000 --- a/test/insert_tests.cpp +++ /dev/null @@ -1,193 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/input_iterator_adaptor.hpp" -#include "./strong.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(insert_individual,Container) -{ - test::random_values values(100); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - - INVARIANT_CHECK(x); - - ACTIVATE_EXCEPTIONS; - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - STRONG_TEST(tester, x) { - try { - x.insert(*it); - } catch(test::hash_exception) { - tester.dismiss(); - throw; - } - } - - DEACTIVATE_EXCEPTIONS; - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it))); - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_with_previous_item_hint,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - - Container x; - INVARIANT_CHECK(x); - - ACTIVATE_EXCEPTIONS; - - typename Container::const_iterator prev = x.begin(); - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - x.insert(prev, *it); - - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it))); - prev = pos; - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_with_begin_hint,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - INVARIANT_CHECK(x); - ACTIVATE_EXCEPTIONS; - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - x.insert(x.begin(), *it); - - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it))); - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_with_end_hint,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - INVARIANT_CHECK(x); - ACTIVATE_EXCEPTIONS; - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - x.insert(x.end(), *it); - - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it))); - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_with_random_hint,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - INVARIANT_CHECK(x); - ACTIVATE_EXCEPTIONS; - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - using namespace std; - x.insert(boost::next(x.begin(), rand() % (x.size() + 1)), *it); - - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it))); - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_range,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - INVARIANT_CHECK(x); - ACTIVATE_EXCEPTIONS; - - x.insert(values.begin(), values.end()); - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(insert_range_input_iterator,Container) -{ - test::random_values values(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - INVARIANT_CHECK(x); - ACTIVATE_EXCEPTIONS; - - x.insert(test::make_input_iterator(values.begin()), - test::make_input_iterator(values.end())); - } - EXCEPTION_TEST_END -} - -AUTO_META_TESTS( - (insert_individual)(insert_with_previous_item_hint)(insert_with_begin_hint) - (insert_with_end_hint)(insert_with_random_hint)(insert_range) - (insert_range_input_iterator), - CONTAINER_SEQ -) diff --git a/test/invariant.hpp b/test/invariant.hpp deleted file mode 100644 index a91714cb..00000000 --- a/test/invariant.hpp +++ /dev/null @@ -1,128 +0,0 @@ - -// Copyright Daniel James 2005. 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_CONTAINER_INVARIANT_HEADER) -#define BOOST_UNORDERED_TEST_CONTAINER_INVARIANT_HEADER - -#include -#include -#include -#include "./helpers/invariant_checker.hpp" -#include "./helpers/functional.hpp" - -namespace test -{ - template - bool check_matches(Key const&, Pred const&) - { - return true; - } - - bool check_matches(hash const& h, equals const& p) - { - // TODO: This isn't actually true - change functional so that it is. - BOOST_CHECK_EQUAL(h.offset, p.tag); - return true; - } - - template - void invariant_check_container(Container const& x) - { - // Check that the begin and end iterators match the container size. - // (And also that you can iterate through all the elements). - BOOST_CHECK_EQUAL((std::size_t) std::distance(x.begin(), x.end()), - x.size()); - - BOOST_CHECK(check_matches(x.hash_function(), x.key_eq())); - - // It is possible for this to legally fail, eg. if you - // set max_load_factor to lower than the current load factor and - // don't give the table a chance to rehash. - BOOST_WARN(x.load_factor() <= x.max_load_factor()); - } - - template - void invariant_check_set(Container const& x) - { - invariant_check_container(x); - - // Check that the elements are in the correct buckets. - std::size_t count = 0; - std::size_t bucket_count = x.bucket_count(); - for(std::size_t i = 0; i < bucket_count; ++i) { - std::size_t bucket_size = 0; - for(typename Container::const_local_iterator j = x.begin(i); - j != x.end(i); ++j) - { - ++bucket_size; - BOOST_CHECK_EQUAL(i, x.bucket(*j)); - BOOST_CHECK_EQUAL(i, - x.hash_function()(*j) % bucket_count); - } - BOOST_CHECK_EQUAL(bucket_size, x.bucket_size(i)); - - count += bucket_size; - } - - // Check that the size matches what we've just seen. - BOOST_CHECK_EQUAL(count, x.size()); - } - - template - void invariant_check_map(Container const& x) - { - invariant_check_container(x); - - // Check that the elements are in the correct buckets. - std::size_t count = 0; - std::size_t bucket_count = x.bucket_count(); - for(std::size_t i = 0; i < bucket_count; ++i) { - std::size_t bucket_size = 0; - for(typename Container::const_local_iterator j = x.begin(i); - j != x.end(i); ++j) - { - ++bucket_size; - BOOST_CHECK_EQUAL(i, x.bucket(j->first)); - BOOST_CHECK_EQUAL(i, - x.hash_function()(j->first) % bucket_count); - } - BOOST_CHECK_EQUAL(bucket_size, x.bucket_size(i)); - - count += bucket_size; - } - - // Check that the size matches what we've just seen. - BOOST_CHECK_EQUAL(count, x.size()); - } -} - -namespace boost -{ - template - void invariant_impl(boost::unordered_set const& x) - { - test::invariant_check_set(x); - } - - template - void invariant_impl(boost::unordered_multiset const& x) - { - test::invariant_check_set(x); - } - - template - void invariant_impl(boost::unordered_map const& x) - { - test::invariant_check_map(x); - } - - template - void invariant_impl(boost::unordered_multimap const& x) - { - test::invariant_check_map(x); - } -} - -#endif diff --git a/test/iterator_tests.cpp b/test/iterator_tests.cpp deleted file mode 100644 index 19a12277..00000000 --- a/test/iterator_tests.cpp +++ /dev/null @@ -1,141 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include -#include - -#define BOOST_AUTO_TEST_MAIN -#include - -// TODO: Add these headers to new_iterator_tests.hpp -#include -#include -#include - -#include -#include -#include -#include "./helpers/unit_test.hpp" - -BOOST_AUTO_UNIT_TEST(iterator_tests) -{ - boost::unordered_set > set; - boost::unordered_multiset multiset; - boost::unordered_map map; - boost::unordered_multimap > multimap; - - set.insert(std::pair("Anthony","Cleopatra")); - set.insert(std::pair("Victoria","Albert")); - set.insert(std::pair("Pete","Dud")); - set.insert(std::pair("Blair","Brown")); - set.insert(std::pair("John","Yoko")); - set.insert(std::pair("Charles","Diana")); - set.insert(std::pair("Marx","Engels")); - set.insert(std::pair("Sid","Nancy")); - set.insert(std::pair("Lucy","Ricky")); - set.insert(std::pair("George","Mildred")); - set.insert(std::pair("Fanny","Alexander")); - set.insert(std::pair("Den","Angie")); - set.insert(std::pair("Sonny","Cher")); - set.insert(std::pair("Bonnie","Clyde")); - set.insert(std::pair("Punch","Judy")); - set.insert(std::pair("Powell","Pressburger")); - set.insert(std::pair("Jekyll","Hyde")); - - multiset.insert(0.434321); - multiset.insert(443421); - multiset.insert(0.434321); - - map[98] = 3; - map[99] = 4; - map[2000] = 788421; - map[2001] = 2; - - static char* strings1 = "Banjo\0Banjo\0Ukulele"; - - static char* strings[] = { - strings1, - strings1 + 6, - strings1 + 12 - }; - - BOOST_CHECK(std::string(strings[0]) == std::string(strings[1])); - BOOST_CHECK(strings[0] != strings[1]); - - multimap.insert(std::make_pair(strings[0], std::make_pair(5,6))); - multimap.insert(std::make_pair(strings[1], std::make_pair(85,32))); - multimap.insert(std::make_pair(strings[1], std::make_pair(91,142))); - multimap.insert(std::make_pair(strings[2], std::make_pair(12,3))); - multimap.insert(std::make_pair(strings[2], std::make_pair(10,94))); - multimap.insert(std::make_pair(strings[2], std::make_pair(345,42))); - - BOOST_CHECK_EQUAL(multimap.count(strings[0]), 1); - BOOST_CHECK_EQUAL(multimap.count(strings[1]), 2); - BOOST_CHECK_EQUAL(multimap.count(strings[2]), 3); - - boost::forward_readable_iterator_test(set.begin(), set.end(), - *set.begin(), *boost::next(set.begin())); - boost::forward_readable_iterator_test(multiset.begin(), multiset.end(), - *multiset.begin(), *boost::next(multiset.begin())); - boost::forward_readable_iterator_test(map.begin(), map.end(), - *map.begin(), *boost::next(map.begin())); - boost::forward_readable_iterator_test(multimap.begin(), multimap.end(), - *multimap.begin(), *boost::next(multimap.begin())); -} - -BOOST_AUTO_UNIT_TEST(rubbish_iterator_test) -{ - typedef boost::unordered_map map; - typedef map::local_iterator local_iterator; - typedef map::const_local_iterator const_local_iterator; - typedef map::iterator iterator; - typedef map::const_iterator const_iterator; - - map m; - iterator it; - const_iterator const_it(it); - local_iterator local; - const_local_iterator const_local(local); - - m[10] = 3; - m[25] = 5; - m[2] = 21; - - it = m.begin(); - const_it = m.begin(); - map::size_type index = m.bucket(10); - local = m.begin(index); - const_local = m.begin(index); - - BOOST_CHECK(it == const_it); - BOOST_CHECK(const_it == it); - BOOST_CHECK(local == const_local); - BOOST_CHECK(const_local == local); - - BOOST_CHECK(it++ == const_it); - BOOST_CHECK(local++ == const_local); - - BOOST_CHECK(it != const_it); - BOOST_CHECK(const_it != it); - BOOST_CHECK(local != const_local); - BOOST_CHECK(const_local != local); - - BOOST_CHECK(++const_it == it); - BOOST_CHECK(++const_local == local); - - it = m.begin(); - int values[3]; - std::pair const& r1= *it++; - values[0] = r1.second; - values[1] = it++->second; - values[2] = it++->second; - BOOST_CHECK(it == m.end()); - - std::sort(values, values+3); - - BOOST_CHECK_EQUAL(values[0], 3); - BOOST_CHECK_EQUAL(values[1], 5); - BOOST_CHECK_EQUAL(values[2], 21); -} diff --git a/test/map_operator_tests.cpp b/test/map_operator_tests.cpp deleted file mode 100644 index 238d2860..00000000 --- a/test/map_operator_tests.cpp +++ /dev/null @@ -1,69 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/input_iterator_adaptor.hpp" -#include "./strong.hpp" -#include "./invariant.hpp" - -// TODO: This is just the first insert test slightly modified, should do better. - -META_FUNC_TEST_CASE(insert_individual,Container) -{ - test::random_values values(100); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - Container x; - - INVARIANT_CHECK(x); - - ACTIVATE_EXCEPTIONS; - - for(typename test::random_values::iterator - it = values.begin(); it != values.end(); ++it) - { - typename Container::value_type::second_type* ref; - - // Looking at TR1 I can't find this requirement anywhere, but it - // would seem silly not to require it so I think it's either an - // omission or I haven't looked hard enough. - STRONG_TEST(tester, x) { - try { - ref = &x[it->first]; - } catch(test::hash_exception) { - tester.dismiss(); - throw; - } - } - - DEACTIVATE_EXCEPTIONS; - *ref = it->second; - - typename Container::iterator pos = x.find(values.get_key(*it)); - BOOST_CHECK(pos != x.end() && - x.key_eq()(values.get_key(*pos), values.get_key(*it)) && - test::equivalent(*it, *pos)); - } - } - EXCEPTION_TEST_END -} - -typedef boost::unordered_map map1; -typedef boost::unordered_map > map2; - -AUTO_META_TESTS( - (insert_individual), - (map1)(map2) -) diff --git a/test/max_load_factor_test.cpp b/test/max_load_factor_test.cpp deleted file mode 100644 index c4a0570b..00000000 --- a/test/max_load_factor_test.cpp +++ /dev/null @@ -1,170 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include -#include - -#define BOOST_AUTO_TEST_MAIN -#include -#include - -#include - -// If the bucket count is higher than the upper bounds in this file, it's not a -// bug (but it's not that great either). There are also some tests on when the -// number of buckets is increased on an insert, these tests are checking that -// some implementation details are working - if the implementation is changed -// they can be removed. -// -// TODO: the argument to max_load_factor is just a hint, so test against the -// container's actual max_load_factor. - -BOOST_AUTO_UNIT_TEST(test_rehash) -{ - boost::counting_iterator begin(0); - boost::counting_iterator end(1000); - - boost::unordered_set x1(begin, end); - BOOST_CHECK(x1.bucket_count() >= 1000); - BOOST_WARN(x1.bucket_count() < 2000); - - x1.max_load_factor(0.5); - x1.rehash(0); - BOOST_CHECK(x1.bucket_count() >= 2000); - BOOST_WARN(x1.bucket_count() < 4000); - x1.rehash(0); - BOOST_CHECK(x1.bucket_count() >= 2000); - BOOST_WARN(x1.bucket_count() < 4000); - - x1.max_load_factor(2.0); - x1.rehash(0); - BOOST_CHECK(x1.bucket_count() >= 500); - BOOST_WARN(x1.bucket_count() < 1000); - x1.rehash(1500); - BOOST_CHECK(x1.bucket_count() >= 1500); - BOOST_WARN(x1.bucket_count() < 3000); - - x1.max_load_factor(0.5); - x1.rehash(0); - BOOST_CHECK(x1.bucket_count() >= 2000); - BOOST_WARN(x1.bucket_count() < 4000); -} - -BOOST_AUTO_UNIT_TEST(test_insert_range) -{ - boost::counting_iterator begin(0); - boost::counting_iterator end(1000); - - boost::unordered_set x1(begin, end); - BOOST_CHECK(x1.bucket_count() >= 1000); - BOOST_WARN(x1.bucket_count() < 2000); - - x1.clear(); - x1.max_load_factor(0.5); - x1.rehash(0); - x1.insert(begin, end); - BOOST_CHECK(x1.bucket_count() >= 2000); - BOOST_WARN(x1.bucket_count() < 4000); - - x1.clear(); - x1.max_load_factor(2.0); - x1.rehash(0); - x1.insert(begin, end); - BOOST_CHECK(x1.bucket_count() >= 500); - BOOST_WARN(x1.bucket_count() < 1000); -} - -BOOST_AUTO_UNIT_TEST(test_insert) -{ - boost::unordered_map x1; - - size_t i; - for(i = 0; i < 1000; ++i) - { - size_t old_bucket_count = x1.bucket_count(); - x1[i] = i; - BOOST_CHECK(i <= x1.bucket_count()); - BOOST_CHECK(x1.bucket_count() == old_bucket_count || - x1.size() >= old_bucket_count); - - // This isn't really required: - BOOST_WARN(x1.size() < x1.bucket_count()); - } - - x1.clear(); - x1.max_load_factor(2.0); - x1.rehash(0); - - for(i = 0; i < 1000; ++i) - { - size_t old_bucket_count = x1.bucket_count(); - x1[i] = i; - BOOST_CHECK(i <= x1.bucket_count() * 2); - BOOST_CHECK(x1.bucket_count() == old_bucket_count || - x1.size() >= old_bucket_count * 2); - - // This isn't really required: - BOOST_WARN(x1.size() < x1.bucket_count() * 2); - } - - x1.clear(); - x1.rehash(0); - x1.max_load_factor(0.5); - - for(i = 0; i < 1000; ++i) - { - size_t old_bucket_count = x1.bucket_count(); - x1[i] = i; - BOOST_CHECK(i * 2 <= x1.bucket_count()); - BOOST_CHECK(x1.bucket_count() == old_bucket_count || - x1.size() * 2 >= old_bucket_count); - - // This isn't really required: - BOOST_WARN(x1.size() * 2 < x1.bucket_count()); - } -} - -BOOST_AUTO_UNIT_TEST(test_large_mlf) -{ - boost::unordered_set x1; - x1.max_load_factor(static_cast( - (std::numeric_limits::size_type>::max)() - ) * 10); - - boost::unordered_map::size_type bucket_count = x1.bucket_count(); - - for(int i = 0; i < 1000; ++i) - { - x1.insert(i); - BOOST_CHECK(x1.bucket_count() == bucket_count); - } - - boost::counting_iterator begin(1000); - boost::counting_iterator end(2000); - x1.insert(begin, end); - BOOST_CHECK(x1.bucket_count() == bucket_count); -} - -BOOST_AUTO_UNIT_TEST(test_infinite_mlf) -{ - if(std::numeric_limits::has_infinity) - { - boost::unordered_set x1; - x1.max_load_factor(std::numeric_limits::infinity()); - - boost::unordered_map::size_type bucket_count = x1.bucket_count(); - - for(int i = 0; i < 1000; ++i) - { - x1.insert(i); - BOOST_CHECK(x1.bucket_count() == bucket_count); - } - - boost::counting_iterator begin(1000); - boost::counting_iterator end(2000); - x1.insert(begin, end); - BOOST_CHECK(x1.bucket_count() == bucket_count); - } -} diff --git a/test/next_prime_tests.cpp b/test/next_prime_tests.cpp deleted file mode 100644 index b3a81f81..00000000 --- a/test/next_prime_tests.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include - -#define BOOST_AUTO_TEST_MAIN -#include - -BOOST_AUTO_UNIT_TEST(next_prime_test) -{ - BOOST_CHECK_EQUAL(53ul, boost::unordered_detail::next_prime(0)); - BOOST_CHECK_EQUAL(53ul, boost::unordered_detail::next_prime(52)); - BOOST_CHECK_EQUAL(53ul, boost::unordered_detail::next_prime(53)); - BOOST_CHECK_EQUAL(97ul, boost::unordered_detail::next_prime(54)); - BOOST_CHECK_EQUAL(98317ul, boost::unordered_detail::next_prime(50000ul)); -} diff --git a/test/set_assign_fail_test.cpp b/test/set_assign_fail_test.cpp deleted file mode 100644 index ccf4e93d..00000000 --- a/test/set_assign_fail_test.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include - -void func() -{ - boost::unordered_set x; - x.insert(10); - boost::unordered_set::iterator it = x.begin(); - *x = 25; -} diff --git a/test/strong.hpp b/test/strong.hpp deleted file mode 100644 index 86218568..00000000 --- a/test/strong.hpp +++ /dev/null @@ -1,102 +0,0 @@ - -// Copyright Daniel James 2005. 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_TESTS_STRONG_HEADER) -#define BOOST_UNORDERED_TESTS_STRONG_HEADER - -#include "./helpers/strong.hpp" -#include "./helpers/equivalent.hpp" -#include "./helpers/metafunctions.hpp" -#include -#include -#include -#include - -namespace test -{ - struct equals_t - { - template - bool operator()(X const& x, Y const& y) - { - return x == y; - } - - template - bool operator()(std::pair const& x, std::pair const& y) - { - return x.first == y.first && x.second == y.second; - } - } equals1; - - template - class unordered_strong_tester - : public strong_tester - { - Container const& reference_; - - typename Container::size_type size_; - typename Container::hasher hasher_; - typename Container::key_equal key_equal_; - - std::deque::type> values_; - public: - unordered_strong_tester(Container const &x) - : reference_(x), size_(x.size()), - hasher_(x.hash_function()), key_equal_(x.key_eq()), - values_(x.begin(), x.end()) - { - } - - void test() - { - BOOST_CHECK(size_ == reference_.size()); - BOOST_CHECK(test::equivalent(hasher_, reference_.hash_function())); - BOOST_CHECK(test::equivalent(key_equal_, reference_.key_eq())); - BOOST_CHECK(values_.size() == reference_.size()); - BOOST_CHECK(values_.size() == reference_.size() && - std::equal(values_.begin(), values_.end(), reference_.begin(), equals1)); - } - private: - unordered_strong_tester(); - }; -} - -namespace boost -{ - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_set const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_set >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_multiset const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_multiset >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_map const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_map >(x)); - } - - template - test::strong_tester_ptr create_tester_impl( - boost::unordered_multimap const& x, int) - { - return test::strong_tester_ptr(new test::unordered_strong_tester< - boost::unordered_multimap >(x)); - } -} - -#endif diff --git a/test/swap_tests.hpp b/test/swap_tests.hpp deleted file mode 100644 index 1c4bbbf3..00000000 --- a/test/swap_tests.hpp +++ /dev/null @@ -1,120 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./helpers/equivalent.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(swap_test1, Container) -{ - test::constructors constructor; - - test::random_values values_x(10); - test::random_values values_y(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - - Container x(values_x.begin(), values_x.end(), 0, - constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - x.max_load_factor(0.5); - Container y(values_y.begin(), values_y.end(), 0, - constructor.hasher(23), constructor.key_equal(23), constructor.allocator(12)); - y.max_load_factor(2.0); - - INVARIANT_CHECK(x); - INVARIANT_CHECK(y); - - ACTIVATE_EXCEPTIONS; - - if(BOOST_UNORDERED_SWAP_METHOD == 1 - && !test::equivalent(x.get_allocator(), y.get_allocator())) { - BOOST_CHECK_THROW(x.swap(y), std::runtime_error); - } - else { -#if BOOST_UNORDERED_SWAP_METHOD == 2 - // Swap Method 2 can't meet TR1's exception specifications. Sigh. - x.swap(y); -#else - try { - x.swap(y); - } - catch (test::hash_copy_exception&) { - throw; - } - catch (test::pred_copy_exception&) { - throw; - } - catch (...) { - BOOST_ERROR("Only the copy constructor/assigned of the hash " - "and predicate objects are allowed to throw in swap."); - throw; - } -#endif - - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(23))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(23))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 2.0); -#if BOOST_UNORDERED_SWAP_METHOD == 2 - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); -#else - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(12))); -#endif - - BOOST_CHECK(test::equivalent(y.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(y.key_eq(), constructor.key_equal(55))); - BOOST_CHECK_EQUAL(y.max_load_factor(), 0.5); -#if BOOST_UNORDERED_SWAP_METHOD == 2 - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator(12))); -#else - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator(10))); -#endif - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(self_swap, Container) -{ - test::constructors constructor; - test::random_values values_x(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - - Container x(values_x.begin(), values_x.end(), 0, - constructor.hasher(55), constructor.key_equal(55), - constructor.allocator(10)); - x.max_load_factor(0.5); - - INVARIANT_CHECK(x); - - ACTIVATE_EXCEPTIONS; - - x.swap(x); - - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 0.5); - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); - } - EXCEPTION_TEST_END -} - -AUTO_META_TESTS( - (swap_test1)(self_swap), - CONTAINER_SEQ -) diff --git a/test/swap_tests.ipp b/test/swap_tests.ipp deleted file mode 100644 index 67623d99..00000000 --- a/test/swap_tests.ipp +++ /dev/null @@ -1,102 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include "./containers.hpp" - -#define BOOST_AUTO_TEST_MAIN -#include - -#include -#include "./helpers/unit_test.hpp" -#include "./helpers/exception_test.hpp" -#include "./helpers/random_values.hpp" -#include "./helpers/constructors.hpp" -#include "./helpers/equivalent.hpp" -#include "./invariant.hpp" - -META_FUNC_TEST_CASE(swap_test1, Container) -{ - test::constructors constructor; - - test::random_values values_x(10); - test::random_values values_y(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - - Container x(values_x.begin(), values_x.end(), 0, - constructor.hasher(55), constructor.key_equal(55), constructor.allocator(10)); - x.max_load_factor(0.5); - Container y(values_y.begin(), values_y.end(), 0, - constructor.hasher(23), constructor.key_equal(23), constructor.allocator(12)); - y.max_load_factor(2.0); - - INVARIANT_CHECK(x); - INVARIANT_CHECK(y); - - ACTIVATE_EXCEPTIONS; - - if(BOOST_UNORDERED_SWAP_METHOD == 1 - && !test::equivalent(x.get_allocator(), y.get_allocator())) { - BOOST_CHECK_THROW(x.swap(y), std::runtime_error); - } - else { - x.swap(y); - - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(23))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(23))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 2.0); -#if BOOST_UNORDERED_SWAP_METHOD == 2 - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); -#else - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(12))); -#endif - - BOOST_CHECK(test::equivalent(y.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(y.key_eq(), constructor.key_equal(55))); - BOOST_CHECK_EQUAL(y.max_load_factor(), 0.5); -#if BOOST_UNORDERED_SWAP_METHOD == 2 - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator(12))); -#else - BOOST_CHECK(test::equivalent(y.get_allocator(), constructor.allocator(10))); -#endif - } - } - EXCEPTION_TEST_END -} - -META_FUNC_TEST_CASE(self_swap, Container) -{ - test::constructors constructor; - test::random_values values_x(10); - - EXCEPTION_TEST(1000) - { - DEACTIVATE_EXCEPTIONS; - - Container x(values_x.begin(), values_x.end(), 0, - constructor.hasher(55), constructor.key_equal(55), - constructor.allocator(10)); - x.max_load_factor(0.5); - - INVARIANT_CHECK(x); - - ACTIVATE_EXCEPTIONS; - - x.swap(x); - - BOOST_CHECK(test::equivalent(x.hash_function(), constructor.hasher(55))); - BOOST_CHECK(test::equivalent(x.key_eq(), constructor.key_equal(55))); - BOOST_CHECK_EQUAL(x.max_load_factor(), 0.5); - BOOST_CHECK(test::equivalent(x.get_allocator(), constructor.allocator(10))); - } - EXCEPTION_TEST_END -} - -AUTO_META_TESTS( - (swap_test1)(self_swap), - CONTAINER_SEQ -) diff --git a/test/swap_tests1.cpp b/test/swap_tests1.cpp deleted file mode 100644 index 5a61be4f..00000000 --- a/test/swap_tests1.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#define BOOST_UNORDERED_SWAP_METHOD 1 -#include "./swap_tests.hpp" diff --git a/test/swap_tests2.cpp b/test/swap_tests2.cpp deleted file mode 100644 index 56ccbd27..00000000 --- a/test/swap_tests2.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#define BOOST_UNORDERED_SWAP_METHOD 2 -#include "./swap_tests.hpp" diff --git a/test/swap_tests3.cpp b/test/swap_tests3.cpp deleted file mode 100644 index 13a5951f..00000000 --- a/test/swap_tests3.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#define BOOST_UNORDERED_SWAP_METHOD 3 -#include "./swap_tests.hpp" diff --git a/test/type_tests.cpp b/test/type_tests.cpp deleted file mode 100644 index 56f8c490..00000000 --- a/test/type_tests.cpp +++ /dev/null @@ -1,208 +0,0 @@ - -// Copyright Daniel James 2005. 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) - -#include -#include - -#include -#include -#include -#include -#include "./helpers/functional.hpp" - -template -struct iterator_checks -{ - typedef Iterator iterator; - - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_value::type, - typename Container::value_type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_reference::type, - typename Container::reference>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_pointer::type, - typename Container::pointer>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_difference::type, - typename Container::difference_type>)); -}; - -template -struct const_iterator_checks -{ - typedef ConstIterator const_iterator; - - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_value::type, - typename Container::value_type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_reference::type, - typename Container::const_reference>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_pointer::type, - typename Container::const_pointer>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_difference::type, - typename Container::difference_type>)); -}; - -template -struct unordered_typedef_checks -{ - typedef typename Container::iterator iterator; - typedef typename Container::const_iterator const_iterator; - typedef typename Container::local_iterator local_iterator; - typedef typename Container::const_local_iterator const_local_iterator; - - // 6.3.1/9 rows 1-3 - BOOST_MPL_ASSERT((boost::is_same< - Key, - typename Container::key_type>)); - BOOST_MPL_ASSERT((boost::is_same< - Hash, - typename Container::hasher>)); - BOOST_MPL_ASSERT((boost::is_same< - Pred, - typename Container::key_equal>)); - - // 6.3.1/9 rows 4-5 - // TODO: A local_iterator may be used to iterate through a single - // bucket but may not be used to iterate across buckets. - BOOST_MPL_ASSERT((boost::is_same< - typename boost::BOOST_ITERATOR_CATEGORY::type, - typename boost::BOOST_ITERATOR_CATEGORY::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_value::type, - typename boost::iterator_value::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_difference::type, - typename boost::iterator_difference::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_pointer::type, - typename boost::iterator_pointer::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_reference::type, - typename boost::iterator_reference::type>)); - - BOOST_MPL_ASSERT((boost::is_same< - typename boost::BOOST_ITERATOR_CATEGORY::type, - typename boost::BOOST_ITERATOR_CATEGORY::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_value::type, - typename boost::iterator_value::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_difference::type, - typename boost::iterator_difference::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_pointer::type, - typename boost::iterator_pointer::type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename boost::iterator_reference::type, - typename boost::iterator_reference::type>)); - - // TODO: Is this ever specified? - BOOST_MPL_ASSERT((boost::is_same< - AllocatorType, - typename Container::allocator_type>)); - BOOST_MPL_ASSERT((boost::is_same< - typename AllocatorType::pointer, - typename Container::pointer>)); - BOOST_MPL_ASSERT((boost::is_same< - typename AllocatorType::const_pointer, - typename Container::const_pointer>)); - BOOST_MPL_ASSERT((boost::is_same< - typename AllocatorType::reference, - typename Container::reference>)); - BOOST_MPL_ASSERT((boost::is_same< - typename AllocatorType::const_reference, - typename Container::const_reference>)); -}; - -template -struct unordered_map_checks -{ - unordered_typedef_checks c1; - iterator_checks c2; - const_iterator_checks c3; - iterator_checks c4; - const_iterator_checks c5; - - // 6.3.1/7 - BOOST_MPL_ASSERT((boost::is_same< - typename Container::value_type, - std::pair >)); -}; - -template -struct unordered_set_checks -{ - unordered_typedef_checks c1; - const_iterator_checks c2; - const_iterator_checks c3; - const_iterator_checks c4; - const_iterator_checks c5; - - // 6.3.1/7 - BOOST_MPL_ASSERT((boost::is_same< - typename Container::value_type, - typename Container::key_type>)); -}; - -unordered_set_checks< - boost::unordered_multiset, int, - boost::hash, std::equal_to, std::allocator -> int_multiset_check; - -unordered_set_checks< - boost::unordered_multiset, - std::string, test::hash, test::less, std::allocator -> custom_string_multiset_check; - -unordered_set_checks< - boost::unordered_set, int, - boost::hash, std::equal_to, std::allocator -> int_set_check; - -unordered_set_checks< - boost::unordered_set, - std::string, test::hash, test::less, std::allocator -> custom_string_set_check; - -unordered_map_checks< - boost::unordered_map, std::string, int, - boost::hash, std::equal_to, - std::allocator > -> string_int_check; - -unordered_map_checks< - boost::unordered_map, - char const*, std::string, - test::hash, test::less, - std::allocator > -> custom_check; - -unordered_map_checks< - boost::unordered_multimap, - int, int, - boost::hash, std::equal_to, - std::allocator > -> int_int_multi_check; - -unordered_map_checks< - boost::unordered_multimap, - std::string, int, - boost::hash, std::equal_to, - std::allocator > -> string_int_multi_check; - -unordered_map_checks< - boost::unordered_multimap, - float, std::string, - test::hash, test::less, - std::allocator > -> custom_multi_check;