1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_TEST_CHECK_MACROS_HPP
12 #define BOOST_COMPUTE_TEST_CHECK_MACROS_HPP
14 #define LIST_ARRAY_VALUES(z, n, data) \
15 BOOST_PP_COMMA_IF(n) BOOST_PP_ARRAY_ELEM(n, data)
17 // checks 'size' values of 'type' in the device range 'actual`
18 // against the values given in the array 'expected'
19 #define CHECK_RANGE_EQUAL(type, size, actual, expected) \
22 boost::compute::copy( \
23 actual.begin(), actual.begin()+size, _actual, queue \
25 const type _expected[size] = { \
26 BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
28 BOOST_CHECK_EQUAL_COLLECTIONS( \
29 _actual, _actual + size, _expected, _expected + size \
33 template <typename Left, typename Right, typename ToleranceBaseType>
35 equal_close_impl(Left left_begin,
39 ToleranceBaseType tolerance)
41 for(; left_begin != (left_end); ++left_begin, ++right_begin) {
42 BOOST_CHECK_CLOSE(*left_begin, *right_begin, tolerance); \
46 #define BOOST_COMPUTE_TEST_CHECK_CLOSE_COLLECTIONS(L_begin, L_end, R_begin, R_end, tolerance) \
48 equal_close_impl(L_begin, L_end, R_begin, R_end, tolerance); \
51 #define CHECK_RANGE_CLOSE(type, size, actual, expected, tolerance) \
54 boost::compute::copy( \
55 actual.begin(), actual.begin()+size, _actual, queue \
57 const type _expected[size] = { \
58 BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
60 BOOST_COMPUTE_TEST_CHECK_CLOSE_COLLECTIONS( \
61 _actual, _actual + size, _expected, _expected + size, tolerance \
65 #define CHECK_HOST_RANGE_EQUAL(type, size, actual, expected) \
67 const type _expected[size] = { \
68 BOOST_PP_REPEAT(size, LIST_ARRAY_VALUES, (size, expected)) \
70 BOOST_CHECK_EQUAL_COLLECTIONS( \
71 actual, actual + size, _expected, _expected + size \
75 #define CHECK_STRING_EQUAL(actual, expected) \
77 std::string _actual(actual.size(), '\0'); \
78 boost::compute::copy( \
79 actual.begin(), actual.end(), _actual.begin(), queue \
81 BOOST_CHECK_EQUAL(_actual, expected); \
84 #endif // BOOST_COMPUTE_TEST_CHECK_MACROS_HPP