• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #861

09 Jan 2023 03:50PM UTC coverage: 86.634% (+0.7%) from 85.965%
#861

push

StellarBot
Merge #6127

6127: Working around gccV9 problem that prevent us from storing enum classes in bit fields r=hkaiser a=hkaiser



Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

40 of 40 new or added lines in 8 files covered. (100.0%)

174879 of 201859 relevant lines covered (86.63%)

1846822.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.27
/libs/core/algorithms/tests/unit/algorithms/includes.cpp
1
//  Copyright (c) 2014-2020 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
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 <hpx/local/init.hpp>
8
#include <hpx/modules/testing.hpp>
9
#include <hpx/parallel/algorithms/includes.hpp>
10

11
#include <cstddef>
12
#include <iostream>
13
#include <iterator>
14
#include <numeric>
15
#include <random>
16
#include <string>
17
#include <vector>
18

19
#include "test_utils.hpp"
20

21
///////////////////////////////////////////////////////////////////////////////
22
int seed = std::random_device{}();
1✔
23
std::mt19937 gen(seed);
1✔
24

25
///////////////////////////////////////////////////////////////////////////////
26
template <typename IteratorTag>
27
void test_includes1(IteratorTag)
2✔
28
{
29
    typedef std::vector<std::size_t>::iterator base_iterator;
30
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
31

32
    std::vector<std::size_t> c1(10007);
2✔
33
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
2✔
34
    std::size_t start = dis(gen);
2✔
35
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
2✔
36
    std::size_t end = start + dist(gen);
2✔
37

38
    std::size_t first_value = gen();    //-V101
2✔
39
    std::iota(std::begin(c1), std::end(c1), first_value);
2✔
40

41
    HPX_TEST_LTE(start, end);
2✔
42

43
    base_iterator start_it = std::next(std::begin(c1), start);
2✔
44
    base_iterator end_it = std::next(std::begin(c1), end);
2✔
45

46
    {
47
        bool result = hpx::includes(
2✔
48
            iterator(std::begin(c1)), iterator(std::end(c1)), start_it, end_it);
2✔
49

50
        bool expected =
2✔
51
            std::includes(std::begin(c1), std::end(c1), start_it, end_it);
2✔
52

53
        // verify values
54
        HPX_TEST_EQ(result, expected);
2✔
55
    }
56

57
    {
58
        // make sure std::less is not violated by incrementing one of the
59
        // elements
60
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
2✔
61
            [](std::size_t val) { return 2 * val; });
20,014✔
62

63
        std::vector<std::size_t> c2;
2✔
64
        std::copy(start_it, end_it, std::back_inserter(c2));
2✔
65

66
        if (!c2.empty())
2✔
67
        {
68
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
2✔
69
            ++c2[dis(gen)];    //-V104
2✔
70

71
            bool result = hpx::includes(iterator(std::begin(c1)),
4✔
72
                iterator(std::end(c1)), std::begin(c2), std::end(c2));
2✔
73

74
            bool expected = std::includes(
2✔
75
                std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
2✔
76

77
            // verify values
78
            HPX_TEST_EQ(result, expected);
2✔
79
        }
2✔
80
    }
2✔
81
}
2✔
82

83
template <typename ExPolicy, typename IteratorTag>
84
void test_includes1(ExPolicy&& policy, IteratorTag)
6✔
85
{
86
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
87
        "hpx::is_execution_policy<ExPolicy>::value");
88

89
    typedef std::vector<std::size_t>::iterator base_iterator;
90
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
91

92
    std::vector<std::size_t> c1(10007);
6✔
93
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
6✔
94
    std::size_t start = dis(gen);
6✔
95
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
6✔
96
    std::size_t end = start + dist(gen);
6✔
97

98
    std::size_t first_value = gen();    //-V101
6✔
99
    std::iota(std::begin(c1), std::end(c1), first_value);
6✔
100

101
    HPX_TEST_LTE(start, end);
6✔
102

103
    base_iterator start_it = std::next(std::begin(c1), start);
6✔
104
    base_iterator end_it = std::next(std::begin(c1), end);
6✔
105

106
    {
107
        bool result = hpx::includes(policy, iterator(std::begin(c1)),
12✔
108
            iterator(std::end(c1)), start_it, end_it);
6✔
109

110
        bool expected =
6✔
111
            std::includes(std::begin(c1), std::end(c1), start_it, end_it);
6✔
112

113
        // verify values
114
        HPX_TEST_EQ(result, expected);
6✔
115
    }
116

117
    {
118
        // make sure std::less is not violated by incrementing one of the
119
        // elements
120
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
6✔
121
            [](std::size_t val) { return 2 * val; });
60,042✔
122

123
        std::vector<std::size_t> c2;
6✔
124
        std::copy(start_it, end_it, std::back_inserter(c2));
6✔
125

126
        if (!c2.empty())
6✔
127
        {
128
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
6✔
129
            ++c2[dis(gen)];    //-V104
6✔
130

131
            bool result = hpx::includes(policy, iterator(std::begin(c1)),
12✔
132
                iterator(std::end(c1)), std::begin(c2), std::end(c2));
6✔
133

134
            bool expected = std::includes(
6✔
135
                std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
6✔
136

137
            // verify values
138
            HPX_TEST_EQ(result, expected);
6✔
139
        }
6✔
140
    }
6✔
141
}
6✔
142

143
template <typename ExPolicy, typename IteratorTag>
144
void test_includes1_async(ExPolicy&& p, IteratorTag)
4✔
145
{
146
    typedef std::vector<std::size_t>::iterator base_iterator;
147
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
148

149
    std::vector<std::size_t> c1(10007);
4✔
150
    std::size_t first_value = gen();    //-V101
4✔
151
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
152
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
153
    std::size_t start = dis(gen);
4✔
154
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
155
    std::size_t end = start + dist(gen);
4✔
156

157
    HPX_TEST_LTE(start, end);
4✔
158

159
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
160
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
161

162
    {
163
        hpx::future<bool> result = hpx::includes(p, iterator(std::begin(c1)),
8✔
164
            iterator(std::end(c1)), start_it, end_it);
4✔
165
        result.wait();
4✔
166

167
        bool expected =
4✔
168
            std::includes(std::begin(c1), std::end(c1), start_it, end_it);
4✔
169

170
        // verify values
171
        HPX_TEST_EQ(result.get(), expected);
4✔
172
    }
4✔
173

174
    {
175
        // make sure std::less is not violated by incrementing one of the
176
        // elements
177
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
4✔
178
            [](std::size_t val) { return 2 * val; });
40,028✔
179

180
        std::vector<std::size_t> c2;
4✔
181
        std::copy(start_it, end_it, std::back_inserter(c2));
4✔
182

183
        if (!c2.empty())
4✔
184
        {
185
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
4✔
186
            ++c2[dis(gen)];    //-V104
4✔
187

188
            hpx::future<bool> result =
189
                hpx::includes(p, iterator(std::begin(c1)),
8✔
190
                    iterator(std::end(c1)), std::begin(c2), std::end(c2));
4✔
191
            result.wait();
4✔
192

193
            bool expected = std::includes(
4✔
194
                std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
4✔
195

196
            // verify values
197
            HPX_TEST_EQ(result.get(), expected);
4✔
198
        }
4✔
199
    }
4✔
200
}
4✔
201

202
template <typename IteratorTag>
203
void test_includes1()
2✔
204
{
205
    using namespace hpx::execution;
206

207
    test_includes1(IteratorTag());
2✔
208

209
    test_includes1(seq, IteratorTag());
2✔
210
    test_includes1(par, IteratorTag());
2✔
211
    test_includes1(par_unseq, IteratorTag());
2✔
212

213
    test_includes1_async(seq(task), IteratorTag());
2✔
214
    test_includes1_async(par(task), IteratorTag());
2✔
215
}
2✔
216

217
void includes_test1()
1✔
218
{
219
    test_includes1<std::random_access_iterator_tag>();
1✔
220
    test_includes1<std::forward_iterator_tag>();
1✔
221
}
1✔
222

223
///////////////////////////////////////////////////////////////////////////////
224
template <typename IteratorTag>
225
void test_includes2(IteratorTag)
2✔
226
{
227
    typedef std::vector<std::size_t>::iterator base_iterator;
228
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
229

230
    std::vector<std::size_t> c1(10007);
2✔
231
    std::size_t first_value = gen();    //-V101
2✔
232
    std::iota(std::begin(c1), std::end(c1), first_value);
2✔
233

234
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
2✔
235
    std::size_t start = dis(gen);
2✔
236
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
2✔
237
    std::size_t end = start + dist(gen);
2✔
238

239
    HPX_TEST_LTE(start, end);
2✔
240

241
    base_iterator start_it = std::next(std::begin(c1), start);
2✔
242
    base_iterator end_it = std::next(std::begin(c1), end);
2✔
243

244
    {
245
        bool result = hpx::includes(iterator(std::begin(c1)),
4✔
246
            iterator(std::end(c1)), start_it, end_it, std::less<std::size_t>());
2✔
247

248
        bool expected = std::includes(std::begin(c1), std::end(c1), start_it,
2✔
249
            end_it, std::less<std::size_t>());
2✔
250

251
        // verify values
252
        HPX_TEST_EQ(result, expected);
2✔
253
    }
254

255
    {
256
        // make sure std::less is not violated by incrementing one of the
257
        // elements
258
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
2✔
259
            [](std::size_t val) { return 2 * val; });
20,014✔
260

261
        std::vector<std::size_t> c2;
2✔
262
        std::copy(start_it, end_it, std::back_inserter(c2));
2✔
263

264
        if (!c2.empty())
2✔
265
        {
266
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
2✔
267
            ++c2[dis(gen)];    //-V104
2✔
268

269
            bool result =
2✔
270
                hpx::includes(iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
271
                    std::begin(c2), std::end(c2), std::less<std::size_t>());
2✔
272

273
            bool expected = std::includes(std::begin(c1), std::end(c1),
4✔
274
                std::begin(c2), std::end(c2), std::less<std::size_t>());
2✔
275

276
            // verify values
277
            HPX_TEST_EQ(result, expected);
2✔
278
        }
2✔
279
    }
2✔
280
}
2✔
281

282
template <typename ExPolicy, typename IteratorTag>
283
void test_includes2(ExPolicy&& policy, IteratorTag)
6✔
284
{
285
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
286
        "hpx::is_execution_policy<ExPolicy>::value");
287

288
    typedef std::vector<std::size_t>::iterator base_iterator;
289
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
290

291
    std::vector<std::size_t> c1(10007);
6✔
292
    std::size_t first_value = gen();    //-V101
6✔
293
    std::iota(std::begin(c1), std::end(c1), first_value);
6✔
294

295
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
6✔
296
    std::size_t start = dis(gen);
6✔
297
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
6✔
298
    std::size_t end = start + dist(gen);
6✔
299

300
    HPX_TEST_LTE(start, end);
6✔
301

302
    base_iterator start_it = std::next(std::begin(c1), start);
6✔
303
    base_iterator end_it = std::next(std::begin(c1), end);
6✔
304

305
    {
306
        bool result = hpx::includes(policy, iterator(std::begin(c1)),
12✔
307
            iterator(std::end(c1)), start_it, end_it, std::less<std::size_t>());
6✔
308

309
        bool expected = std::includes(std::begin(c1), std::end(c1), start_it,
6✔
310
            end_it, std::less<std::size_t>());
6✔
311

312
        // verify values
313
        HPX_TEST_EQ(result, expected);
6✔
314
    }
315

316
    {
317
        // make sure std::less is not violated by incrementing one of the
318
        // elements
319
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
6✔
320
            [](std::size_t val) { return 2 * val; });
60,042✔
321

322
        std::vector<std::size_t> c2;
6✔
323
        std::copy(start_it, end_it, std::back_inserter(c2));
6✔
324

325
        if (!c2.empty())
6✔
326
        {
327
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
6✔
328
            ++c2[dis(gen)];    //-V104
6✔
329

330
            bool result = hpx::includes(policy, iterator(std::begin(c1)),
12✔
331
                iterator(std::end(c1)), std::begin(c2), std::end(c2),
6✔
332
                std::less<std::size_t>());
333

334
            bool expected = std::includes(std::begin(c1), std::end(c1),
12✔
335
                std::begin(c2), std::end(c2), std::less<std::size_t>());
6✔
336

337
            // verify values
338
            HPX_TEST_EQ(result, expected);
6✔
339
        }
6✔
340
    }
6✔
341
}
6✔
342

343
template <typename ExPolicy, typename IteratorTag>
344
void test_includes2_async(ExPolicy&& p, IteratorTag)
4✔
345
{
346
    typedef std::vector<std::size_t>::iterator base_iterator;
347
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
348

349
    std::vector<std::size_t> c1(10007);
4✔
350
    std::size_t first_value = gen();    //-V101
4✔
351
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
352

353
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
354
    std::size_t start = dis(gen);
4✔
355
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
356
    std::size_t end = start + dist(gen);
4✔
357

358
    HPX_TEST_LTE(start, end);
4✔
359

360
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
361
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
362

363
    {
364
        hpx::future<bool> result = hpx::includes(p, iterator(std::begin(c1)),
8✔
365
            iterator(std::end(c1)), start_it, end_it, std::less<std::size_t>());
4✔
366
        result.wait();
4✔
367

368
        bool expected = std::includes(std::begin(c1), std::end(c1), start_it,
4✔
369
            end_it, std::less<std::size_t>());
4✔
370

371
        // verify values
372
        HPX_TEST_EQ(result.get(), expected);
4✔
373
    }
4✔
374

375
    {
376
        // make sure std::less is not violated by incrementing one of the
377
        // elements
378
        std::transform(std::begin(c1), std::end(c1), std::begin(c1),
4✔
379
            [](std::size_t val) { return 2 * val; });
40,028✔
380

381
        std::vector<std::size_t> c2;
4✔
382
        std::copy(start_it, end_it, std::back_inserter(c2));
4✔
383

384
        if (!c2.empty())
4✔
385
        {
386
            std::uniform_int_distribution<> dis(0, c2.size() - 1);
4✔
387
            ++c2[dis(gen)];    //-V104
4✔
388

389
            hpx::future<bool> result = hpx::includes(p,
8✔
390
                iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
391
                std::begin(c2), std::end(c2), std::less<std::size_t>());
4✔
392
            result.wait();
4✔
393

394
            bool expected = std::includes(std::begin(c1), std::end(c1),
8✔
395
                std::begin(c2), std::end(c2), std::less<std::size_t>());
4✔
396

397
            // verify values
398
            HPX_TEST_EQ(result.get(), expected);
4✔
399
        }
4✔
400
    }
4✔
401
}
4✔
402

403
template <typename IteratorTag>
404
void test_includes2()
2✔
405
{
406
    using namespace hpx::execution;
407

408
    test_includes2(IteratorTag());
2✔
409

410
    test_includes2(seq, IteratorTag());
2✔
411
    test_includes2(par, IteratorTag());
2✔
412
    test_includes2(par_unseq, IteratorTag());
2✔
413

414
    test_includes2_async(seq(task), IteratorTag());
2✔
415
    test_includes2_async(par(task), IteratorTag());
2✔
416
}
2✔
417

418
void includes_test2()
1✔
419
{
420
    test_includes2<std::random_access_iterator_tag>();
1✔
421
    test_includes2<std::forward_iterator_tag>();
1✔
422
}
1✔
423

424
///////////////////////////////////////////////////////////////////////////////
425
template <typename IteratorTag>
426
void test_includes_exception(IteratorTag)
2✔
427
{
428
    typedef std::vector<std::size_t>::iterator base_iterator;
429
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
430

431
    std::vector<std::size_t> c1(10007);
2✔
432
    std::size_t first_value = gen();    //-V101
2✔
433
    std::iota(std::begin(c1), std::end(c1), first_value);
2✔
434

435
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
2✔
436
    std::size_t start = dis(gen);
2✔
437
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
2✔
438
    std::size_t end = start + dist(gen);
2✔
439

440
    HPX_TEST_LTE(start, end);
2✔
441

442
    if (start == end)
2✔
443
        ++end;
×
444

445
    HPX_TEST_LTE(end, c1.size());
2✔
446

447
    base_iterator start_it = std::next(std::begin(c1), start);
2✔
448
    base_iterator end_it = std::next(std::begin(c1), end);
2✔
449

450
    bool caught_exception = false;
2✔
451
    try
452
    {
453
        hpx::includes(iterator(std::begin(c1)), iterator(std::end(c1)),
2✔
454
            start_it, end_it, [](std::size_t, std::size_t) {
2✔
455
                return throw std::runtime_error("test"), true;
2✔
456
            });
×
457

458
        HPX_TEST(false);
×
459
    }
2✔
460
    catch (hpx::exception_list const& e)
461
    {
462
        caught_exception = true;
2✔
463
        test::test_num_exceptions<hpx::execution::sequenced_policy,
2✔
464
            IteratorTag>::call(hpx::execution::seq, e);
2✔
465
    }
2✔
466
    catch (...)
467
    {
468
        HPX_TEST(false);
×
469
    }
2✔
470

471
    HPX_TEST(caught_exception);
2✔
472
}
4✔
473

474
template <typename ExPolicy, typename IteratorTag>
475
void test_includes_exception(ExPolicy&& policy, IteratorTag)
4✔
476
{
477
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
478
        "hpx::is_execution_policy<ExPolicy>::value");
479

480
    typedef std::vector<std::size_t>::iterator base_iterator;
481
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
482

483
    std::vector<std::size_t> c1(10007);
4✔
484
    std::size_t first_value = gen();    //-V101
4✔
485
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
486

487
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
488
    std::size_t start = dis(gen);
4✔
489
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
490
    std::size_t end = start + dist(gen);
4✔
491

492
    HPX_TEST_LTE(start, end);
4✔
493

494
    if (start == end)
4✔
495
        ++end;
×
496

497
    HPX_TEST_LTE(end, c1.size());
4✔
498

499
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
500
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
501

502
    bool caught_exception = false;
4✔
503
    try
504
    {
505
        hpx::includes(policy, iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
506
            start_it, end_it, [](std::size_t, std::size_t) {
31✔
507
                return throw std::runtime_error("test"), true;
31✔
508
            });
×
509

510
        HPX_TEST(false);
×
511
    }
4✔
512
    catch (hpx::exception_list const& e)
513
    {
514
        caught_exception = true;
4✔
515
        test::test_num_exceptions<ExPolicy, IteratorTag>::call(policy, e);
4✔
516
    }
4✔
517
    catch (...)
518
    {
519
        HPX_TEST(false);
×
520
    }
4✔
521

522
    HPX_TEST(caught_exception);
4✔
523
}
8✔
524

525
template <typename ExPolicy, typename IteratorTag>
526
void test_includes_exception_async(ExPolicy&& p, IteratorTag)
4✔
527
{
528
    typedef std::vector<std::size_t>::iterator base_iterator;
529
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
530

531
    std::vector<std::size_t> c1(10007);
4✔
532
    std::size_t first_value = gen();    //-V101
4✔
533
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
534

535
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
536
    std::size_t start = dis(gen);
4✔
537
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
538
    std::size_t end = start + dist(gen);
4✔
539

540
    HPX_TEST_LTE(start, end);
4✔
541

542
    if (start == end)
4✔
543
        ++end;
×
544

545
    HPX_TEST_LTE(end, c1.size());
4✔
546

547
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
548
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
549

550
    bool caught_exception = false;
4✔
551
    bool returned_from_algorithm = false;
4✔
552
    try
553
    {
554
        hpx::future<bool> f =
555
            hpx::includes(p, iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
556
                start_it, end_it, [](std::size_t, std::size_t) {
23✔
557
                    return throw std::runtime_error("test"), true;
23✔
558
                });
×
559
        returned_from_algorithm = true;
4✔
560
        f.get();
4✔
561

562
        HPX_TEST(false);
×
563
    }
4✔
564
    catch (hpx::exception_list const& e)
565
    {
566
        caught_exception = true;
4✔
567
        test::test_num_exceptions<ExPolicy, IteratorTag>::call(p, e);
4✔
568
    }
4✔
569
    catch (...)
570
    {
571
        HPX_TEST(false);
×
572
    }
4✔
573

574
    HPX_TEST(caught_exception);
4✔
575
    HPX_TEST(returned_from_algorithm);
4✔
576
}
8✔
577

578
template <typename IteratorTag>
579
void test_includes_exception()
2✔
580
{
581
    using namespace hpx::execution;
582

583
    test_includes_exception(IteratorTag());
2✔
584

585
    // If the execution policy object is of type vector_execution_policy,
586
    // std::terminate shall be called. therefore we do not test exceptions
587
    // with a vector execution policy
588
    test_includes_exception(seq, IteratorTag());
2✔
589
    test_includes_exception(par, IteratorTag());
2✔
590

591
    test_includes_exception_async(seq(task), IteratorTag());
2✔
592
    test_includes_exception_async(par(task), IteratorTag());
2✔
593
}
2✔
594

595
void includes_exception_test()
1✔
596
{
597
    test_includes_exception<std::random_access_iterator_tag>();
1✔
598
    test_includes_exception<std::forward_iterator_tag>();
1✔
599
}
1✔
600

601
///////////////////////////////////////////////////////////////////////////////
602
template <typename IteratorTag>
603
void test_includes_bad_alloc(IteratorTag)
2✔
604
{
605
    typedef std::vector<std::size_t>::iterator base_iterator;
606
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
607

608
    std::vector<std::size_t> c1(10007);
2✔
609
    std::size_t first_value = gen();    //-V101
2✔
610
    std::iota(std::begin(c1), std::end(c1), first_value);
2✔
611

612
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
2✔
613
    std::size_t start = dis(gen);
2✔
614
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
2✔
615
    std::size_t end = start + dist(gen);
2✔
616

617
    HPX_TEST_LTE(start, end);
2✔
618

619
    if (start == end)
2✔
620
        ++end;
×
621

622
    HPX_TEST_LTE(end, c1.size());
2✔
623

624
    base_iterator start_it = std::next(std::begin(c1), start);
2✔
625
    base_iterator end_it = std::next(std::begin(c1), end);
2✔
626

627
    bool caught_bad_alloc = false;
2✔
628
    try
629
    {
630
        hpx::includes(iterator(std::begin(c1)), iterator(std::end(c1)),
2✔
631
            start_it, end_it, [](std::size_t, std::size_t) {
2✔
632
                return throw std::bad_alloc(), true;
2✔
633
            });
634

635
        HPX_TEST(false);
×
636
    }
2✔
637
    catch (std::bad_alloc const&)
638
    {
639
        caught_bad_alloc = true;
2✔
640
    }
2✔
641
    catch (...)
642
    {
643
        HPX_TEST(false);
×
644
    }
2✔
645

646
    HPX_TEST(caught_bad_alloc);
2✔
647
}
4✔
648

649
template <typename ExPolicy, typename IteratorTag>
650
void test_includes_bad_alloc(ExPolicy&& policy, IteratorTag)
4✔
651
{
652
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
653
        "hpx::is_execution_policy<ExPolicy>::value");
654

655
    typedef std::vector<std::size_t>::iterator base_iterator;
656
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
657

658
    std::vector<std::size_t> c1(10007);
4✔
659
    std::size_t first_value = gen();    //-V101
4✔
660
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
661

662
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
663
    std::size_t start = dis(gen);
4✔
664
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
665
    std::size_t end = start + dist(gen);
4✔
666

667
    HPX_TEST_LTE(start, end);
4✔
668

669
    if (start == end)
4✔
670
        ++end;
×
671

672
    HPX_TEST_LTE(end, c1.size());
4✔
673

674
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
675
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
676

677
    bool caught_bad_alloc = false;
4✔
678
    try
679
    {
680
        hpx::includes(policy, iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
681
            start_it, end_it, [](std::size_t, std::size_t) {
23✔
682
                return throw std::bad_alloc(), true;
23✔
683
            });
684

685
        HPX_TEST(false);
×
686
    }
4✔
687
    catch (std::bad_alloc const&)
688
    {
689
        caught_bad_alloc = true;
4✔
690
    }
4✔
691
    catch (...)
692
    {
693
        HPX_TEST(false);
×
694
    }
4✔
695

696
    HPX_TEST(caught_bad_alloc);
4✔
697
}
8✔
698

699
template <typename ExPolicy, typename IteratorTag>
700
void test_includes_bad_alloc_async(ExPolicy&& p, IteratorTag)
4✔
701
{
702
    typedef std::vector<std::size_t>::iterator base_iterator;
703
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;
704

705
    std::vector<std::size_t> c1(10007);
4✔
706
    std::size_t first_value = gen();    //-V101
4✔
707
    std::iota(std::begin(c1), std::end(c1), first_value);
4✔
708

709
    std::uniform_int_distribution<> dis(0, c1.size() - 1);
4✔
710
    std::size_t start = dis(gen);
4✔
711
    std::uniform_int_distribution<> dist(0, c1.size() - start - 1);
4✔
712
    std::size_t end = start + dist(gen);
4✔
713

714
    HPX_TEST_LTE(start, end);
4✔
715

716
    if (start == end)
4✔
717
        ++end;
×
718

719
    HPX_TEST_LTE(end, c1.size());
4✔
720

721
    base_iterator start_it = std::next(std::begin(c1), start);
4✔
722
    base_iterator end_it = std::next(std::begin(c1), end);
4✔
723

724
    bool caught_bad_alloc = false;
4✔
725
    bool returned_from_algorithm = false;
4✔
726
    try
727
    {
728
        hpx::future<bool> f =
729
            hpx::includes(p, iterator(std::begin(c1)), iterator(std::end(c1)),
4✔
730
                start_it, end_it, [](std::size_t, std::size_t) {
24✔
731
                    return throw std::bad_alloc(), true;
24✔
732
                });
733
        returned_from_algorithm = true;
4✔
734
        f.get();
4✔
735

736
        HPX_TEST(false);
×
737
    }
4✔
738
    catch (std::bad_alloc const&)
739
    {
740
        caught_bad_alloc = true;
4✔
741
    }
4✔
742
    catch (...)
743
    {
744
        HPX_TEST(false);
×
745
    }
4✔
746

747
    HPX_TEST(caught_bad_alloc);
4✔
748
    HPX_TEST(returned_from_algorithm);
4✔
749
}
8✔
750

751
template <typename IteratorTag>
752
void test_includes_bad_alloc()
2✔
753
{
754
    using namespace hpx::execution;
755

756
    test_includes_bad_alloc(IteratorTag());
2✔
757

758
    // If the execution policy object is of type vector_execution_policy,
759
    // std::terminate shall be called. therefore we do not test exceptions
760
    // with a vector execution policy
761
    test_includes_bad_alloc(seq, IteratorTag());
2✔
762
    test_includes_bad_alloc(par, IteratorTag());
2✔
763

764
    test_includes_bad_alloc_async(seq(task), IteratorTag());
2✔
765
    test_includes_bad_alloc_async(par(task), IteratorTag());
2✔
766
}
2✔
767

768
void includes_bad_alloc_test()
1✔
769
{
770
    test_includes_bad_alloc<std::random_access_iterator_tag>();
1✔
771
    test_includes_bad_alloc<std::forward_iterator_tag>();
1✔
772
}
1✔
773

774
///////////////////////////////////////////////////////////////////////////////
775
int hpx_main(hpx::program_options::variables_map& vm)
1✔
776
{
777
    if (vm.count("seed"))
1✔
778
    {
779
        seed = vm["seed"].as<unsigned int>();
×
780
        gen.seed(seed);
×
781
    }
×
782
    std::cout << "using seed: " << seed << std::endl;
1✔
783

784
    includes_test1();
1✔
785
    includes_test2();
1✔
786
    includes_exception_test();
1✔
787
    includes_bad_alloc_test();
1✔
788
    return hpx::local::finalize();
1✔
789
}
×
790

791
int main(int argc, char* argv[])
1✔
792
{
793
    // add command line option which controls the random number generator seed
794
    using namespace hpx::program_options;
795
    options_description desc_commandline(
1✔
796
        "Usage: " HPX_APPLICATION_STRING " [options]");
1✔
797

798
    desc_commandline.add_options()("seed,s", value<unsigned int>(),
1✔
799
        "the random number generator seed to use for this run");
800

801
    // By default this test should run on all available cores
802
    std::vector<std::string> const cfg = {"hpx.os_threads=all"};
1✔
803

804
    // Initialize and run HPX
805
    hpx::local::init_params init_args;
1✔
806
    init_args.desc_cmdline = desc_commandline;
1✔
807
    init_args.cfg = cfg;
1✔
808

809
    HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv, init_args), 0,
1✔
810
        "HPX main exited with non-zero status");
811

812
    return hpx::util::report_errors();
1✔
813
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc