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)
6 // This test checks the runtime requirements of containers.
9 #include "../helpers/prefix.hpp"
10 #include <boost/unordered_set.hpp>
11 #include <boost/unordered_map.hpp>
12 #include "../helpers/postfix.hpp"
15 #include "../helpers/test.hpp"
18 #include "../helpers/equivalent.hpp"
20 template <class X
> void simple_test(X
const& a
)
22 test::unordered_equivalence_tester
<X
> equivalent(a
);
26 BOOST_TEST(u
.size() == 0);
27 BOOST_TEST(X().size() == 0);
31 BOOST_TEST(equivalent(X(a
)));
36 BOOST_TEST(equivalent(u
));
41 BOOST_TEST(equivalent(u
));
46 BOOST_TEST(b
.begin() == const_cast<X
const&>(b
).cbegin());
47 BOOST_TEST(b
.end() == const_cast<X
const&>(b
).cend());
53 BOOST_TEST(equivalent(b
));
54 BOOST_TEST(c
.empty());
56 BOOST_TEST(b
.empty());
57 BOOST_TEST(equivalent(c
));
59 BOOST_TEST(c
.empty());
60 BOOST_TEST(equivalent(b
));
66 BOOST_TEST(&(r
= r
) == &r
);
68 BOOST_TEST(r
.empty());
69 BOOST_TEST(&(r
= a
) == &r
);
70 BOOST_TEST(equivalent(r
));
71 BOOST_TEST(&(r
= r
) == &r
);
72 BOOST_TEST(equivalent(r
));
76 BOOST_TEST(a
.size() == static_cast<BOOST_DEDUCED_TYPENAME
X::size_type
>(
77 std::distance(a
.begin(), a
.end())));
81 BOOST_TEST(a
.empty() == (a
.size() == 0));
85 BOOST_TEST(a
.empty() == (a
.begin() == a
.end()));
87 BOOST_TEST(u
.begin() == u
.end());
91 UNORDERED_AUTO_TEST (simple_tests
) {
95 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< "Test unordered_set.\n";
96 boost::unordered_set
<int> set
;
104 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< "Test unordered_multiset.\n";
105 boost::unordered_multiset
<int> multiset
;
106 simple_test(multiset
);
108 for (int i1
= 0; i1
< 1000; ++i1
) {
109 int count
= rand() % 10, index
= rand();
110 for (int j
= 0; j
< count
; ++j
)
111 multiset
.insert(index
);
113 simple_test(multiset
);
115 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< "Test unordered_map.\n";
116 boost::unordered_map
<int, int> map
;
118 for (int i2
= 0; i2
< 1000; ++i2
) {
119 map
.insert(std::pair
<const int, int>(rand(), rand()));
123 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< "Test unordered_multimap.\n";
124 boost::unordered_multimap
<int, int> multimap
;
126 for (int i3
= 0; i3
< 1000; ++i3
) {
127 int count
= rand() % 10, index
= rand();
128 for (int j
= 0; j
< count
; ++j
)
129 multimap
.insert(std::pair
<const int, int>(index
, rand()));
131 simple_test(multimap
);