/
small_bit_vector.allocator.cpp
231 lines (211 loc) · 9.32 KB
/
small_bit_vector.allocator.cpp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// itsy.bitsy
//
// Copyright ⓒ 2019-present ThePhD.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See https://github.com/ThePhD/itsy_bitsy#using-the-library for documentation.
#include <itsy/tests/tracking_allocator.hpp>
#include <itsy/tests/constants.hpp>
#include <itsy/tests/shared_allocator_tests.hpp>
#include <catch2/catch.hpp>
#include <itsy/bitsy.hpp>
#include <cstddef>
#include <cstdint>
TEMPLATE_TEST_CASE("small_bit_vector allocator", "[small_bit_vector<T>][allocator]", std::uint64_t,
std::uint32_t, std::uint16_t, std::uint8_t, std::byte, std::int64_t, std::int32_t,
std::int16_t, std::int8_t, char32_t, char16_t, char, unsigned char, signed char,
std::ptrdiff_t, std::size_t)
{
using sbv_allocator = bitsy::tests::tracking_allocator<std::allocator<TestType>>;
using sbv_allocator_ref = std::reference_wrapper<sbv_allocator>;
using tracking_sbv = bitsy::small_bit_vector<TestType, 2, sbv_allocator_ref>;
SECTION("normal")
{
SECTION("empty")
{
sbv_allocator empty_bit_vec_allocator;
{
const auto& expected = bitsy::tests::il_empty();
tracking_sbv bit_vec(empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(empty_bit_vec_allocator);
}
SECTION("initializer_list")
{
sbv_allocator il_empty_bit_vec_allocator;
{
std::initializer_list<bitsy::bit_value> expected{};
tracking_sbv bit_vec({}, il_empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(il_empty_bit_vec_allocator);
sbv_allocator il_arg_empty_bit_vec_allocator;
{
const auto& expected = bitsy::tests::il_empty();
tracking_sbv bit_vec(expected, il_arg_empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(il_arg_empty_bit_vec_allocator);
sbv_allocator il_in_sbo_bit_vec_allocator;
{
std::initializer_list<bitsy::bit_value> expected{ true, false, true, false };
tracking_sbv bit_vec({ true, false, true, false }, il_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(il_in_sbo_bit_vec_allocator);
sbv_allocator il_arg_in_sbo_bit_vec_allocator;
{
std::initializer_list<bitsy::bit_value> expected{ true, false, true, false };
tracking_sbv bit_vec(expected, il_arg_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(il_arg_in_sbo_bit_vec_allocator);
sbv_allocator il_arg_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::il_large();
tracking_sbv bit_vec(expected, il_arg_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(il_arg_on_heap_bit_vec_allocator);
}
SECTION("first, last")
{
sbv_allocator fl_empty_bit_vec_allocator;
{
const auto& expected = bitsy::tests::il_empty();
tracking_sbv bit_vec(
std::begin(expected), std::begin(expected), fl_empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_empty_bit_vec_allocator);
sbv_allocator fl_in_sbo_bit_vec_allocator;
{
const auto& expected = bitsy::tests::source_small();
tracking_sbv bit_vec(
std::cbegin(expected), std::cend(expected), fl_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_in_sbo_bit_vec_allocator);
sbv_allocator fl_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::source_large();
tracking_sbv bit_vec(
std::cbegin(expected), std::cend(expected), fl_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_on_heap_bit_vec_allocator);
sbv_allocator fl_bidi_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::list_large();
tracking_sbv bit_vec(std::begin(expected), std::end(expected),
fl_bidi_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_bidi_on_heap_bit_vec_allocator);
}
SECTION("count, value")
{
sbv_allocator cv_in_sbo_bit_vec_allocator;
{
const auto& expected = bitsy::tests::source_small_all_1();
tracking_sbv bit_vec(std::size(expected), true, cv_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(cv_in_sbo_bit_vec_allocator);
sbv_allocator cv_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::source_large_all_1();
tracking_sbv bit_vec(std::size(expected), true, cv_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(cv_on_heap_bit_vec_allocator);
sbv_allocator cv_bidi_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::list_large_all_1();
tracking_sbv bit_vec(
std::size(expected), true, cv_bidi_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(cv_bidi_on_heap_bit_vec_allocator);
}
}
SECTION("in_place")
{
SECTION("empty")
{
sbv_allocator empty_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_il_empty<TestType>();
tracking_sbv bit_vec(std::in_place, empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(empty_bit_vec_allocator);
}
SECTION("first, last")
{
sbv_allocator fl_inplace_empty_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_il_empty<TestType>();
tracking_sbv bit_vec(std::in_place, std::cbegin(expected), std::cend(expected),
fl_inplace_empty_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_inplace_empty_bit_vec_allocator);
sbv_allocator fl_inplace_in_sbo_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_il_small_all_1<TestType>();
tracking_sbv bit_vec(std::in_place, std::begin(expected), std::end(expected),
fl_inplace_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_inplace_in_sbo_bit_vec_allocator);
sbv_allocator fl_inplace_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_il_large<TestType>();
tracking_sbv bit_vec(std::in_place, std::begin(expected), std::end(expected),
fl_inplace_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_inplace_on_heap_bit_vec_allocator);
sbv_allocator fl_inplace_bidi_in_sbo_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_list_small_all_1<TestType>();
tracking_sbv bit_vec(std::in_place, std::begin(expected), std::end(expected),
fl_inplace_bidi_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_inplace_bidi_in_sbo_bit_vec_allocator);
sbv_allocator fl_inplace_bidi_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_list_large_all_0<TestType>();
tracking_sbv bit_vec(std::in_place, std::begin(expected), std::end(expected),
fl_inplace_bidi_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(fl_inplace_bidi_on_heap_bit_vec_allocator);
}
SECTION("count, value")
{
sbv_allocator cv_inplace_in_sbo_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_il_small_all_1<TestType>();
tracking_sbv bit_vec(std::in_place, std::size(expected), *expected.begin(),
cv_inplace_in_sbo_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(cv_inplace_in_sbo_bit_vec_allocator);
sbv_allocator cv_inplace_on_heap_bit_vec_allocator;
{
const auto& expected = bitsy::tests::inplace_list_large_all_0<TestType>();
tracking_sbv bit_vec(std::in_place, std::size(expected), *expected.begin(),
cv_inplace_on_heap_bit_vec_allocator);
bitsy::tests::allocator_test<TestType, sbv_allocator>(bit_vec, expected);
}
bitsy::tests::balanced_allocator_test(cv_inplace_on_heap_bit_vec_allocator);
}
}
}