• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 namespace ba = boost::algorithm;
25 
triangle(int n)26 int triangle(int n) { return n*(n+1)/2; }
27 
basic_tests_init()28 void basic_tests_init()
29 {
30     {
31     std::vector<int> v(10);
32     std::fill(v.begin(), v.end(), 3);
33     ba::exclusive_scan(v.begin(), v.end(), v.begin(), 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(v.begin(), v.end(), 0);
41     ba::exclusive_scan(v.begin(), v.end(), v.begin(), 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(v.begin(), v.end(), 1);
49     ba::exclusive_scan(v.begin(), v.end(), v.begin(), 40);
50     for (size_t i = 0; i < v.size(); ++i)
51         BOOST_CHECK(v[i] == 40 + triangle(i));
52     }
53 
54 }
55 
test_exclusive_scan_init()56 void test_exclusive_scan_init()
57 {
58 	basic_tests_init();
59 }
60 
test_exclusive_scan_init_op()61 void test_exclusive_scan_init_op()
62 {
63 	BOOST_CHECK(true);
64 }
65 
66 
67 
BOOST_AUTO_TEST_CASE(test_main)68 BOOST_AUTO_TEST_CASE( test_main )
69 {
70   test_exclusive_scan_init();
71   test_exclusive_scan_init_op();
72 }
73