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_multiset
16 // template <class InputIterator>
17 // unordered_multiset(InputIterator first, InputIterator last);
19 #include <unordered_set>
24 #include "test_macros.h"
25 #include "test_iterators.h"
26 #include "../../../test_compare.h"
27 #include "../../../test_hash.h"
28 #include "test_allocator.h"
29 #include "min_allocator.h"
34 typedef std::unordered_multiset<int,
35 test_hash<std::hash<int> >,
36 test_compare<std::equal_to<int> >,
49 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
50 assert(c.bucket_count() >= 7);
51 assert(c.size() == 6);
52 assert(c.count(1) == 2);
53 assert(c.count(2) == 2);
54 assert(c.count(3) == 1);
55 assert(c.count(4) == 1);
56 assert(c.hash_function() == test_hash<std::hash<int> >());
57 assert(c.key_eq() == test_compare<std::equal_to<int> >());
58 assert(c.get_allocator() == test_allocator<int>());
60 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
61 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
62 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
63 assert(c.max_load_factor() == 1);
65 #if TEST_STD_VER >= 11
67 typedef std::unordered_multiset<int,
68 test_hash<std::hash<int> >,
69 test_compare<std::equal_to<int> >,
82 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
83 assert(c.bucket_count() >= 7);
84 assert(c.size() == 6);
85 assert(c.count(1) == 2);
86 assert(c.count(2) == 2);
87 assert(c.count(3) == 1);
88 assert(c.count(4) == 1);
89 assert(c.hash_function() == test_hash<std::hash<int> >());
90 assert(c.key_eq() == test_compare<std::equal_to<int> >());
91 assert(c.get_allocator() == min_allocator<int>());
93 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
94 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
95 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
96 assert(c.max_load_factor() == 1);
101 typedef test_hash<std::hash<T>> HF;
102 typedef test_compare<std::equal_to<T>> Comp;
103 typedef test_allocator<T> A;
104 typedef std::unordered_multiset<T, HF, Comp, A> C;
115 C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 12, a);
116 assert(c.bucket_count() >= 12);
117 assert(c.size() == 6);
118 assert(c.count(1) == 2);
119 assert(c.count(2) == 2);
120 assert(c.count(3) == 1);
121 assert(c.count(4) == 1);
122 assert(c.hash_function() == HF());
123 assert(c.key_eq() == Comp());
124 assert(c.get_allocator() == a);
125 assert(!(c.get_allocator() == A()));
127 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
128 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
129 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
130 assert(c.max_load_factor() == 1);
134 typedef test_hash<std::hash<T>> HF;
135 typedef test_compare<std::equal_to<T>> Comp;
136 typedef test_allocator<T> A;
137 typedef std::unordered_multiset<T, HF, Comp, A> C;
149 C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a);
150 assert(c.bucket_count() >= 16);
151 assert(c.size() == 6);
152 assert(c.count(1) == 2);
153 assert(c.count(2) == 2);
154 assert(c.count(3) == 1);
155 assert(c.count(4) == 1);
156 assert(c.hash_function() == hf);
157 assert(!(c.hash_function() == HF()));
158 assert(c.key_eq() == Comp());
159 assert(c.get_allocator() == a);
160 assert(!(c.get_allocator() == A()));
162 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
163 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
164 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
165 assert(c.max_load_factor() == 1);