]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal_allocator.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.set / unord.set.cnstr / range_size_hash_equal_allocator.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_set
15
16 // template <class InputIterator>
17 //     unordered_set(InputIterator first, InputIterator last, size_type n,
18 //                   const hasher& hf, const key_equal& eql,
19 //                   const allocator_type& a);
20
21 #include <unordered_set>
22 #include <cassert>
23 #include <cfloat>
24 #include <cmath>
25 #include <cstddef>
26
27 #include "test_macros.h"
28 #include "test_iterators.h"
29 #include "../../../test_compare.h"
30 #include "../../../test_hash.h"
31 #include "test_allocator.h"
32 #include "min_allocator.h"
33
34 int main()
35 {
36     {
37         typedef std::unordered_set<int,
38                                    test_hash<std::hash<int> >,
39                                    test_compare<std::equal_to<int> >,
40                                    test_allocator<int>
41                                    > C;
42         typedef int P;
43         P a[] =
44         {
45             P(1),
46             P(2),
47             P(3),
48             P(4),
49             P(1),
50             P(2)
51         };
52         C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
53             7,
54             test_hash<std::hash<int> >(8),
55             test_compare<std::equal_to<int> >(9),
56             test_allocator<int>(10)
57            );
58         LIBCPP_ASSERT(c.bucket_count() == 7);
59         assert(c.size() == 4);
60         assert(c.count(1) == 1);
61         assert(c.count(2) == 1);
62         assert(c.count(3) == 1);
63         assert(c.count(4) == 1);
64         assert(c.hash_function() == test_hash<std::hash<int> >(8));
65         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
66         assert(c.get_allocator() == test_allocator<int>(10));
67         assert(!c.empty());
68         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
69         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
70         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
71         assert(c.max_load_factor() == 1);
72     }
73 #if TEST_STD_VER >= 11
74     {
75         typedef std::unordered_set<int,
76                                    test_hash<std::hash<int> >,
77                                    test_compare<std::equal_to<int> >,
78                                    min_allocator<int>
79                                    > C;
80         typedef int P;
81         P a[] =
82         {
83             P(1),
84             P(2),
85             P(3),
86             P(4),
87             P(1),
88             P(2)
89         };
90         C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
91             7,
92             test_hash<std::hash<int> >(8),
93             test_compare<std::equal_to<int> >(9),
94             min_allocator<int>()
95            );
96         LIBCPP_ASSERT(c.bucket_count() == 7);
97         assert(c.size() == 4);
98         assert(c.count(1) == 1);
99         assert(c.count(2) == 1);
100         assert(c.count(3) == 1);
101         assert(c.count(4) == 1);
102         assert(c.hash_function() == test_hash<std::hash<int> >(8));
103         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
104         assert(c.get_allocator() == min_allocator<int>());
105         assert(!c.empty());
106         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
107         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
108         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
109         assert(c.max_load_factor() == 1);
110     }
111 #endif
112 }