]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.set / unord.set.cnstr / range_size_hash.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);
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            );
55         LIBCPP_ASSERT(c.bucket_count() == 7);
56         assert(c.size() == 4);
57         assert(c.count(1) == 1);
58         assert(c.count(2) == 1);
59         assert(c.count(3) == 1);
60         assert(c.count(4) == 1);
61         assert(c.hash_function() == test_hash<std::hash<int> >(8));
62         assert(c.key_eq() == test_compare<std::equal_to<int> >());
63         assert(c.get_allocator() == test_allocator<int>());
64         assert(!c.empty());
65         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
66         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
67         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
68         assert(c.max_load_factor() == 1);
69     }
70 #if TEST_STD_VER >= 11
71     {
72         typedef std::unordered_set<int,
73                                    test_hash<std::hash<int> >,
74                                    test_compare<std::equal_to<int> >,
75                                    min_allocator<int>
76                                    > C;
77         typedef int P;
78         P a[] =
79         {
80             P(1),
81             P(2),
82             P(3),
83             P(4),
84             P(1),
85             P(2)
86         };
87         C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
88             7,
89             test_hash<std::hash<int> >(8)
90            );
91         LIBCPP_ASSERT(c.bucket_count() == 7);
92         assert(c.size() == 4);
93         assert(c.count(1) == 1);
94         assert(c.count(2) == 1);
95         assert(c.count(3) == 1);
96         assert(c.count(4) == 1);
97         assert(c.hash_function() == test_hash<std::hash<int> >(8));
98         assert(c.key_eq() == test_compare<std::equal_to<int> >());
99         assert(c.get_allocator() == min_allocator<int>());
100         assert(!c.empty());
101         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
102         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
103         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
104         assert(c.max_load_factor() == 1);
105     }
106 #endif
107 }