forked from boostorg/unordered
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_tests.cpp
More file actions
162 lines (131 loc) · 3.36 KB
/
simple_tests.cpp
File metadata and controls
162 lines (131 loc) · 3.36 KB
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
// Copyright 2006-2009 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)
// This test checks the runtime requirements of containers.
#include "../helpers/unordered.hpp"
#include "../helpers/equivalent.hpp"
#include "../helpers/generators.hpp"
#include "../helpers/test.hpp"
#include <algorithm>
#include <cstdlib>
test::seed_t initialize_seed(14878);
template <class X> void simple_test(X const& a)
{
test::unordered_equivalence_tester<X> equivalent(a);
{
X u;
BOOST_TEST(u.size() == 0);
BOOST_TEST(X().size() == 0);
}
{
BOOST_TEST(equivalent(X(a)));
}
{
X u(a);
BOOST_TEST(equivalent(u));
}
{
X u = a;
BOOST_TEST(equivalent(u));
}
{
X b(a);
BOOST_TEST(b.begin() == const_cast<X const&>(b).cbegin());
BOOST_TEST(b.end() == const_cast<X const&>(b).cend());
}
{
X b(a);
X c;
BOOST_TEST(equivalent(b));
BOOST_TEST(c.empty());
b.swap(c);
BOOST_TEST(b.empty());
BOOST_TEST(equivalent(c));
b.swap(c);
BOOST_TEST(c.empty());
BOOST_TEST(equivalent(b));
}
{
X u;
X& r = u;
BOOST_TEST(&(r = r) == &r);
BOOST_TEST(r.empty());
BOOST_TEST(&(r = a) == &r);
BOOST_TEST(equivalent(r));
BOOST_TEST(&(r = r) == &r);
BOOST_TEST(equivalent(r));
}
{
BOOST_TEST(a.size() == static_cast<typename X::size_type>(
std::distance(a.begin(), a.end())));
}
{
BOOST_TEST(a.empty() == (a.size() == 0));
}
{
BOOST_TEST(a.empty() == (a.begin() == a.end()));
X u;
BOOST_TEST(u.begin() == u.end());
}
}
template <class X> static void simple_set_tests(X*)
{
X x;
simple_test(x);
x.insert(1);
x.insert(2);
x.insert(1456);
simple_test(x);
}
#ifndef BOOST_UNORDERED_FOA_TESTS
template <class X> static void simple_multiset_tests(X*)
{
X x;
simple_test(x);
for (int i1 = 0; i1 < 1000; ++i1) {
int count = rand() % 10, index = rand();
for (int j = 0; j < count; ++j)
x.insert(index);
}
simple_test(x);
}
#endif
template <class X> static void simple_map_tests(X*)
{
X x;
for (int i2 = 0; i2 < 1000; ++i2) {
x.insert(std::pair<const int, int>(rand(), rand()));
}
simple_test(x);
}
#ifndef BOOST_UNORDERED_FOA_TESTS
template <class X> static void simple_multimap_tests(X*)
{
X x;
for (int i3 = 0; i3 < 1000; ++i3) {
int count = rand() % 10, index = rand();
for (int j = 0; j < count; ++j)
x.insert(std::pair<const int, int>(index, rand()));
}
simple_test(x);
}
#endif
#ifdef BOOST_UNORDERED_FOA_TESTS
static boost::unordered_flat_set<int>* flat_set;
static boost::unordered_flat_map<int, int>* flat_map;
static boost::unordered_node_set<int>* node_set;
static boost::unordered_node_map<int, int>* node_map;
UNORDERED_TEST(simple_map_tests, ((flat_map)(node_map)))
UNORDERED_TEST(simple_set_tests, ((flat_set)(node_set)))
#else
static boost::unordered_set<int>* set;
static boost::unordered_map<int, int>* map;
static boost::unordered_multiset<int>* multiset;
static boost::unordered_multimap<int, int>* multimap;
UNORDERED_TEST(simple_set_tests, ((set)))
UNORDERED_TEST(simple_map_tests, ((map)))
UNORDERED_TEST(simple_multiset_tests, ((multiset)))
UNORDERED_TEST(simple_multimap_tests, ((multimap)))
#endif
RUN_TESTS()