1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13 // class Alloc = allocator<pair<const Key, T>>>
14 // class unordered_multimap
16 // unordered_multimap& operator=(const unordered_multimap& u);
18 #include <unordered_map>
24 #include "test_macros.h"
25 #include "../../../test_compare.h"
26 #include "../../../test_hash.h"
27 #include "test_allocator.h"
28 #include "min_allocator.h"
33 typedef test_allocator<std::pair<const int, std::string> > A;
34 typedef std::unordered_multimap<int, std::string,
35 test_hash<std::hash<int> >,
36 test_compare<std::equal_to<int> >,
39 typedef std::pair<int, std::string> P;
49 C c0(a, a + sizeof(a)/sizeof(a[0]),
51 test_hash<std::hash<int> >(8),
52 test_compare<std::equal_to<int> >(9),
57 test_hash<std::hash<int> >(2),
58 test_compare<std::equal_to<int> >(3),
62 LIBCPP_ASSERT(c.bucket_count() == 7);
63 assert(c.size() == 6);
64 C::const_iterator i = c.cbegin();
65 assert(i->first == 1);
66 assert(i->second == "one");
68 assert(i->first == 1);
69 assert(i->second == "four");
71 assert(i->first == 2);
72 assert(i->second == "two");
74 assert(i->first == 2);
75 assert(i->second == "four");
77 assert(i->first == 3);
78 assert(i->second == "three");
80 assert(i->first == 4);
81 assert(i->second == "four");
82 assert(c.hash_function() == test_hash<std::hash<int> >(8));
83 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
84 assert(c.get_allocator() == A(4));
86 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
87 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
88 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
89 assert(c.max_load_factor() == 1);
92 typedef std::unordered_multimap<int, std::string> C;
93 typedef std::pair<const int, std::string> P;
103 C c(a, a+sizeof(a)/sizeof(a[0]));
106 assert(c.size() == 6);
107 assert(std::is_permutation(c.begin(), c.end(), a));
110 typedef other_allocator<std::pair<const int, std::string> > A;
111 typedef std::unordered_multimap<int, std::string,
112 test_hash<std::hash<int> >,
113 test_compare<std::equal_to<int> >,
116 typedef std::pair<int, std::string> P;
126 C c0(a, a + sizeof(a)/sizeof(a[0]),
128 test_hash<std::hash<int> >(8),
129 test_compare<std::equal_to<int> >(9),
134 test_hash<std::hash<int> >(2),
135 test_compare<std::equal_to<int> >(3),
139 assert(c.bucket_count() >= 7);
140 assert(c.size() == 6);
141 C::const_iterator i = c.cbegin();
142 assert(i->first == 1);
143 assert(i->second == "one");
145 assert(i->first == 1);
146 assert(i->second == "four");
148 assert(i->first == 2);
149 assert(i->second == "two");
151 assert(i->first == 2);
152 assert(i->second == "four");
154 assert(i->first == 3);
155 assert(i->second == "three");
157 assert(i->first == 4);
158 assert(i->second == "four");
159 assert(c.hash_function() == test_hash<std::hash<int> >(8));
160 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
161 assert(c.get_allocator() == A(10));
163 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
164 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
165 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
166 assert(c.max_load_factor() == 1);
168 #if TEST_STD_VER >= 11
170 typedef min_allocator<std::pair<const int, std::string> > A;
171 typedef std::unordered_multimap<int, std::string,
172 test_hash<std::hash<int> >,
173 test_compare<std::equal_to<int> >,
176 typedef std::pair<int, std::string> P;
186 C c0(a, a + sizeof(a)/sizeof(a[0]),
188 test_hash<std::hash<int> >(8),
189 test_compare<std::equal_to<int> >(9),
194 test_hash<std::hash<int> >(2),
195 test_compare<std::equal_to<int> >(3),
199 LIBCPP_ASSERT(c.bucket_count() == 7);
200 assert(c.size() == 6);
201 C::const_iterator i = c.cbegin();
202 assert(i->first == 1);
203 assert(i->second == "one");
205 assert(i->first == 1);
206 assert(i->second == "four");
208 assert(i->first == 2);
209 assert(i->second == "two");
211 assert(i->first == 2);
212 assert(i->second == "four");
214 assert(i->first == 3);
215 assert(i->second == "three");
217 assert(i->first == 4);
218 assert(i->second == "four");
219 assert(c.hash_function() == test_hash<std::hash<int> >(8));
220 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
221 assert(c.get_allocator() == A());
223 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
224 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
225 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
226 assert(c.max_load_factor() == 1);