2 // Copyright 2016 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 #include "../helpers/prefix.hpp"
7 #include <boost/unordered_set.hpp>
8 #include <boost/unordered_map.hpp>
9 #include "../helpers/postfix.hpp"
11 #include "../helpers/test.hpp"
12 #include "../helpers/invariants.hpp"
20 UNORDERED_AUTO_TEST(insert_hint_empty
) {
21 typedef boost::unordered_multiset
<int> container
;
23 x
.insert(x
.cbegin(), 10);
24 BOOST_TEST_EQ(x
.size(), 1u);
25 BOOST_TEST_EQ(x
.count(10), 1u);
26 test::check_equivalent_keys(x
);
29 UNORDERED_AUTO_TEST(insert_hint_empty2
) {
30 typedef boost::unordered_multimap
<std::string
, int> container
;
32 x
.emplace_hint(x
.cbegin(), "hello", 50);
33 BOOST_TEST_EQ(x
.size(), 1u);
34 BOOST_TEST_EQ(x
.count("hello"), 1u);
35 BOOST_TEST_EQ(x
.find("hello")->second
, 50);
36 test::check_equivalent_keys(x
);
39 UNORDERED_AUTO_TEST(insert_hint_single
) {
40 typedef boost::unordered_multiset
<std::string
> container
;
43 x
.insert(x
.cbegin(), "equal");
44 BOOST_TEST_EQ(x
.size(), 2u);
45 BOOST_TEST_EQ(x
.count("equal"), 2u);
46 test::check_equivalent_keys(x
);
49 UNORDERED_AUTO_TEST(insert_hint_single2
) {
50 typedef boost::unordered_multimap
<int, std::string
> container
;
53 x
.emplace_hint(x
.cbegin(), 10, "two");
54 BOOST_TEST_EQ(x
.size(), 2u);
55 BOOST_TEST_EQ(x
.count(10), 2u);
57 container::iterator it
= x
.find(10);
58 std::string v0
= (it
++)->second
;
59 std::string v1
= (it
++)->second
;
61 BOOST_TEST(v0
== "one" || v0
== "two");
62 BOOST_TEST(v1
== "one" || v1
== "two");
65 test::check_equivalent_keys(x
);
68 UNORDERED_AUTO_TEST(insert_hint_multiple
) {
69 for (unsigned int size
= 0; size
< 10; ++size
) {
70 for (unsigned int offset
= 0; offset
<= size
; ++offset
) {
71 typedef boost::unordered_multiset
<std::string
> container
;
74 for (unsigned int i
= 0; i
< size
; ++i
) { x
.insert("multiple"); }
76 BOOST_TEST_EQ(x
.size(), size
);
78 container::const_iterator position
= x
.cbegin();
79 for (unsigned int i
= 0; i
< offset
; ++i
) { ++position
; }
81 x
.insert(position
, "multiple");
83 BOOST_TEST_EQ(x
.size(), size
+ 1u);
84 BOOST_TEST_EQ(x
.count("multiple"), size
+ 1u);
85 test::check_equivalent_keys(x
);
90 UNORDERED_AUTO_TEST(insert_hint_unique
) {
91 typedef boost::unordered_set
<int> container
;
93 x
.insert(x
.cbegin(), 10);
94 BOOST_TEST_EQ(x
.size(), 1u);
95 BOOST_TEST_EQ(x
.count(10), 1u);
96 test::check_equivalent_keys(x
);
99 UNORDERED_AUTO_TEST(insert_hint_unique_single
) {
100 typedef boost::unordered_set
<int> container
;
104 x
.insert(x
.cbegin(), 10);
105 BOOST_TEST_EQ(x
.size(), 1u);
106 BOOST_TEST_EQ(x
.count(10), 1u);
107 test::check_equivalent_keys(x
);
109 x
.insert(x
.cbegin(), 20);
110 BOOST_TEST_EQ(x
.size(), 2u);
111 BOOST_TEST_EQ(x
.count(10), 1u);
112 BOOST_TEST_EQ(x
.count(20), 1u);
113 test::check_equivalent_keys(x
);