| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <unordered_set> |
| 12 | |
| 13 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 14 | // class Alloc = allocator<Value>> |
| 15 | // class unordered_set |
| 16 | |
| 17 | // unordered_set(unordered_set&& u, const allocator_type& a); |
| 18 | |
| 19 | #include <unordered_set> |
| 20 | #include <cassert> |
| 21 | #include <cfloat> |
| 22 | #include <cmath> |
| 23 | #include <cstddef> |
| 24 | |
| 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" |
| 30 | |
| 31 | int main(int, char**) { |
| 32 | { |
| 33 | typedef int P; |
| 34 | typedef test_allocator<int> A; |
| 35 | typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C; |
| 36 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 37 | C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10)); |
| 38 | C c(std::move(c0), A(12)); |
| 39 | assert(c.bucket_count() >= 5); |
| 40 | assert(c.size() == 4); |
| 41 | assert(c.count(1) == 1); |
| 42 | assert(c.count(2) == 1); |
| 43 | assert(c.count(3) == 1); |
| 44 | assert(c.count(4) == 1); |
| 45 | assert(c.hash_function() == test_hash<int>(8)); |
| 46 | assert(c.key_eq() == test_equal_to<int>(9)); |
| 47 | assert(c.get_allocator() == A(12)); |
| 48 | assert(!c.empty()); |
| 49 | assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 50 | assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 51 | assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON); |
| 52 | assert(c.max_load_factor() == 1); |
| 53 | |
| 54 | assert(c0.empty()); |
| 55 | } |
| 56 | { |
| 57 | typedef int P; |
| 58 | typedef test_allocator<int> A; |
| 59 | typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C; |
| 60 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 61 | C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10)); |
| 62 | C c(std::move(c0), A(10)); |
| 63 | assert(c.bucket_count() >= 5); |
| 64 | assert(c.size() == 4); |
| 65 | assert(c.count(1) == 1); |
| 66 | assert(c.count(2) == 1); |
| 67 | assert(c.count(3) == 1); |
| 68 | assert(c.count(4) == 1); |
| 69 | assert(c.hash_function() == test_hash<int>(8)); |
| 70 | assert(c.key_eq() == test_equal_to<int>(9)); |
| 71 | assert(c.get_allocator() == A(10)); |
| 72 | assert(!c.empty()); |
| 73 | assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 74 | assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 75 | assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON); |
| 76 | assert(c.max_load_factor() == 1); |
| 77 | |
| 78 | assert(c0.empty()); |
| 79 | } |
| 80 | { |
| 81 | typedef int P; |
| 82 | typedef min_allocator<int> A; |
| 83 | typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C; |
| 84 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 85 | C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A()); |
| 86 | C c(std::move(c0), A()); |
| 87 | assert(c.bucket_count() >= 5); |
| 88 | assert(c.size() == 4); |
| 89 | assert(c.count(1) == 1); |
| 90 | assert(c.count(2) == 1); |
| 91 | assert(c.count(3) == 1); |
| 92 | assert(c.count(4) == 1); |
| 93 | assert(c.hash_function() == test_hash<int>(8)); |
| 94 | assert(c.key_eq() == test_equal_to<int>(9)); |
| 95 | assert(c.get_allocator() == A()); |
| 96 | assert(!c.empty()); |
| 97 | assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 98 | assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 99 | assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON); |
| 100 | assert(c.max_load_factor() == 1); |
| 101 | |
| 102 | assert(c0.empty()); |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |