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>
24 #include "../../../test_compare.h"
25 #include "../../../test_hash.h"
26 #include "test_allocator.h"
27 #include "min_allocator.h"
31 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
33 typedef std::unordered_set<int,
34 test_hash<std::hash<int> >,
35 test_compare<std::equal_to<int> >,
48 test_hash<std::hash<int> >(8),
49 test_compare<std::equal_to<int> >(9),
50 test_allocator<int>(10)
52 assert(c.bucket_count() == 7);
53 assert(c.size() == 4);
54 assert(c.count(1) == 1);
55 assert(c.count(2) == 1);
56 assert(c.count(3) == 1);
57 assert(c.count(4) == 1);
58 assert(c.hash_function() == test_hash<std::hash<int> >(8));
59 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
60 assert(c.get_allocator() == test_allocator<int>(10));
62 assert(std::distance(c.begin(), c.end()) == c.size());
63 assert(std::distance(c.cbegin(), c.cend()) == c.size());
64 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
65 assert(c.max_load_factor() == 1);
67 #if __cplusplus >= 201103L
69 typedef std::unordered_set<int,
70 test_hash<std::hash<int> >,
71 test_compare<std::equal_to<int> >,
84 test_hash<std::hash<int> >(8),
85 test_compare<std::equal_to<int> >(9),
88 assert(c.bucket_count() == 7);
89 assert(c.size() == 4);
90 assert(c.count(1) == 1);
91 assert(c.count(2) == 1);
92 assert(c.count(3) == 1);
93 assert(c.count(4) == 1);
94 assert(c.hash_function() == test_hash<std::hash<int> >(8));
95 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
96 assert(c.get_allocator() == min_allocator<int>());
98 assert(std::distance(c.begin(), c.end()) == c.size());
99 assert(std::distance(c.cbegin(), c.cend()) == c.size());
100 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
101 assert(c.max_load_factor() == 1);
104 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS