1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
14 // class Alloc = allocator<pair<const Key, T>>>
15 // class unordered_multimap
17 // unordered_multimap(unordered_multimap&& u);
19 #include <unordered_map>
27 #include "test_macros.h"
28 #include "../../../check_consecutive.h"
29 #include "../../../test_compare.h"
30 #include "../../../test_hash.h"
31 #include "test_allocator.h"
32 #include "min_allocator.h"
37 typedef std::unordered_multimap
<int, std::string
,
40 test_allocator
<std::pair
<const int, std::string
> >
45 test_equal_to
<int>(9),
46 test_allocator
<std::pair
<const int, std::string
> >(10)
49 LIBCPP_ASSERT(c
.bucket_count() == 7);
50 assert(c
.size() == 0);
51 assert(c
.hash_function() == test_hash
<int>(8));
52 assert(c
.key_eq() == test_equal_to
<int>(9));
53 assert(c
.get_allocator() ==
54 (test_allocator
<std::pair
<const int, std::string
> >(10)));
56 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
57 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
58 assert(c
.load_factor() == 0);
59 assert(c
.max_load_factor() == 1);
64 typedef std::unordered_multimap
<int, std::string
,
67 test_allocator
<std::pair
<const int, std::string
> >
69 typedef std::pair
<int, std::string
> P
;
79 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
82 test_equal_to
<int>(9),
83 test_allocator
<std::pair
<const int, std::string
> >(10)
85 C::iterator it0
= c0
.begin();
87 assert(it0
== c
.begin()); // Iterators remain valid
88 LIBCPP_ASSERT(c
.bucket_count() == 7);
89 assert(c
.size() == 6);
90 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
91 Eq eq
= c
.equal_range(1);
92 assert(std::distance(eq
.first
, eq
.second
) == 2);
93 std::multiset
<std::string
> s
;
96 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
97 eq
= c
.equal_range(2);
98 assert(std::distance(eq
.first
, eq
.second
) == 2);
101 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
103 eq
= c
.equal_range(3);
104 assert(std::distance(eq
.first
, eq
.second
) == 1);
105 C::const_iterator i
= eq
.first
;
106 assert(i
->first
== 3);
107 assert(i
->second
== "three");
108 eq
= c
.equal_range(4);
109 assert(std::distance(eq
.first
, eq
.second
) == 1);
111 assert(i
->first
== 4);
112 assert(i
->second
== "four");
113 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
114 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
115 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
116 assert(c
.max_load_factor() == 1);
117 assert(c
.hash_function() == test_hash
<int>(8));
118 assert(c
.key_eq() == test_equal_to
<int>(9));
119 assert((c
.get_allocator() == test_allocator
<std::pair
<const int, std::string
> >(10)));
124 typedef std::unordered_multimap
<int, std::string
,
127 min_allocator
<std::pair
<const int, std::string
> >
131 test_equal_to
<int>(9),
132 min_allocator
<std::pair
<const int, std::string
> >()
135 LIBCPP_ASSERT(c
.bucket_count() == 7);
136 assert(c
.size() == 0);
137 assert(c
.hash_function() == test_hash
<int>(8));
138 assert(c
.key_eq() == test_equal_to
<int>(9));
139 assert(c
.get_allocator() ==
140 (min_allocator
<std::pair
<const int, std::string
> >()));
142 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
143 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
144 assert(c
.load_factor() == 0);
145 assert(c
.max_load_factor() == 1);
150 typedef std::unordered_multimap
<int, std::string
,
153 min_allocator
<std::pair
<const int, std::string
> >
155 typedef std::pair
<int, std::string
> P
;
165 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
168 test_equal_to
<int>(9),
169 min_allocator
<std::pair
<const int, std::string
> >()
171 C::iterator it0
= c0
.begin();
173 assert(it0
== c
.begin()); // Iterators remain valid
174 LIBCPP_ASSERT(c
.bucket_count() == 7);
175 assert(c
.size() == 6);
176 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
177 Eq eq
= c
.equal_range(1);
178 assert(std::distance(eq
.first
, eq
.second
) == 2);
179 std::multiset
<std::string
> s
;
182 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
183 eq
= c
.equal_range(2);
184 assert(std::distance(eq
.first
, eq
.second
) == 2);
187 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
189 eq
= c
.equal_range(3);
190 assert(std::distance(eq
.first
, eq
.second
) == 1);
191 C::const_iterator i
= eq
.first
;
192 assert(i
->first
== 3);
193 assert(i
->second
== "three");
194 eq
= c
.equal_range(4);
195 assert(std::distance(eq
.first
, eq
.second
) == 1);
197 assert(i
->first
== 4);
198 assert(i
->second
== "four");
199 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
200 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
201 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
202 assert(c
.max_load_factor() == 1);
203 assert(c
.hash_function() == test_hash
<int>(8));
204 assert(c
.key_eq() == test_equal_to
<int>(9));
205 assert((c
.get_allocator() == min_allocator
<std::pair
<const int, std::string
> >()));