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_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_set 15 16 // unordered_set(const unordered_set& u, const allocator_type& a); 17 18 #include <unordered_set> 19 #include <cassert> 20 #include <cfloat> 21 #include <cmath> 22 #include <cstddef> 23 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" 29 30 int main() 31 { 32 { 33 typedef std::unordered_set<int, 34 test_hash<std::hash<int> >, 35 test_compare<std::equal_to<int> >, 36 test_allocator<int> 37 > C; 38 typedef int P; 39 P a[] = 40 { 41 P(1), 42 P(2), 43 P(3), 44 P(4), 45 P(1), 46 P(2) 47 }; 48 C c0(a, a + sizeof(a)/sizeof(a[0]), 49 7, 50 test_hash<std::hash<int> >(8), 51 test_compare<std::equal_to<int> >(9), 52 test_allocator<int>(10) 53 ); 54 C c(c0, test_allocator<int>(5)); 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> >(9)); 63 assert(c.get_allocator() == test_allocator<int>(5)); 64 assert(!c.empty()); 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); 69 } 70 #if TEST_STD_VER >= 11 71 { 72 typedef std::unordered_set<int, 73 test_hash<std::hash<int> >, 74 test_compare<std::equal_to<int> >, 75 min_allocator<int> 76 > C; 77 typedef int P; 78 P a[] = 79 { 80 P(1), 81 P(2), 82 P(3), 83 P(4), 84 P(1), 85 P(2) 86 }; 87 C c0(a, a + sizeof(a)/sizeof(a[0]), 88 7, 89 test_hash<std::hash<int> >(8), 90 test_compare<std::equal_to<int> >(9), 91 min_allocator<int>() 92 ); 93 C c(c0, min_allocator<int>()); 94 LIBCPP_ASSERT(c.bucket_count() == 7); 95 assert(c.size() == 4); 96 assert(c.count(1) == 1); 97 assert(c.count(2) == 1); 98 assert(c.count(3) == 1); 99 assert(c.count(4) == 1); 100 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 101 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 102 assert(c.get_allocator() == min_allocator<int>()); 103 assert(!c.empty()); 104 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 105 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 106 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 107 assert(c.max_load_factor() == 1); 108 } 109 #endif 110 } 111