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>
22 #include "../../../test_compare.h"
23 #include "../../../test_hash.h"
24 #include "test_allocator.h"
25 #include "min_allocator.h"
30 typedef test_allocator<int> A;
31 typedef std::unordered_set<int,
32 test_hash<std::hash<int> >,
33 test_compare<std::equal_to<int> >,
46 C c0(a, a + sizeof(a)/sizeof(a[0]),
48 test_hash<std::hash<int> >(8),
49 test_compare<std::equal_to<int> >(9),
54 test_hash<std::hash<int> >(2),
55 test_compare<std::equal_to<int> >(3),
59 assert(c.bucket_count() == 7);
60 assert(c.size() == 4);
61 assert(c.count(1) == 1);
62 assert(c.count(2) == 1);
63 assert(c.count(3) == 1);
64 assert(c.count(4) == 1);
65 assert(c.hash_function() == test_hash<std::hash<int> >(8));
66 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
67 assert(c.get_allocator() == A(4));
69 assert(std::distance(c.begin(), c.end()) == c.size());
70 assert(std::distance(c.cbegin(), c.cend()) == c.size());
71 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
72 assert(c.max_load_factor() == 1);
75 typedef std::unordered_set<int> C;
86 C c(a, a + sizeof(a)/sizeof(a[0]));
89 assert(c.size() == 4);
90 assert(std::is_permutation(c.begin(), c.end(), a));
93 typedef other_allocator<int> A;
94 typedef std::unordered_set<int,
95 test_hash<std::hash<int> >,
96 test_compare<std::equal_to<int> >,
109 C c0(a, a + sizeof(a)/sizeof(a[0]),
111 test_hash<std::hash<int> >(8),
112 test_compare<std::equal_to<int> >(9),
117 test_hash<std::hash<int> >(2),
118 test_compare<std::equal_to<int> >(3),
122 assert(c.bucket_count() >= 5);
123 assert(c.size() == 4);
124 assert(c.count(1) == 1);
125 assert(c.count(2) == 1);
126 assert(c.count(3) == 1);
127 assert(c.count(4) == 1);
128 assert(c.hash_function() == test_hash<std::hash<int> >(8));
129 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
130 assert(c.get_allocator() == A(10));
132 assert(std::distance(c.begin(), c.end()) == c.size());
133 assert(std::distance(c.cbegin(), c.cend()) == c.size());
134 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
135 assert(c.max_load_factor() == 1);
137 #if __cplusplus >= 201103L
139 typedef min_allocator<int> A;
140 typedef std::unordered_set<int,
141 test_hash<std::hash<int> >,
142 test_compare<std::equal_to<int> >,
155 C c0(a, a + sizeof(a)/sizeof(a[0]),
157 test_hash<std::hash<int> >(8),
158 test_compare<std::equal_to<int> >(9),
163 test_hash<std::hash<int> >(2),
164 test_compare<std::equal_to<int> >(3),
168 assert(c.bucket_count() == 7);
169 assert(c.size() == 4);
170 assert(c.count(1) == 1);
171 assert(c.count(2) == 1);
172 assert(c.count(3) == 1);
173 assert(c.count(4) == 1);
174 assert(c.hash_function() == test_hash<std::hash<int> >(8));
175 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
176 assert(c.get_allocator() == A());
178 assert(std::distance(c.begin(), c.end()) == c.size());
179 assert(std::distance(c.cbegin(), c.cend()) == c.size());
180 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
181 assert(c.max_load_factor() == 1);