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_set
16 // template <class InputIterator>
17 // unordered_set(InputIterator first, InputIterator last, size_type n,
20 #include <unordered_set>
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"
36 typedef std::unordered_set<int,
37 test_hash<std::hash<int> >,
38 test_compare<std::equal_to<int> >,
51 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
53 test_hash<std::hash<int> >(8)
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>());
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);
70 #if TEST_STD_VER >= 11
72 typedef std::unordered_set<int,
73 test_hash<std::hash<int> >,
74 test_compare<std::equal_to<int> >,
87 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
89 test_hash<std::hash<int> >(8)
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>());
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);