test_functional_popcount.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 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 TestFunctionalPopcount
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/algorithm/transform.hpp>
  13. #include <boost/compute/container/vector.hpp>
  14. #include <boost/compute/functional/popcount.hpp>
  15. #include "check_macros.hpp"
  16. #include "context_setup.hpp"
  17. namespace compute = boost::compute;
  18. typedef boost::mpl::list<
  19. compute::uchar_, compute::ushort_, compute::uint_, compute::ulong_
  20. > popcount_test_types;
  21. BOOST_AUTO_TEST_CASE_TEMPLATE(popcount, T, popcount_test_types)
  22. {
  23. compute::vector<T> vec(context);
  24. vec.push_back(0x00, queue);
  25. vec.push_back(0x01, queue);
  26. vec.push_back(0x03, queue);
  27. vec.push_back(0xff, queue);
  28. compute::vector<int> popcounts(vec.size(), context);
  29. compute::transform(
  30. vec.begin(), vec.end(), popcounts.begin(), compute::popcount<T>(), queue
  31. );
  32. CHECK_RANGE_EQUAL(int, 4, popcounts, (0, 1, 2, 8));
  33. }
  34. BOOST_AUTO_TEST_SUITE_END()