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>
23 #include "../../../test_compare.h"
24 #include "../../../test_hash.h"
25 #include "test_allocator.h"
26 #include "min_allocator.h"
31 typedef test_allocator<std::pair<const int, std::string> > A;
32 typedef std::unordered_multimap<int, std::string,
33 test_hash<std::hash<int> >,
34 test_compare<std::equal_to<int> >,
37 typedef std::pair<int, std::string> P;
47 C c0(a, a + sizeof(a)/sizeof(a[0]),
49 test_hash<std::hash<int> >(8),
50 test_compare<std::equal_to<int> >(9),
55 test_hash<std::hash<int> >(2),
56 test_compare<std::equal_to<int> >(3),
60 assert(c.bucket_count() == 7);
61 assert(c.size() == 6);
62 C::const_iterator i = c.cbegin();
63 assert(i->first == 1);
64 assert(i->second == "one");
66 assert(i->first == 1);
67 assert(i->second == "four");
69 assert(i->first == 2);
70 assert(i->second == "two");
72 assert(i->first == 2);
73 assert(i->second == "four");
75 assert(i->first == 3);
76 assert(i->second == "three");
78 assert(i->first == 4);
79 assert(i->second == "four");
80 assert(c.hash_function() == test_hash<std::hash<int> >(8));
81 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
82 assert(c.get_allocator() == A(4));
84 assert(std::distance(c.begin(), c.end()) == c.size());
85 assert(std::distance(c.cbegin(), c.cend()) == c.size());
86 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
87 assert(c.max_load_factor() == 1);
90 typedef other_allocator<std::pair<const int, std::string> > A;
91 typedef std::unordered_multimap<int, std::string,
92 test_hash<std::hash<int> >,
93 test_compare<std::equal_to<int> >,
96 typedef std::pair<int, std::string> P;
106 C c0(a, a + sizeof(a)/sizeof(a[0]),
108 test_hash<std::hash<int> >(8),
109 test_compare<std::equal_to<int> >(9),
114 test_hash<std::hash<int> >(2),
115 test_compare<std::equal_to<int> >(3),
119 assert(c.bucket_count() >= 7);
120 assert(c.size() == 6);
121 C::const_iterator i = c.cbegin();
122 assert(i->first == 1);
123 assert(i->second == "one");
125 assert(i->first == 1);
126 assert(i->second == "four");
128 assert(i->first == 2);
129 assert(i->second == "two");
131 assert(i->first == 2);
132 assert(i->second == "four");
134 assert(i->first == 3);
135 assert(i->second == "three");
137 assert(i->first == 4);
138 assert(i->second == "four");
139 assert(c.hash_function() == test_hash<std::hash<int> >(8));
140 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
141 assert(c.get_allocator() == A(10));
143 assert(std::distance(c.begin(), c.end()) == c.size());
144 assert(std::distance(c.cbegin(), c.cend()) == c.size());
145 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
146 assert(c.max_load_factor() == 1);
148 #if __cplusplus >= 201103L
150 typedef min_allocator<std::pair<const int, std::string> > A;
151 typedef std::unordered_multimap<int, std::string,
152 test_hash<std::hash<int> >,
153 test_compare<std::equal_to<int> >,
156 typedef std::pair<int, std::string> P;
166 C c0(a, a + sizeof(a)/sizeof(a[0]),
168 test_hash<std::hash<int> >(8),
169 test_compare<std::equal_to<int> >(9),
174 test_hash<std::hash<int> >(2),
175 test_compare<std::equal_to<int> >(3),
179 assert(c.bucket_count() == 7);
180 assert(c.size() == 6);
181 C::const_iterator i = c.cbegin();
182 assert(i->first == 1);
183 assert(i->second == "one");
185 assert(i->first == 1);
186 assert(i->second == "four");
188 assert(i->first == 2);
189 assert(i->second == "two");
191 assert(i->first == 2);
192 assert(i->second == "four");
194 assert(i->first == 3);
195 assert(i->second == "three");
197 assert(i->first == 4);
198 assert(i->second == "four");
199 assert(c.hash_function() == test_hash<std::hash<int> >(8));
200 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
201 assert(c.get_allocator() == A());
203 assert(std::distance(c.begin(), c.end()) == c.size());
204 assert(std::distance(c.cbegin(), c.cend()) == c.size());
205 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
206 assert(c.max_load_factor() == 1);