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