exclusive_scan_test.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright (c) Marshall Clow 2017.
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. For more information, see http://www.boost.org
  6. */
  7. #include <vector>
  8. #include <functional>
  9. #include <numeric>
  10. #include <algorithm>
  11. #include <boost/config.hpp>
  12. #include <boost/algorithm/cxx11/iota.hpp>
  13. #include <boost/algorithm/cxx17/exclusive_scan.hpp>
  14. #include "iterator_test.hpp"
  15. #define BOOST_TEST_MAIN
  16. #include <boost/test/unit_test.hpp>
  17. namespace ba = boost::algorithm;
  18. int triangle(int n) { return n*(n+1)/2; }
  19. void basic_tests_init()
  20. {
  21. {
  22. std::vector<int> v(10);
  23. std::fill(v.begin(), v.end(), 3);
  24. ba::exclusive_scan(v.begin(), v.end(), v.begin(), 50);
  25. for (size_t i = 0; i < v.size(); ++i)
  26. BOOST_CHECK(v[i] == 50 + (int) i * 3);
  27. }
  28. {
  29. std::vector<int> v(10);
  30. ba::iota(v.begin(), v.end(), 0);
  31. ba::exclusive_scan(v.begin(), v.end(), v.begin(), 30);
  32. for (size_t i = 0; i < v.size(); ++i)
  33. BOOST_CHECK(v[i] == 30 + triangle(i-1));
  34. }
  35. {
  36. std::vector<int> v(10);
  37. ba::iota(v.begin(), v.end(), 1);
  38. ba::exclusive_scan(v.begin(), v.end(), v.begin(), 40);
  39. for (size_t i = 0; i < v.size(); ++i)
  40. BOOST_CHECK(v[i] == 40 + triangle(i));
  41. }
  42. }
  43. void test_exclusive_scan_init()
  44. {
  45. basic_tests_init();
  46. }
  47. void test_exclusive_scan_init_op()
  48. {
  49. BOOST_CHECK(true);
  50. }
  51. BOOST_AUTO_TEST_CASE( test_main )
  52. {
  53. test_exclusive_scan_init();
  54. test_exclusive_scan_init_op();
  55. }