]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.multiset / unord.multiset.cnstr / init_size.pass.cpp
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 // unordered_multiset(initializer_list<value_type> il, size_type n);
17
18 #include <unordered_set>
19 #include <cassert>
20 #include <cfloat>
21 #include <cmath>
22 #include <cstddef>
23
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"
29
30 int main()
31 {
32 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
33     {
34         typedef std::unordered_multiset<int,
35                                    test_hash<std::hash<int> >,
36                                    test_compare<std::equal_to<int> >,
37                                    test_allocator<int>
38                                    > C;
39         typedef int P;
40         C c({
41                 P(1),
42                 P(2),
43                 P(3),
44                 P(4),
45                 P(1),
46                 P(2)
47             },
48             7
49            );
50         LIBCPP_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>());
59         assert(!c.empty());
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(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
63         assert(c.max_load_factor() == 1);
64     }
65 #if TEST_STD_VER >= 11
66     {
67         typedef std::unordered_multiset<int,
68                                    test_hash<std::hash<int> >,
69                                    test_compare<std::equal_to<int> >,
70                                    min_allocator<int>
71                                    > C;
72         typedef int P;
73         C c({
74                 P(1),
75                 P(2),
76                 P(3),
77                 P(4),
78                 P(1),
79                 P(2)
80             },
81             7
82            );
83         LIBCPP_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>());
92         assert(!c.empty());
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(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
96         assert(c.max_load_factor() == 1);
97     }
98 #endif
99 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
100 }