• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@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 TestPrevPermutation
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/functional.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/prev_permutation.hpp>
18 #include <boost/compute/container/vector.hpp>
19 
20 #include "check_macros.hpp"
21 #include "context_setup.hpp"
22 
23 namespace bc = boost::compute;
24 
BOOST_AUTO_TEST_CASE(prev_permutation_int)25 BOOST_AUTO_TEST_CASE(prev_permutation_int)
26 {
27     int dataset[] = {1, 3, 4, 2, 5};
28     bc::vector<bc::int_> vector(dataset, dataset + 5, queue);
29 
30     bool result =
31         bc::prev_permutation(vector.begin(), vector.begin() + 5, queue);
32 
33     CHECK_RANGE_EQUAL(int, 5, vector, (1, 3, 2, 5, 4));
34     BOOST_VERIFY(result == true);
35 
36     vector[1] = 1; vector[4] = 6;
37 
38     result = bc::prev_permutation(vector.begin(), vector.begin() + 5, queue);
39 
40     CHECK_RANGE_EQUAL(int, 5, vector, (6, 5, 2, 1, 1));
41     BOOST_VERIFY(result == false);
42 }
43 
BOOST_AUTO_TEST_CASE(prev_permutation_string)44 BOOST_AUTO_TEST_CASE(prev_permutation_string)
45 {
46     char dataset[] = "baaa";
47     bc::vector<bc::char_> vector(dataset, dataset + 4, queue);
48 
49     bool result =
50         bc::prev_permutation(vector.begin(), vector.begin() + 4, queue);
51 
52     CHECK_RANGE_EQUAL(char, 4, vector, ('a', 'b', 'a', 'a'));
53     BOOST_VERIFY(result == true);
54 
55     result = bc::prev_permutation(vector.begin(), vector.begin() + 4, queue);
56 
57     CHECK_RANGE_EQUAL(char, 4, vector, ('a', 'a', 'b', 'a'));
58     BOOST_VERIFY(result == true);
59 
60     result = bc::prev_permutation(vector.begin(), vector.begin() + 4, queue);
61 
62     CHECK_RANGE_EQUAL(char, 4, vector, ('a', 'a', 'a', 'b'));
63     BOOST_VERIFY(result == true);
64 
65     result = bc::prev_permutation(vector.begin(), vector.begin() + 4, queue);
66 
67     CHECK_RANGE_EQUAL(char, 4, vector, ('b', 'a', 'a', 'a'));
68     BOOST_VERIFY(result == false);
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
72