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