]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_insertion_sort.cpp
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 #define BOOST_TEST_MODULE TestInsertionSort
12 #include <boost/test/unit_test.hpp>
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/is_sorted.hpp>
16 #include <boost/compute/algorithm/detail/insertion_sort.hpp>
17 #include <boost/compute/container/vector.hpp>
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
22 namespace bc
= boost::compute
;
24 BOOST_AUTO_TEST_CASE(sort_char_vector
)
26 using boost::compute::char_
;
28 char_ data
[] = { 'c', 'a', '0', '7', 'B', 'F', '\0', '$' };
29 boost::compute::vector
<char_
> vector(data
, data
+ 8, queue
);
30 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
31 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
33 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
34 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
35 CHECK_RANGE_EQUAL(char_
, 8, vector
, ('\0', '$', '0', '7', 'B', 'F', 'a', 'c'));
38 BOOST_AUTO_TEST_CASE(sort_uchar_vector
)
40 using boost::compute::uchar_
;
42 uchar_ data
[] = { 0x12, 0x00, 0xFF, 0xB4, 0x80, 0x32, 0x64, 0xA2 };
43 boost::compute::vector
<uchar_
> vector(data
, data
+ 8, queue
);
44 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
45 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
47 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
48 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
49 CHECK_RANGE_EQUAL(uchar_
, 8, vector
, (0x00, 0x12, 0x32, 0x64, 0x80, 0xA2, 0xB4, 0xFF));
52 BOOST_AUTO_TEST_CASE(sort_short_vector
)
54 using boost::compute::short_
;
56 short_ data
[] = { -4, 152, -94, 963, 31002, -456, 0, -2113 };
57 boost::compute::vector
<short_
> vector(data
, data
+ 8, queue
);
58 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
59 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
61 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
62 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
63 CHECK_RANGE_EQUAL(short_
, 8, vector
, (-2113, -456, -94, -4, 0, 152, 963, 31002));
66 BOOST_AUTO_TEST_CASE(sort_ushort_vector
)
68 using boost::compute::ushort_
;
70 ushort_ data
[] = { 4, 152, 94, 963, 63202, 34560, 0, 2113 };
71 boost::compute::vector
<ushort_
> vector(data
, data
+ 8, queue
);
72 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
73 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
75 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
76 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
77 CHECK_RANGE_EQUAL(ushort_
, 8, vector
, (0, 4, 94, 152, 963, 2113, 34560, 63202));
80 BOOST_AUTO_TEST_CASE(sort_int_vector
)
82 int data
[] = { -4, 152, -5000, 963, 75321, -456, 0, 1112 };
83 boost::compute::vector
<int> vector(data
, data
+ 8, queue
);
84 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
85 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
87 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
88 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
89 CHECK_RANGE_EQUAL(int, 8, vector
, (-5000, -456, -4, 0, 152, 963, 1112, 75321));
92 BOOST_AUTO_TEST_CASE(sort_uint_vector
)
94 using boost::compute::uint_
;
96 uint_ data
[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 };
97 boost::compute::vector
<uint_
> vector(data
, data
+ 8, queue
);
98 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
99 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
101 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
102 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
103 CHECK_RANGE_EQUAL(uint_
, 8, vector
, (0, 500, 562, 1988, 9852, 102030, 123456, 4000000));
106 BOOST_AUTO_TEST_CASE(sort_long_vector
)
108 using boost::compute::long_
;
110 long_ data
[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 };
111 boost::compute::vector
<long_
> vector(data
, data
+ 8, queue
);
112 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
113 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
115 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
116 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
117 CHECK_RANGE_EQUAL(long_
, 8, vector
, (0, 500, 562, 1988, 9852, 102030, 123456, 4000000));
120 BOOST_AUTO_TEST_CASE(sort_ulong_vector
)
122 using boost::compute::ulong_
;
124 ulong_ data
[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 };
125 boost::compute::vector
<ulong_
> vector(data
, data
+ 8, queue
);
126 BOOST_CHECK_EQUAL(vector
.size(), size_t(8));
127 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
129 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
130 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
131 CHECK_RANGE_EQUAL(ulong_
, 8, vector
, (0, 500, 562, 1988, 9852, 102030, 123456, 4000000));
134 BOOST_AUTO_TEST_CASE(sort_float_vector
)
136 float data
[] = { -6023.0f
, 152.5f
, -63.0f
, 1234567.0f
, 11.2f
,
137 -5000.1f
, 0.0f
, 14.0f
, -8.25f
, -0.0f
};
138 boost::compute::vector
<float> vector(data
, data
+ 10, queue
);
139 BOOST_CHECK_EQUAL(vector
.size(), size_t(10));
140 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
142 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
143 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
146 (-6023.0f
, -5000.1f
, -63.0f
, -8.25f
, -0.0f
, 0.0f
, 11.2f
, 14.0f
, 152.5f
, 1234567.0f
)
150 BOOST_AUTO_TEST_CASE(sort_double_vector
)
152 if(!device
.supports_extension("cl_khr_fp64")){
153 std::cout
<< "skipping test: device does not support double" << std::endl
;
157 double data
[] = { -6023.0, 152.5, -63.0, 1234567.0, 11.2,
158 -5000.1, 0.0, 14.0, -8.25, -0.0 };
159 boost::compute::vector
<double> vector(data
, data
+ 10, queue
);
160 BOOST_CHECK_EQUAL(vector
.size(), size_t(10));
161 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == false);
163 boost::compute::detail::serial_insertion_sort(vector
.begin(), vector
.end(), queue
);
164 BOOST_CHECK(boost::compute::is_sorted(vector
.begin(), vector
.end(), queue
) == true);
167 (-6023.0, -5000.1, -63.0, -8.25, -0.0, 0.0, 11.2, 14.0, 152.5, 1234567.0)
171 BOOST_AUTO_TEST_SUITE_END()