check_macros.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef BOOST_COMPUTE_TEST_CHECK_MACROS_HPP
  11. #define BOOST_COMPUTE_TEST_CHECK_MACROS_HPP
  12. #define LIST_ARRAY_VALUES(z, n, data) \
  13. BOOST_PP_COMMA_IF(n) BOOST_PP_ARRAY_ELEM(n, data)
  14. // checks 'size' values of 'type' in the device range 'actual`
  15. // against the values given in the array 'expected'
  16. #define CHECK_RANGE_EQUAL(type, size, actual, expected) \
  17. { \
  18. type _actual[size]; \
  19. boost::compute::copy( \
  20. actual.begin(), actual.begin()+size, _actual, queue \
  21. ); \
  22. const type _expected[size] = { \
  23. BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
  24. }; \
  25. BOOST_CHECK_EQUAL_COLLECTIONS( \
  26. _actual, _actual + size, _expected, _expected + size \
  27. ); \
  28. }
  29. template <typename Left, typename Right, typename ToleranceBaseType>
  30. inline void
  31. equal_close_impl(Left left_begin,
  32. Left left_end,
  33. Right right_begin,
  34. Right right_end,
  35. ToleranceBaseType tolerance)
  36. {
  37. for(; left_begin != (left_end); ++left_begin, ++right_begin) {
  38. BOOST_CHECK_CLOSE(*left_begin, *right_begin, tolerance); \
  39. }
  40. }
  41. #define BOOST_COMPUTE_TEST_CHECK_CLOSE_COLLECTIONS(L_begin, L_end, R_begin, R_end, tolerance) \
  42. { \
  43. equal_close_impl(L_begin, L_end, R_begin, R_end, tolerance); \
  44. }
  45. #define CHECK_RANGE_CLOSE(type, size, actual, expected, tolerance) \
  46. { \
  47. type _actual[size]; \
  48. boost::compute::copy( \
  49. actual.begin(), actual.begin()+size, _actual, queue \
  50. ); \
  51. const type _expected[size] = { \
  52. BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
  53. }; \
  54. BOOST_COMPUTE_TEST_CHECK_CLOSE_COLLECTIONS( \
  55. _actual, _actual + size, _expected, _expected + size, tolerance \
  56. ); \
  57. }
  58. #define CHECK_HOST_RANGE_EQUAL(type, size, actual, expected) \
  59. { \
  60. const type _expected[size] = { \
  61. BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
  62. }; \
  63. BOOST_CHECK_EQUAL_COLLECTIONS( \
  64. actual, actual + size, _expected, _expected + size \
  65. ); \
  66. }
  67. #define CHECK_STRING_EQUAL(actual, expected) \
  68. { \
  69. std::string _actual(actual.size(), '\0'); \
  70. boost::compute::copy( \
  71. actual.begin(), actual.end(), _actual.begin(), queue \
  72. ); \
  73. BOOST_CHECK_EQUAL(_actual, expected); \
  74. }
  75. #endif // BOOST_COMPUTE_TEST_CHECK_MACROS_HPP