mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-29 12:07:18 +02:00
Implement the C++17 new algorithms
This commit is contained in:
71
test/exclusive_scan_test.cpp
Normal file
71
test/exclusive_scan_test.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/cxx17/exclusive_scan.hpp>
|
||||
|
||||
#include "iterator_test.hpp"
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
int triangle(int n) { return n*(n+1)/2; }
|
||||
|
||||
void basic_tests_init()
|
||||
{
|
||||
{
|
||||
std::vector<int> v(10);
|
||||
std::fill(v.begin(), v.end(), 3);
|
||||
ba::exclusive_scan(v.begin(), v.end(), v.begin(), 50);
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
BOOST_CHECK(v[i] == 50 + (int) i * 3);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<int> v(10);
|
||||
std::iota(v.begin(), v.end(), 0);
|
||||
ba::exclusive_scan(v.begin(), v.end(), v.begin(), 30);
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
BOOST_CHECK(v[i] == 30 + triangle(i-1));
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<int> v(10);
|
||||
std::iota(v.begin(), v.end(), 1);
|
||||
ba::exclusive_scan(v.begin(), v.end(), v.begin(), 40);
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
BOOST_CHECK(v[i] == 40 + triangle(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_exclusive_scan_init()
|
||||
{
|
||||
basic_tests_init();
|
||||
}
|
||||
|
||||
void test_exclusive_scan_init_op()
|
||||
{
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
test_exclusive_scan_init();
|
||||
test_exclusive_scan_init_op();
|
||||
}
|
Reference in New Issue
Block a user