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_map> 11 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_multimap 15 16// template <class InputIterator> 17// unordered_multimap(InputIterator first, InputIterator last, size_type n); 18 19#include <unordered_map> 20#include <string> 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 "../../../NotConstructible.h" 29#include "../../../test_compare.h" 30#include "../../../test_hash.h" 31#include "test_allocator.h" 32#include "min_allocator.h" 33 34int main() 35{ 36 { 37 typedef std::unordered_multimap<int, std::string, 38 test_hash<std::hash<int> >, 39 test_compare<std::equal_to<int> >, 40 test_allocator<std::pair<const int, std::string> > 41 > C; 42 typedef std::pair<int, std::string> P; 43 P a[] = 44 { 45 P(1, "one"), 46 P(2, "two"), 47 P(3, "three"), 48 P(4, "four"), 49 P(1, "four"), 50 P(2, "four"), 51 }; 52 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), 53 10 54 ); 55 LIBCPP_ASSERT(c.bucket_count() == 11); 56 assert(c.size() == 6); 57 typedef std::pair<C::const_iterator, C::const_iterator> Eq; 58 Eq eq = c.equal_range(1); 59 assert(std::distance(eq.first, eq.second) == 2); 60 C::const_iterator i = eq.first; 61 assert(i->first == 1); 62 assert(i->second == "one"); 63 ++i; 64 assert(i->first == 1); 65 assert(i->second == "four"); 66 eq = c.equal_range(2); 67 assert(std::distance(eq.first, eq.second) == 2); 68 i = eq.first; 69 assert(i->first == 2); 70 assert(i->second == "two"); 71 ++i; 72 assert(i->first == 2); 73 assert(i->second == "four"); 74 75 eq = c.equal_range(3); 76 assert(std::distance(eq.first, eq.second) == 1); 77 i = eq.first; 78 assert(i->first == 3); 79 assert(i->second == "three"); 80 eq = c.equal_range(4); 81 assert(std::distance(eq.first, eq.second) == 1); 82 i = eq.first; 83 assert(i->first == 4); 84 assert(i->second == "four"); 85 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 86 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 87 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 88 assert(c.max_load_factor() == 1); 89 assert(c.hash_function() == test_hash<std::hash<int> >()); 90 assert(c.key_eq() == test_compare<std::equal_to<int> >()); 91 assert((c.get_allocator() == test_allocator<std::pair<const int, std::string> >())); 92 } 93#if TEST_STD_VER >= 11 94 { 95 typedef std::unordered_multimap<int, std::string, 96 test_hash<std::hash<int> >, 97 test_compare<std::equal_to<int> >, 98 min_allocator<std::pair<const int, std::string> > 99 > C; 100 typedef std::pair<int, std::string> P; 101 P a[] = 102 { 103 P(1, "one"), 104 P(2, "two"), 105 P(3, "three"), 106 P(4, "four"), 107 P(1, "four"), 108 P(2, "four"), 109 }; 110 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), 111 10 112 ); 113 LIBCPP_ASSERT(c.bucket_count() == 11); 114 assert(c.size() == 6); 115 typedef std::pair<C::const_iterator, C::const_iterator> Eq; 116 Eq eq = c.equal_range(1); 117 assert(std::distance(eq.first, eq.second) == 2); 118 C::const_iterator i = eq.first; 119 assert(i->first == 1); 120 assert(i->second == "one"); 121 ++i; 122 assert(i->first == 1); 123 assert(i->second == "four"); 124 eq = c.equal_range(2); 125 assert(std::distance(eq.first, eq.second) == 2); 126 i = eq.first; 127 assert(i->first == 2); 128 assert(i->second == "two"); 129 ++i; 130 assert(i->first == 2); 131 assert(i->second == "four"); 132 133 eq = c.equal_range(3); 134 assert(std::distance(eq.first, eq.second) == 1); 135 i = eq.first; 136 assert(i->first == 3); 137 assert(i->second == "three"); 138 eq = c.equal_range(4); 139 assert(std::distance(eq.first, eq.second) == 1); 140 i = eq.first; 141 assert(i->first == 4); 142 assert(i->second == "four"); 143 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 144 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 145 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 146 assert(c.max_load_factor() == 1); 147 assert(c.hash_function() == test_hash<std::hash<int> >()); 148 assert(c.key_eq() == test_compare<std::equal_to<int> >()); 149 assert((c.get_allocator() == min_allocator<std::pair<const int, std::string> >())); 150 } 151#endif 152} 153