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(initializer_list<value_type> il);
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
> >
42 typedef std::pair
<int, std::string
> P
;
51 assert(c
.bucket_count() >= 7);
52 assert(c
.size() == 6);
53 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
54 Eq eq
= c
.equal_range(1);
55 assert(std::distance(eq
.first
, eq
.second
) == 2);
56 std::multiset
<std::string
> s
;
59 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
60 eq
= c
.equal_range(2);
61 assert(std::distance(eq
.first
, eq
.second
) == 2);
64 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
66 eq
= c
.equal_range(3);
67 assert(std::distance(eq
.first
, eq
.second
) == 1);
68 C::const_iterator i
= eq
.first
;
69 assert(i
->first
== 3);
70 assert(i
->second
== "three");
71 eq
= c
.equal_range(4);
72 assert(std::distance(eq
.first
, eq
.second
) == 1);
74 assert(i
->first
== 4);
75 assert(i
->second
== "four");
76 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
77 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
78 assert(fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
79 assert(c
.max_load_factor() == 1);
80 assert(c
.hash_function() == test_hash
<int>());
81 assert(c
.key_eq() == test_equal_to
<int>());
82 assert((c
.get_allocator() == test_allocator
<std::pair
<const int, std::string
> >()));
85 typedef std::unordered_multimap
<int, std::string
,
88 min_allocator
<std::pair
<const int, std::string
> >
90 typedef std::pair
<int, std::string
> P
;
99 assert(c
.bucket_count() >= 7);
100 assert(c
.size() == 6);
101 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
102 Eq eq
= c
.equal_range(1);
103 assert(std::distance(eq
.first
, eq
.second
) == 2);
104 std::multiset
<std::string
> s
;
107 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
108 eq
= c
.equal_range(2);
109 assert(std::distance(eq
.first
, eq
.second
) == 2);
112 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
114 eq
= c
.equal_range(3);
115 assert(std::distance(eq
.first
, eq
.second
) == 1);
116 C::const_iterator i
= eq
.first
;
117 assert(i
->first
== 3);
118 assert(i
->second
== "three");
119 eq
= c
.equal_range(4);
120 assert(std::distance(eq
.first
, eq
.second
) == 1);
122 assert(i
->first
== 4);
123 assert(i
->second
== "four");
124 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
125 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
126 assert(fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
127 assert(c
.max_load_factor() == 1);
128 assert(c
.hash_function() == test_hash
<int>());
129 assert(c
.key_eq() == test_equal_to
<int>());
130 assert((c
.get_allocator() == min_allocator
<std::pair
<const int, std::string
> >()));
132 #if TEST_STD_VER > 11
134 typedef std::pair
<int, std::string
> P
;
135 typedef test_allocator
<std::pair
<const int, std::string
>> A
;
136 typedef test_hash
<int> HF
;
137 typedef test_equal_to
<int> Comp
;
138 typedef std::unordered_multimap
<int, std::string
, HF
, Comp
, A
> C
;
149 assert(c
.bucket_count() >= 12);
150 assert(c
.size() == 6);
151 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
152 Eq eq
= c
.equal_range(1);
153 assert(std::distance(eq
.first
, eq
.second
) == 2);
154 std::multiset
<std::string
> s
;
157 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
158 eq
= c
.equal_range(2);
159 assert(std::distance(eq
.first
, eq
.second
) == 2);
162 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
164 eq
= c
.equal_range(3);
165 assert(std::distance(eq
.first
, eq
.second
) == 1);
166 C::const_iterator i
= eq
.first
;
167 assert(i
->first
== 3);
168 assert(i
->second
== "three");
169 eq
= c
.equal_range(4);
170 assert(std::distance(eq
.first
, eq
.second
) == 1);
172 assert(i
->first
== 4);
173 assert(i
->second
== "four");
174 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
175 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
176 assert(fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
177 assert(c
.max_load_factor() == 1);
178 assert(c
.hash_function() == HF());
179 assert(c
.key_eq() == Comp());
180 assert(c
.get_allocator() == a
);
181 assert(!(c
.get_allocator() == A()));
184 typedef std::pair
<int, std::string
> P
;
185 typedef test_allocator
<std::pair
<const int, std::string
>> A
;
186 typedef test_hash
<int> HF
;
187 typedef test_equal_to
<int> Comp
;
188 typedef std::unordered_multimap
<int, std::string
, HF
, Comp
, A
> C
;
200 assert(c
.bucket_count() >= 12);
201 assert(c
.size() == 6);
202 typedef std::pair
<C::const_iterator
, C::const_iterator
> Eq
;
203 Eq eq
= c
.equal_range(1);
204 assert(std::distance(eq
.first
, eq
.second
) == 2);
205 std::multiset
<std::string
> s
;
208 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
209 eq
= c
.equal_range(2);
210 assert(std::distance(eq
.first
, eq
.second
) == 2);
213 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
215 eq
= c
.equal_range(3);
216 assert(std::distance(eq
.first
, eq
.second
) == 1);
217 C::const_iterator i
= eq
.first
;
218 assert(i
->first
== 3);
219 assert(i
->second
== "three");
220 eq
= c
.equal_range(4);
221 assert(std::distance(eq
.first
, eq
.second
) == 1);
223 assert(i
->first
== 4);
224 assert(i
->second
== "four");
225 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
226 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
227 assert(fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
228 assert(c
.max_load_factor() == 1);
229 assert(c
.hash_function() == hf
);
230 assert(!(c
.hash_function() == HF()));
231 assert(c
.key_eq() == Comp());
232 assert(c
.get_allocator() == a
);
233 assert(!(c
.get_allocator() == A()));
235 #endif // TEST_STD_VER > 11