File: merge_exception_tests.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (193 lines) | stat: -rw-r--r-- 6,556 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

// Copyright 2017-2018 Daniel James.
// Copyright 2022-2023 Christian Mazakas.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include "../helpers/exception_test.hpp"
#include "../helpers/invariants.hpp"
#include "../helpers/metafunctions.hpp"
#include "../helpers/random_values.hpp"
#include "./containers.hpp"

template <typename T1, typename T2> void merge_exception_test(T1 x, T2 y)
{
  std::size_t size = x.size() + y.size();

  try {
    ENABLE_EXCEPTIONS;
    x.merge(y);
  } catch (...) {
    test::check_equivalent_keys(x);
    test::check_equivalent_keys(y);
    throw;
  }

  // Not a full check, just want to make sure the merge completed.
  BOOST_TEST(size == x.size() + y.size());
  if (y.size()) {
    BOOST_TEST(test::has_unique_keys<T1>::value);
    for (typename T2::iterator it = y.begin(); it != y.end(); ++it) {
      BOOST_TEST(x.find(test::get_key<T2>(*it)) != x.end());
    }
  }
  test::check_equivalent_keys(x);
  test::check_equivalent_keys(y);
}

template <typename T1, typename T2>
void merge_exception_test(T1 const*, T2 const*, std::size_t count12, int tag12,
  test::random_generator gen1, test::random_generator gen2)
{
  std::size_t count1 = count12 / 256;
  std::size_t count2 = count12 % 256;
  int tag1 = tag12 / 256;
  int tag2 = tag12 % 256;
  test::random_values<T1> v1(count1, gen1);
  test::random_values<T2> v2(count2, gen2);
  T1 x(v1.begin(), v1.end(), 0, test::exception::hash(tag1),
    test::exception::equal_to(tag1));
  T2 y(v2.begin(), v2.end(), 0, test::exception::hash(tag2),
    test::exception::equal_to(tag2));

  EXCEPTION_LOOP(merge_exception_test(x, y))
}

using test::default_generator;
using test::generate_collisions;
using test::limited_range;

#ifdef BOOST_UNORDERED_FOA_TESTS
boost::unordered_flat_set<test::exception::object, test::exception::hash,
  test::exception::equal_to,
  test::exception::allocator<test::exception::object> >* test_set_;
boost::unordered_flat_map<test::exception::object, test::exception::object,
  test::exception::hash, test::exception::equal_to,
  test::exception::allocator2<test::exception::object> >* test_map_;
boost::unordered_node_set<test::exception::object, test::exception::hash,
  test::exception::equal_to,
  test::exception::allocator<test::exception::object> >* test_node_set_;
boost::unordered_node_map<test::exception::object, test::exception::object,
  test::exception::hash, test::exception::equal_to,
  test::exception::allocator2<test::exception::object> >* test_node_map_;

// clang-format off
UNORDERED_MULTI_TEST(set_merge, merge_exception_test,
    ((test_set_))
    ((test_set_))
    ((0x0000)(0x6400)(0x0064)(0x0a64)(0x3232))
    ((0x0000)(0x0001)(0x0102))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
UNORDERED_MULTI_TEST(map_merge, merge_exception_test,
    ((test_map_))
    ((test_map_))
    ((0x0000)(0x6400)(0x0064)(0x0a64)(0x3232))
    ((0x0101)(0x0200)(0x0201))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
// Run fewer generate_collisions tests, as they're slow.
UNORDERED_MULTI_TEST(set_merge_collisions, merge_exception_test,
    ((test_set_))
    ((test_set_))
    ((0x0a0a))
    ((0x0202)(0x0100)(0x0201))
    ((generate_collisions))
    ((generate_collisions))
)
UNORDERED_MULTI_TEST(map_merge_collisions, merge_exception_test,
    ((test_map_))
    ((test_map_))
    ((0x0a0a))
    ((0x0000)(0x0002)(0x0102))
    ((generate_collisions))
    ((generate_collisions))
)
UNORDERED_MULTI_TEST(node_set_merge, merge_exception_test,
    ((test_node_set_))
    ((test_node_set_))
    (/* (0x0000)(0x6400) */(0x0064)/* (0x0a64)(0x3232) */)
    ((0x0000)(0x0001)(0x0102))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
UNORDERED_MULTI_TEST(node_map_merge, merge_exception_test,
    ((test_node_map_))
    ((test_node_map_))
    ((0x0000)(0x6400)(0x0064)(0x0a64)(0x3232))
    ((0x0101)(0x0200)(0x0201))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
// Run fewer generate_collisions tests, as they're slow.
UNORDERED_MULTI_TEST(node_set_merge_collisions, merge_exception_test,
    ((test_node_set_))
    ((test_node_set_))
    ((0x0a0a))
    ((0x0202)(0x0100)(0x0201))
    ((generate_collisions))
    ((generate_collisions))
)
UNORDERED_MULTI_TEST(node_map_merge_collisions, merge_exception_test,
    ((test_node_map_))
    ((test_node_map_))
    ((0x0a0a))
    ((0x0000)(0x0002)(0x0102))
    ((generate_collisions))
    ((generate_collisions))
)
// clang-format on
#else
boost::unordered_set<test::exception::object, test::exception::hash,
  test::exception::equal_to,
  test::exception::allocator<test::exception::object> >* test_set_;
boost::unordered_multiset<test::exception::object, test::exception::hash,
  test::exception::equal_to,
  test::exception::allocator<test::exception::object> >* test_multiset_;
boost::unordered_map<test::exception::object, test::exception::object,
  test::exception::hash, test::exception::equal_to,
  test::exception::allocator2<test::exception::object> >* test_map_;
boost::unordered_multimap<test::exception::object, test::exception::object,
  test::exception::hash, test::exception::equal_to,
  test::exception::allocator2<test::exception::object> >* test_multimap_;

// clang-format off
UNORDERED_MULTI_TEST(set_merge, merge_exception_test,
    ((test_set_)(test_multiset_))
    ((test_set_)(test_multiset_))
    ((0x0000)(0x6400)(0x0064)(0x0a64)(0x3232))
    ((0x0000)(0x0001)(0x0102))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
UNORDERED_MULTI_TEST(map_merge, merge_exception_test,
    ((test_map_)(test_multimap_))
    ((test_map_)(test_multimap_))
    ((0x0000)(0x6400)(0x0064)(0x0a64)(0x3232))
    ((0x0101)(0x0200)(0x0201))
    ((default_generator)(limited_range))
    ((default_generator)(limited_range))
)
// Run fewer generate_collisions tests, as they're slow.
UNORDERED_MULTI_TEST(set_merge_collisions, merge_exception_test,
    ((test_set_)(test_multiset_))
    ((test_set_)(test_multiset_))
    ((0x0a0a))
    ((0x0202)(0x0100)(0x0201))
    ((generate_collisions))
    ((generate_collisions))
)
UNORDERED_MULTI_TEST(map_merge_collisions, merge_exception_test,
    ((test_map_)(test_multimap_))
    ((test_map_)(test_multimap_))
    ((0x0a0a))
    ((0x0000)(0x0002)(0x0102))
    ((generate_collisions))
    ((generate_collisions))
)
// clang-format on
#endif

RUN_TESTS_QUIET()