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 Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13 // class Alloc = allocator<pair<const Key, T>>>
14 // class unordered_map
16 // unordered_map(initializer_list<value_type> il);
18 #include <unordered_map>
24 #include "test_macros.h"
25 #include "../../../test_compare.h"
26 #include "../../../test_hash.h"
27 #include "test_allocator.h"
28 #include "min_allocator.h"
32 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
34 typedef std::unordered_map<int, std::string,
35 test_hash<std::hash<int> >,
36 test_compare<std::equal_to<int> >,
37 test_allocator<std::pair<const int, std::string> >
39 typedef std::pair<int, std::string> P;
48 assert(c.bucket_count() >= 5);
49 assert(c.size() == 4);
50 assert(c.at(1) == "one");
51 assert(c.at(2) == "two");
52 assert(c.at(3) == "three");
53 assert(c.at(4) == "four");
54 assert(c.hash_function() == test_hash<std::hash<int> >());
55 assert(c.key_eq() == test_compare<std::equal_to<int> >());
56 assert(c.get_allocator() ==
57 (test_allocator<std::pair<const int, std::string> >()));
59 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
60 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
61 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
62 assert(c.max_load_factor() == 1);
64 #if TEST_STD_VER >= 11
66 typedef std::unordered_map<int, std::string,
67 test_hash<std::hash<int> >,
68 test_compare<std::equal_to<int> >,
69 min_allocator<std::pair<const int, std::string> >
71 typedef std::pair<int, std::string> P;
80 assert(c.bucket_count() >= 5);
81 assert(c.size() == 4);
82 assert(c.at(1) == "one");
83 assert(c.at(2) == "two");
84 assert(c.at(3) == "three");
85 assert(c.at(4) == "four");
86 assert(c.hash_function() == test_hash<std::hash<int> >());
87 assert(c.key_eq() == test_compare<std::equal_to<int> >());
88 assert(c.get_allocator() ==
89 (min_allocator<std::pair<const int, std::string> >()));
91 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
92 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
93 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
94 assert(c.max_load_factor() == 1);
98 typedef std::pair<int, std::string> P;
99 typedef test_allocator<std::pair<const int, std::string>> A;
100 typedef test_hash<std::hash<int>> HF;
101 typedef test_compare<std::equal_to<int>> Comp;
102 typedef std::unordered_map<int, std::string, HF, Comp, A> C;
113 assert(c.bucket_count() >= 12);
114 assert(c.size() == 4);
115 assert(c.at(1) == "one");
116 assert(c.at(2) == "two");
117 assert(c.at(3) == "three");
118 assert(c.at(4) == "four");
119 assert(c.hash_function() == test_hash<std::hash<int> >());
120 assert(c.key_eq() == test_compare<std::equal_to<int> >());
121 assert(c.get_allocator() == a);
123 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
124 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
125 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
126 assert(c.max_load_factor() == 1);
129 typedef std::pair<int, std::string> P;
130 typedef test_allocator<std::pair<const int, std::string>> A;
131 typedef test_hash<std::hash<int>> HF;
132 typedef test_compare<std::equal_to<int>> Comp;
133 typedef std::unordered_map<int, std::string, HF, Comp, A> C;
145 assert(c.bucket_count() >= 12);
146 assert(c.size() == 4);
147 assert(c.at(1) == "one");
148 assert(c.at(2) == "two");
149 assert(c.at(3) == "three");
150 assert(c.at(4) == "four");
151 assert(c.hash_function() == hf);
152 assert(!(c.hash_function() == test_hash<std::hash<int> >()));
153 assert(c.key_eq() == test_compare<std::equal_to<int> >());
154 assert(c.get_allocator() == a);
156 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
157 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
158 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
159 assert(c.max_load_factor() == 1);
163 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS