test_random_fill.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 TestRandomFill
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/algorithm/count_if.hpp>
  15. #include <boost/compute/algorithm/detail/random_fill.hpp>
  16. #include <boost/compute/container/vector.hpp>
  17. #include <boost/compute/lambda.hpp>
  18. #include "context_setup.hpp"
  19. namespace compute = boost::compute;
  20. BOOST_AUTO_TEST_CASE(random_fill_float)
  21. {
  22. using compute::lambda::_1;
  23. compute::vector<float> vector(10, context);
  24. // fill with values between 0 and 1
  25. compute::detail::random_fill(
  26. vector.begin(),
  27. vector.end(),
  28. 0.0f,
  29. 1.0f,
  30. queue
  31. );
  32. BOOST_CHECK_EQUAL(
  33. compute::count_if(
  34. vector.begin(), vector.end(), _1 < 0.0f || _1 > 1.0f, queue
  35. ),
  36. size_t(0)
  37. );
  38. // fill with values between 5 and 10
  39. compute::detail::random_fill(
  40. vector.begin(),
  41. vector.end(),
  42. 5.0f,
  43. 10.0f,
  44. queue
  45. );
  46. BOOST_CHECK_EQUAL(
  47. compute::count_if(
  48. vector.begin(), vector.end(), _1 < 5.0f || _1 > 10.0f, queue
  49. ),
  50. size_t(0)
  51. );
  52. // fill with values between -25 and 25
  53. compute::detail::random_fill(
  54. vector.begin(), vector.end(), -25.0f, 25.0f, queue
  55. );
  56. BOOST_CHECK_EQUAL(
  57. compute::count_if(
  58. vector.begin(), vector.end(), _1 < -25.0f || _1 > 25.0f, queue
  59. ),
  60. size_t(0)
  61. );
  62. }
  63. BOOST_AUTO_TEST_SUITE_END()