• 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 TestRandomShuffle
12 #include <boost/test/unit_test.hpp>
13 
14 #include <set>
15 #include <iterator>
16 
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/command_queue.hpp>
19 #include <boost/compute/algorithm/random_shuffle.hpp>
20 #include <boost/compute/container/vector.hpp>
21 
22 #include "context_setup.hpp"
23 
24 namespace bc = boost::compute;
25 
BOOST_AUTO_TEST_CASE(shuffle_int_vector)26 BOOST_AUTO_TEST_CASE(shuffle_int_vector)
27 {
28     bc::vector<int> vector(context);
29     vector.push_back(1, queue);
30     vector.push_back(9, queue);
31     vector.push_back(19, queue);
32     vector.push_back(29, queue);
33     queue.finish();
34 
35     std::set<int> original_values;
36     for(size_t i = 0; i < vector.size(); i++){
37         original_values.insert(vector[i]);
38     }
39     BOOST_CHECK_EQUAL(original_values.size(), size_t(4));
40 
41     bc::random_shuffle(vector.begin(), vector.end(), queue);
42 
43     std::set<int> shuffled_values;
44     bc::copy(
45         vector.begin(),
46         vector.end(),
47         std::inserter(shuffled_values, shuffled_values.begin()),
48         queue
49     );
50     BOOST_CHECK_EQUAL(shuffled_values.size(), size_t(4));
51     BOOST_VERIFY(original_values == shuffled_values);
52 }
53 
54 BOOST_AUTO_TEST_SUITE_END()
55