1/*
2 Copyright (c) Marshall Clow 2017.
3
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 For more information, see http://www.boost.org
8*/
9
10#include <vector>
11#include <functional>
12#include <numeric>
13#include <algorithm>
14
15#include <boost/config.hpp>
16#include <boost/algorithm/cxx11/iota.hpp>
17#include <boost/algorithm/cxx17/exclusive_scan.hpp>
18
19#include "iterator_test.hpp"
20
21#define BOOST_TEST_MAIN
22#include <boost/test/unit_test.hpp>
23
24namespace ba = boost::algorithm;
25
26int triangle(int n) { return n*(n+1)/2; }
27
28void basic_tests_init()
29{
30 {
31 std::vector<int> v(10);
32 std::fill(first: v.begin(), last: v.end(), value: 3);
33 ba::exclusive_scan(first: v.begin(), last: v.end(), result: v.begin(), init: 50);
34 for (size_t i = 0; i < v.size(); ++i)
35 BOOST_CHECK(v[i] == 50 + (int) i * 3);
36 }
37
38 {
39 std::vector<int> v(10);
40 ba::iota(first: v.begin(), last: v.end(), value: 0);
41 ba::exclusive_scan(first: v.begin(), last: v.end(), result: v.begin(), init: 30);
42 for (size_t i = 0; i < v.size(); ++i)
43 BOOST_CHECK(v[i] == 30 + triangle(i-1));
44 }
45
46 {
47 std::vector<int> v(10);
48 ba::iota(first: v.begin(), last: v.end(), value: 1);
49 ba::exclusive_scan(first: v.begin(), last: v.end(), result: v.begin(), init: 40);
50 for (size_t i = 0; i < v.size(); ++i)
51 BOOST_CHECK(v[i] == 40 + triangle(i));
52 }
53
54}
55
56void test_exclusive_scan_init()
57{
58 basic_tests_init();
59}
60
61void test_exclusive_scan_init_op()
62{
63 BOOST_CHECK(true);
64}
65
66
67
68BOOST_AUTO_TEST_CASE( test_main )
69{
70 test_exclusive_scan_init();
71 test_exclusive_scan_init_op();
72}
73

source code of boost/libs/algorithm/test/exclusive_scan_test.cpp