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_map
16 // unordered_map& operator=(const unordered_map& 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_map<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() == 4);
64 assert(c.at(1) == "one");
65 assert(c.at(2) == "two");
66 assert(c.at(3) == "three");
67 assert(c.at(4) == "four");
68 assert(c.hash_function() == test_hash<std::hash<int> >(8));
69 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
70 assert(c.get_allocator() == A(4));
72 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
73 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
74 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
75 assert(c.max_load_factor() == 1);
78 typedef std::unordered_map<int, std::string> C;
79 typedef std::pair<const int, std::string> P;
89 C c(a, a + sizeof(a)/sizeof(a[0]));
92 assert(c.size() == 4);
93 assert(std::is_permutation(c.begin(), c.end(), a));
96 typedef other_allocator<std::pair<const int, std::string> > A;
97 typedef std::unordered_map<int, std::string,
98 test_hash<std::hash<int> >,
99 test_compare<std::equal_to<int> >,
102 typedef std::pair<int, std::string> P;
112 C c0(a, a + sizeof(a)/sizeof(a[0]),
114 test_hash<std::hash<int> >(8),
115 test_compare<std::equal_to<int> >(9),
120 test_hash<std::hash<int> >(2),
121 test_compare<std::equal_to<int> >(3),
125 assert(c.bucket_count() >= 5);
126 assert(c.size() == 4);
127 assert(c.at(1) == "one");
128 assert(c.at(2) == "two");
129 assert(c.at(3) == "three");
130 assert(c.at(4) == "four");
131 assert(c.hash_function() == test_hash<std::hash<int> >(8));
132 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
133 assert(c.get_allocator() == A(10));
135 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
136 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
137 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
138 assert(c.max_load_factor() == 1);
140 #if TEST_STD_VER >= 11
142 typedef min_allocator<std::pair<const int, std::string> > A;
143 typedef std::unordered_map<int, std::string,
144 test_hash<std::hash<int> >,
145 test_compare<std::equal_to<int> >,
148 typedef std::pair<int, std::string> P;
158 C c0(a, a + sizeof(a)/sizeof(a[0]),
160 test_hash<std::hash<int> >(8),
161 test_compare<std::equal_to<int> >(9),
166 test_hash<std::hash<int> >(2),
167 test_compare<std::equal_to<int> >(3),
171 LIBCPP_ASSERT(c.bucket_count() == 7);
172 assert(c.size() == 4);
173 assert(c.at(1) == "one");
174 assert(c.at(2) == "two");
175 assert(c.at(3) == "three");
176 assert(c.at(4) == "four");
177 assert(c.hash_function() == test_hash<std::hash<int> >(8));
178 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
179 assert(c.get_allocator() == A());
181 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
182 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
183 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
184 assert(c.max_load_factor() == 1);