1 2 // Copyright 2006-2009 Daniel James. 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #include "./containers.hpp" 7 8 #include "../helpers/invariants.hpp" 9 #include "../helpers/random_values.hpp" 10 #include "../helpers/strong.hpp" 11 #include "../helpers/tracker.hpp" 12 #include <string> 13 14 test::seed_t initialize_seed(3298597); 15 16 template <class T> struct rehash_test_base : public test::exception_base 17 { 18 test::random_values<T> values; 19 unsigned int n; rehash_test_baserehash_test_base20 rehash_test_base(unsigned int count = 100, unsigned int n_ = 0) 21 : values(count, test::limited_range), n(n_) 22 { 23 } 24 25 typedef T data_type; 26 typedef test::strong<T> strong_type; 27 initrehash_test_base28 data_type init() const 29 { 30 T x(values.begin(), values.end(), n); 31 return x; 32 } 33 BOOST_PREVENT_MACRO_SUBSTITUTIONrehash_test_base34 void check BOOST_PREVENT_MACRO_SUBSTITUTION( 35 T const& x, strong_type const& strong) const 36 { 37 std::string scope(test::scope); 38 39 if (scope.find("hash::operator()") == std::string::npos && 40 scope.find("equal_to::operator()") == std::string::npos && 41 scope != "operator==(object, object)") 42 strong.test(x); 43 44 test::check_equivalent_keys(x); 45 } 46 }; 47 48 template <class T> struct rehash_test0 : rehash_test_base<T> 49 { rehash_test0rehash_test050 rehash_test0() : rehash_test_base<T>(0) {} runrehash_test051 void run(T& x) const 52 { 53 x.rehash(0); 54 55 DISABLE_EXCEPTIONS; 56 test::check_container(x, this->values); 57 test::check_equivalent_keys(x); 58 } 59 }; 60 61 template <class T> struct rehash_test1 : rehash_test_base<T> 62 { rehash_test1rehash_test163 rehash_test1() : rehash_test_base<T>(0) {} runrehash_test164 void run(T& x) const 65 { 66 x.rehash(200); 67 68 DISABLE_EXCEPTIONS; 69 test::check_container(x, this->values); 70 test::check_equivalent_keys(x); 71 } 72 }; 73 74 template <class T> struct rehash_test2 : rehash_test_base<T> 75 { rehash_test2rehash_test276 rehash_test2() : rehash_test_base<T>(0, 200) {} runrehash_test277 void run(T& x) const 78 { 79 x.rehash(0); 80 81 DISABLE_EXCEPTIONS; 82 test::check_container(x, this->values); 83 test::check_equivalent_keys(x); 84 } 85 }; 86 87 template <class T> struct rehash_test3 : rehash_test_base<T> 88 { rehash_test3rehash_test389 rehash_test3() : rehash_test_base<T>(10, 0) {} runrehash_test390 void run(T& x) const 91 { 92 x.rehash(200); 93 94 DISABLE_EXCEPTIONS; 95 test::check_container(x, this->values); 96 test::check_equivalent_keys(x); 97 } 98 }; 99 100 template <class T> struct rehash_test4 : rehash_test_base<T> 101 { rehash_test4rehash_test4102 rehash_test4() : rehash_test_base<T>(10, 200) {} runrehash_test4103 void run(T& x) const 104 { 105 x.rehash(0); 106 107 DISABLE_EXCEPTIONS; 108 test::check_container(x, this->values); 109 test::check_equivalent_keys(x); 110 } 111 }; 112 113 template <class T> struct rehash_test5 : rehash_test_base<T> 114 { rehash_test5rehash_test5115 rehash_test5() : rehash_test_base<T>(200, 10) {} runrehash_test5116 void run(T& x) const 117 { 118 x.rehash(0); 119 120 DISABLE_EXCEPTIONS; 121 test::check_container(x, this->values); 122 test::check_equivalent_keys(x); 123 } 124 }; 125 126 // clang-format off 127 EXCEPTION_TESTS( 128 (rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4) 129 (rehash_test5), 130 CONTAINER_SEQ) 131 // clang-format on 132 133 RUN_TESTS() 134