test_constant_iterator.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestConstantIterator
  11. #include <boost/test/unit_test.hpp>
  12. #include <iterator>
  13. #include <boost/type_traits.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/compute/algorithm/copy.hpp>
  16. #include <boost/compute/container/vector.hpp>
  17. #include <boost/compute/iterator/constant_iterator.hpp>
  18. #include "check_macros.hpp"
  19. #include "context_setup.hpp"
  20. BOOST_AUTO_TEST_CASE(value_type)
  21. {
  22. BOOST_STATIC_ASSERT((
  23. boost::is_same<
  24. boost::compute::constant_iterator<int>::value_type,
  25. int
  26. >::value
  27. ));
  28. BOOST_STATIC_ASSERT((
  29. boost::is_same<
  30. boost::compute::constant_iterator<float>::value_type,
  31. float
  32. >::value
  33. ));
  34. }
  35. BOOST_AUTO_TEST_CASE(distance)
  36. {
  37. BOOST_CHECK_EQUAL(
  38. std::distance(
  39. boost::compute::make_constant_iterator(128, 0),
  40. boost::compute::make_constant_iterator(128, 10)
  41. ),
  42. std::ptrdiff_t(10)
  43. );
  44. BOOST_CHECK_EQUAL(
  45. std::distance(
  46. boost::compute::make_constant_iterator(256, 5),
  47. boost::compute::make_constant_iterator(256, 10)
  48. ),
  49. std::ptrdiff_t(5)
  50. );
  51. }
  52. BOOST_AUTO_TEST_CASE(copy)
  53. {
  54. boost::compute::vector<int> vector(10, context);
  55. boost::compute::copy(
  56. boost::compute::make_constant_iterator(42, 0),
  57. boost::compute::make_constant_iterator(42, 10),
  58. vector.begin(),
  59. queue
  60. );
  61. CHECK_RANGE_EQUAL(
  62. int, 10, vector,
  63. (42, 42, 42, 42, 42, 42, 42, 42, 42, 42)
  64. );
  65. }
  66. BOOST_AUTO_TEST_CASE(fill_with_copy_doctest)
  67. {
  68. //! [fill_with_copy]
  69. using boost::compute::make_constant_iterator;
  70. boost::compute::vector<int> result(5, context);
  71. boost::compute::copy(
  72. make_constant_iterator(42, 0),
  73. make_constant_iterator(42, result.size()),
  74. result.begin(),
  75. queue
  76. );
  77. // result == { 42, 42, 42, 42, 42 }
  78. //! [fill_with_copy]
  79. CHECK_RANGE_EQUAL(int, 5, result, (42, 42, 42, 42, 42));
  80. }
  81. BOOST_AUTO_TEST_SUITE_END()