| 1 | |
| 2 | // Copyright 2006-2009 Daniel James. |
| 3 | // Copyright 2022-2023 Christian Mazakas. |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | #include "../helpers/unordered.hpp" |
| 8 | |
| 9 | #include "../helpers/test.hpp" |
| 10 | #include <algorithm> |
| 11 | #include <map> |
| 12 | #include "../helpers/list.hpp" |
| 13 | #include "../helpers/tracker.hpp" |
| 14 | #include "../helpers/invariants.hpp" |
| 15 | |
| 16 | template <class Container, class Iterator> |
| 17 | void test_equal_insertion(Iterator begin, Iterator end) |
| 18 | { |
| 19 | typedef test::ordered<Container> tracker; |
| 20 | |
| 21 | Container x1; |
| 22 | tracker x2 = test::create_ordered(x1); |
| 23 | |
| 24 | for (Iterator it = begin; it != end; ++it) { |
| 25 | x1.insert(*it); |
| 26 | x2.insert(*it); |
| 27 | x2.compare_key(x1, *it); |
| 28 | } |
| 29 | |
| 30 | x2.compare(x1); |
| 31 | test::check_equivalent_keys(x1); |
| 32 | } |
| 33 | |
| 34 | UNORDERED_AUTO_TEST (set_tests) { |
| 35 | int values[][5] = {{1}, {54, 23}, {-13, 65}, {77, 77}, {986, 25, 986}}; |
| 36 | |
| 37 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 38 | typedef boost::unordered_flat_set<int> set; |
| 39 | |
| 40 | test_equal_insertion<set>(values[0], values[0] + 1); |
| 41 | test_equal_insertion<set>(values[1], values[1] + 2); |
| 42 | test_equal_insertion<set>(values[2], values[2] + 2); |
| 43 | test_equal_insertion<set>(values[3], values[3] + 2); |
| 44 | test_equal_insertion<set>(values[4], values[4] + 3); |
| 45 | |
| 46 | typedef boost::unordered_node_set<int> node_set; |
| 47 | test_equal_insertion<node_set>(values[0], values[0] + 1); |
| 48 | test_equal_insertion<node_set>(values[1], values[1] + 2); |
| 49 | test_equal_insertion<node_set>(values[2], values[2] + 2); |
| 50 | test_equal_insertion<node_set>(values[3], values[3] + 2); |
| 51 | test_equal_insertion<node_set>(values[4], values[4] + 3); |
| 52 | #else |
| 53 | typedef boost::unordered_set<int> set; |
| 54 | |
| 55 | test_equal_insertion<set>(begin: values[0], end: values[0] + 1); |
| 56 | test_equal_insertion<set>(begin: values[1], end: values[1] + 2); |
| 57 | test_equal_insertion<set>(begin: values[2], end: values[2] + 2); |
| 58 | test_equal_insertion<set>(begin: values[3], end: values[3] + 2); |
| 59 | test_equal_insertion<set>(begin: values[4], end: values[4] + 3); |
| 60 | |
| 61 | typedef boost::unordered_multiset<int> multiset; |
| 62 | test_equal_insertion<multiset>(begin: values[0], end: values[0] + 1); |
| 63 | test_equal_insertion<multiset>(begin: values[1], end: values[1] + 2); |
| 64 | test_equal_insertion<multiset>(begin: values[2], end: values[2] + 2); |
| 65 | test_equal_insertion<multiset>(begin: values[3], end: values[3] + 2); |
| 66 | test_equal_insertion<multiset>(begin: values[4], end: values[4] + 3); |
| 67 | #endif |
| 68 | |
| 69 | } |
| 70 | |
| 71 | UNORDERED_AUTO_TEST (map_tests) { |
| 72 | typedef test::list<std::pair<int const, int> > values_type; |
| 73 | values_type v[5]; |
| 74 | v[0].push_back(v: std::pair<int const, int>(1, 1)); |
| 75 | v[1].push_back(v: std::pair<int const, int>(28, 34)); |
| 76 | v[1].push_back(v: std::pair<int const, int>(16, 58)); |
| 77 | v[1].push_back(v: std::pair<int const, int>(-124, 62)); |
| 78 | v[2].push_back(v: std::pair<int const, int>(432, 12)); |
| 79 | v[2].push_back(v: std::pair<int const, int>(9, 13)); |
| 80 | v[2].push_back(v: std::pair<int const, int>(432, 24)); |
| 81 | |
| 82 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 83 | for (int i = 0; i < 5; ++i) |
| 84 | test_equal_insertion<boost::unordered_flat_map<int, int> >( |
| 85 | v[i].begin(), v[i].end()); |
| 86 | |
| 87 | for (int i2 = 0; i2 < 5; ++i2) |
| 88 | test_equal_insertion<boost::unordered_node_map<int, int> >( |
| 89 | v[i2].begin(), v[i2].end()); |
| 90 | #else |
| 91 | for (int i = 0; i < 5; ++i) |
| 92 | test_equal_insertion<boost::unordered_map<int, int> >( |
| 93 | begin: v[i].begin(), end: v[i].end()); |
| 94 | |
| 95 | for (int i2 = 0; i2 < 5; ++i2) |
| 96 | test_equal_insertion<boost::unordered_multimap<int, int> >( |
| 97 | begin: v[i2].begin(), end: v[i2].end()); |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | RUN_TESTS() |
| 102 | |