1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <unordered_set>
11
12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 // class Alloc = allocator<Value>>
14 // class unordered_multiset
15
16 // template <class InputIterator>
17 // unordered_multiset(InputIterator first, InputIterator last);
18
19 #include <unordered_set>
20 #include <cassert>
21 #include <cfloat>
22
23 #include "test_iterators.h"
24 #include "../../../test_compare.h"
25 #include "../../../test_hash.h"
26 #include "test_allocator.h"
27 #include "min_allocator.h"
28
main()29 int main()
30 {
31 {
32 typedef std::unordered_multiset<int,
33 test_hash<std::hash<int> >,
34 test_compare<std::equal_to<int> >,
35 test_allocator<int>
36 > C;
37 typedef int P;
38 P a[] =
39 {
40 P(1),
41 P(2),
42 P(3),
43 P(4),
44 P(1),
45 P(2)
46 };
47 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
48 assert(c.bucket_count() >= 7);
49 assert(c.size() == 6);
50 assert(c.count(1) == 2);
51 assert(c.count(2) == 2);
52 assert(c.count(3) == 1);
53 assert(c.count(4) == 1);
54 assert(c.hash_function() == test_hash<std::hash<int> >());
55 assert(c.key_eq() == test_compare<std::equal_to<int> >());
56 assert(c.get_allocator() == test_allocator<int>());
57 assert(!c.empty());
58 assert(std::distance(c.begin(), c.end()) == c.size());
59 assert(std::distance(c.cbegin(), c.cend()) == c.size());
60 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
61 assert(c.max_load_factor() == 1);
62 }
63 #if __cplusplus >= 201103L
64 {
65 typedef std::unordered_multiset<int,
66 test_hash<std::hash<int> >,
67 test_compare<std::equal_to<int> >,
68 min_allocator<int>
69 > C;
70 typedef int P;
71 P a[] =
72 {
73 P(1),
74 P(2),
75 P(3),
76 P(4),
77 P(1),
78 P(2)
79 };
80 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
81 assert(c.bucket_count() >= 7);
82 assert(c.size() == 6);
83 assert(c.count(1) == 2);
84 assert(c.count(2) == 2);
85 assert(c.count(3) == 1);
86 assert(c.count(4) == 1);
87 assert(c.hash_function() == test_hash<std::hash<int> >());
88 assert(c.key_eq() == test_compare<std::equal_to<int> >());
89 assert(c.get_allocator() == min_allocator<int>());
90 assert(!c.empty());
91 assert(std::distance(c.begin(), c.end()) == c.size());
92 assert(std::distance(c.cbegin(), c.cend()) == c.size());
93 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
94 assert(c.max_load_factor() == 1);
95 }
96 #if _LIBCPP_STD_VER > 11
97 {
98 typedef int T;
99 typedef test_hash<std::hash<T>> HF;
100 typedef test_compare<std::equal_to<T>> Comp;
101 typedef test_allocator<T> A;
102 typedef std::unordered_multiset<T, HF, Comp, A> C;
103 T arr[] =
104 {
105 T(1),
106 T(2),
107 T(3),
108 T(4),
109 T(1),
110 T(2)
111 };
112 A a(42);
113 C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 12, a);
114 assert(c.bucket_count() >= 12);
115 assert(c.size() == 6);
116 assert(c.count(1) == 2);
117 assert(c.count(2) == 2);
118 assert(c.count(3) == 1);
119 assert(c.count(4) == 1);
120 assert(c.hash_function() == HF());
121 assert(c.key_eq() == Comp());
122 assert(c.get_allocator() == a);
123 assert(!(c.get_allocator() == A()));
124 assert(!c.empty());
125 assert(std::distance(c.begin(), c.end()) == c.size());
126 assert(std::distance(c.cbegin(), c.cend()) == c.size());
127 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
128 assert(c.max_load_factor() == 1);
129 }
130 {
131 typedef int T;
132 typedef test_hash<std::hash<T>> HF;
133 typedef test_compare<std::equal_to<T>> Comp;
134 typedef test_allocator<T> A;
135 typedef std::unordered_multiset<T, HF, Comp, A> C;
136 T arr[] =
137 {
138 T(1),
139 T(2),
140 T(3),
141 T(4),
142 T(1),
143 T(2)
144 };
145 HF hf(43);
146 A a(42);
147 C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a);
148 assert(c.bucket_count() >= 16);
149 assert(c.size() == 6);
150 assert(c.count(1) == 2);
151 assert(c.count(2) == 2);
152 assert(c.count(3) == 1);
153 assert(c.count(4) == 1);
154 assert(c.hash_function() == hf);
155 assert(!(c.hash_function() == HF()));
156 assert(c.key_eq() == Comp());
157 assert(c.get_allocator() == a);
158 assert(!(c.get_allocator() == A()));
159 assert(!c.empty());
160 assert(std::distance(c.begin(), c.end()) == c.size());
161 assert(std::distance(c.cbegin(), c.cend()) == c.size());
162 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
163 assert(c.max_load_factor() == 1);
164 }
165 #endif
166 #endif
167 }
168