• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define BOOST_TEST_MODULE TestInplaceMerge
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/inplace_merge.hpp>
16 #include <boost/compute/container/vector.hpp>
17 
18 #include "check_macros.hpp"
19 #include "context_setup.hpp"
20 
21 namespace compute = boost::compute;
22 
BOOST_AUTO_TEST_CASE(simple_merge_int)23 BOOST_AUTO_TEST_CASE(simple_merge_int)
24 {
25     int data[] = { 1, 3, 5, 7, 2, 4, 6, 8 };
26     compute::vector<int> vector(data, data + 8, queue);
27 
28     // merge each half in-place
29     compute::inplace_merge(
30         vector.begin(),
31         vector.begin() + 4,
32         vector.end(),
33         queue
34     );
35     CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8));
36 
37     // run again on already sorted list
38     compute::inplace_merge(
39         vector.begin(),
40         vector.begin() + 4,
41         vector.end(),
42         queue
43     );
44     CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8));
45 }
46 
47 BOOST_AUTO_TEST_SUITE_END()
48