Skip to content

Commit ddd9e24

Browse files
committed
coverage
1 parent 169bebd commit ddd9e24

File tree

1 file changed

+100
-0
lines changed
  • tests/std/tests/GH_000625_vector_bool_optimization

1 file changed

+100
-0
lines changed

tests/std/tests/GH_000625_vector_bool_optimization/test.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,104 @@ CONSTEXPR20 bool test_transform() {
190190
return true;
191191
}
192192

193+
CONSTEXPR20 bool test__meow_of_helper(const size_t length_before, const size_t length, const size_t length_after) {
194+
const size_t total_length = length_before + length + length_after;
195+
196+
vector<bool> zeros(total_length);
197+
vector<bool> ones(total_length);
198+
vector<bool> mix(total_length);
199+
fill(zeros.begin(), zeros.begin() + length_before, true);
200+
fill(zeros.end() - length_after, zeros.end(), true);
201+
fill(ones.begin() + length_before, ones.end() - length_after, true);
202+
fill(mix.begin(), mix.begin() + length_before, true);
203+
fill(mix.begin() + length_before + length / 2, mix.end() - length_after, true);
204+
205+
const auto first_0 = zeros.begin() + length_before;
206+
const auto last_0 = zeros.end() - length_after;
207+
const auto first_1 = ones.cbegin() + length_before;
208+
const auto last_1 = ones.cend() - length_after;
209+
const auto first_m = mix.cbegin() + length_before;
210+
const auto last_m = mix.cend() - length_after;
211+
212+
if (length == 0) {
213+
#if _HAS_CXX20
214+
assert(all_of(first_0, last_0, identity{}) == true);
215+
assert(all_of(first_1, last_1, identity{}) == true);
216+
assert(all_of(first_m, last_m, identity{}) == true);
217+
218+
assert(any_of(first_0, last_0, identity{}) == false);
219+
assert(any_of(first_1, last_1, identity{}) == false);
220+
assert(any_of(first_m, last_m, identity{}) == false);
221+
222+
assert(none_of(first_0, last_0, identity{}) == true);
223+
assert(none_of(first_1, last_1, identity{}) == true);
224+
assert(none_of(first_m, last_m, identity{}) == true);
225+
#endif // _HAS_CXX20
226+
227+
assert(all_of(first_0, last_0, logical_not<>{}) == true);
228+
assert(all_of(first_1, last_1, logical_not<>{}) == true);
229+
assert(all_of(first_m, last_m, logical_not<>{}) == true);
230+
231+
assert(any_of(first_0, last_0, logical_not<>{}) == false);
232+
assert(any_of(first_1, last_1, logical_not<>{}) == false);
233+
assert(any_of(first_m, last_m, logical_not<>{}) == false);
234+
235+
assert(none_of(first_0, last_0, logical_not<>{}) == true);
236+
assert(none_of(first_1, last_1, logical_not<>{}) == true);
237+
assert(none_of(first_m, last_m, logical_not<>{}) == true);
238+
} else {
239+
#if _HAS_CXX20
240+
assert(all_of(first_0, last_0, identity{}) == false);
241+
assert(all_of(first_1, last_1, identity{}) == true);
242+
assert(all_of(first_m, last_m, identity{}) == false);
243+
244+
assert(any_of(first_0, last_0, identity{}) == false);
245+
assert(any_of(first_1, last_1, identity{}) == true);
246+
assert(any_of(first_m, last_m, identity{}) == true);
247+
248+
assert(none_of(first_0, last_0, identity{}) == true);
249+
assert(none_of(first_1, last_1, identity{}) == false);
250+
assert(none_of(first_m, last_m, identity{}) == false);
251+
#endif // _HAS_CXX20
252+
253+
assert(all_of(first_0, last_0, logical_not<>{}) == true);
254+
assert(all_of(first_1, last_1, logical_not<>{}) == false);
255+
assert(all_of(first_m, last_m, logical_not<>{}) == false);
256+
257+
assert(any_of(first_0, last_0, logical_not<>{}) == true);
258+
assert(any_of(first_1, last_1, logical_not<>{}) == false);
259+
assert(any_of(first_m, last_m, logical_not<>{}) == true);
260+
261+
assert(none_of(first_0, last_0, logical_not<>{}) == false);
262+
assert(none_of(first_1, last_1, logical_not<>{}) == true);
263+
assert(none_of(first_m, last_m, logical_not<>{}) == false);
264+
}
265+
266+
return true;
267+
}
268+
269+
CONSTEXPR20 bool test_meow_of() {
270+
// Empty range
271+
test__meow_of_helper(0, 0, 3);
272+
test__meow_of_helper(3, 0, 3);
273+
274+
// One block, ends within block
275+
test__meow_of_helper(0, 10, 3);
276+
test__meow_of_helper(3, 10, 3);
277+
278+
// One block, exactly
279+
test__meow_of_helper(0, blockSize, 0);
280+
281+
// Multiple blocks, spanning
282+
test__meow_of_helper(3, blockSize - 2, 3);
283+
test__meow_of_helper(3, blockSize + 2, 3);
284+
285+
// Many blocks, exaclty
286+
test__meow_of_helper(blockSize, 4 * blockSize, blockSize);
287+
288+
return true;
289+
}
290+
193291
CONSTEXPR20 void test_fill_helper(const size_t length) {
194292
// No offset
195293
{
@@ -1531,6 +1629,7 @@ static_assert(test_fill());
15311629
static_assert(test_find());
15321630
static_assert(test_count());
15331631
static_assert(test_transform());
1632+
static_assert(test_meow_of());
15341633

15351634
#if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-2574489
15361635
static_assert(test_copy_part_1());
@@ -1543,6 +1642,7 @@ int main() {
15431642
test_find();
15441643
test_count();
15451644
test_transform();
1645+
test_meow_of();
15461646
test_copy_part_1();
15471647
test_copy_part_2();
15481648

0 commit comments

Comments
 (0)