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)
96 std::cout << "Test unordered_set.\n";
97 boost::unordered_set<int> set;
105 std::cout << "Test unordered_multiset.\n";
106 boost::unordered_multiset<int> multiset;
107 simple_test(multiset);
109 for (int i1 = 0; i1 < 1000; ++i1) {
110 int count = rand() % 10, index = rand();
111 for (int j = 0; j < count; ++j)
112 multiset.insert(index);
114 simple_test(multiset);
116 std::cout << "Test unordered_map.\n";
117 boost::unordered_map<int, int> map;
119 for (int i2 = 0; i2 < 1000; ++i2) {
120 map.insert(std::pair<const int, int>(rand(), rand()));
124 std::cout << "Test unordered_multimap.\n";
125 boost::unordered_multimap<int, int> multimap;
127 for (int i3 = 0; i3 < 1000; ++i3) {
128 int count = rand() % 10, index = rand();
129 for (int j = 0; j < count; ++j)
130 multimap.insert(std::pair<const int, int>(index, rand()));
132 simple_test(multimap);