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 Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 // class Alloc = allocator<Value>>
14 // class unordered_set
16 // unordered_set& operator=(const unordered_set& u);
18 #include <unordered_set>
23 #include "test_macros.h"
24 #include "../../../test_compare.h"
25 #include "../../../test_hash.h"
26 #include "test_allocator.h"
27 #include "min_allocator.h"
32 typedef test_allocator<int> A;
33 typedef std::unordered_set<int,
34 test_hash<std::hash<int> >,
35 test_compare<std::equal_to<int> >,
48 C c0(a, a + sizeof(a)/sizeof(a[0]),
50 test_hash<std::hash<int> >(8),
51 test_compare<std::equal_to<int> >(9),
56 test_hash<std::hash<int> >(2),
57 test_compare<std::equal_to<int> >(3),
61 LIBCPP_ASSERT(c.bucket_count() == 7);
62 assert(c.size() == 4);
63 assert(c.count(1) == 1);
64 assert(c.count(2) == 1);
65 assert(c.count(3) == 1);
66 assert(c.count(4) == 1);
67 assert(c.hash_function() == test_hash<std::hash<int> >(8));
68 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
69 assert(c.get_allocator() == A(4));
71 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
72 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
73 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
74 assert(c.max_load_factor() == 1);
77 typedef std::unordered_set<int> C;
88 C c(a, a + sizeof(a)/sizeof(a[0]));
91 assert(c.size() == 4);
92 assert(std::is_permutation(c.begin(), c.end(), a));
95 typedef other_allocator<int> A;
96 typedef std::unordered_set<int,
97 test_hash<std::hash<int> >,
98 test_compare<std::equal_to<int> >,
111 C c0(a, a + sizeof(a)/sizeof(a[0]),
113 test_hash<std::hash<int> >(8),
114 test_compare<std::equal_to<int> >(9),
119 test_hash<std::hash<int> >(2),
120 test_compare<std::equal_to<int> >(3),
124 assert(c.bucket_count() >= 5);
125 assert(c.size() == 4);
126 assert(c.count(1) == 1);
127 assert(c.count(2) == 1);
128 assert(c.count(3) == 1);
129 assert(c.count(4) == 1);
130 assert(c.hash_function() == test_hash<std::hash<int> >(8));
131 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
132 assert(c.get_allocator() == A(10));
134 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
135 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
136 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
137 assert(c.max_load_factor() == 1);
139 #if TEST_STD_VER >= 11
141 typedef min_allocator<int> A;
142 typedef std::unordered_set<int,
143 test_hash<std::hash<int> >,
144 test_compare<std::equal_to<int> >,
157 C c0(a, a + sizeof(a)/sizeof(a[0]),
159 test_hash<std::hash<int> >(8),
160 test_compare<std::equal_to<int> >(9),
165 test_hash<std::hash<int> >(2),
166 test_compare<std::equal_to<int> >(3),
170 LIBCPP_ASSERT(c.bucket_count() == 7);
171 assert(c.size() == 4);
172 assert(c.count(1) == 1);
173 assert(c.count(2) == 1);
174 assert(c.count(3) == 1);
175 assert(c.count(4) == 1);
176 assert(c.hash_function() == test_hash<std::hash<int> >(8));
177 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
178 assert(c.get_allocator() == A());
180 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
181 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
182 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
183 assert(c.max_load_factor() == 1);