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 // unordered_set(initializer_list<value_type> il, size_type n,
17 // const hasher& hf, const key_equal& eql, const allocator_type& a);
19 #include <unordered_set>
25 #include "test_macros.h"
26 #include "../../../test_compare.h"
27 #include "../../../test_hash.h"
28 #include "test_allocator.h"
29 #include "min_allocator.h"
33 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
35 typedef std::unordered_set<int,
36 test_hash<std::hash<int> >,
37 test_compare<std::equal_to<int> >,
50 test_hash<std::hash<int> >(8),
51 test_compare<std::equal_to<int> >(9),
52 test_allocator<int>(10)
54 LIBCPP_ASSERT(c.bucket_count() == 7);
55 assert(c.size() == 4);
56 assert(c.count(1) == 1);
57 assert(c.count(2) == 1);
58 assert(c.count(3) == 1);
59 assert(c.count(4) == 1);
60 assert(c.hash_function() == test_hash<std::hash<int> >(8));
61 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
62 assert(c.get_allocator() == test_allocator<int>(10));
64 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
65 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
66 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
67 assert(c.max_load_factor() == 1);
69 #if TEST_STD_VER >= 11
71 typedef std::unordered_set<int,
72 test_hash<std::hash<int> >,
73 test_compare<std::equal_to<int> >,
86 test_hash<std::hash<int> >(8),
87 test_compare<std::equal_to<int> >(9),
90 LIBCPP_ASSERT(c.bucket_count() == 7);
91 assert(c.size() == 4);
92 assert(c.count(1) == 1);
93 assert(c.count(2) == 1);
94 assert(c.count(3) == 1);
95 assert(c.count(4) == 1);
96 assert(c.hash_function() == test_hash<std::hash<int> >(8));
97 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
98 assert(c.get_allocator() == min_allocator<int>());
100 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
101 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
102 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
103 assert(c.max_load_factor() == 1);
106 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS