• 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 TestIsPermutation
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/is_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(is_permutation_int)25 BOOST_AUTO_TEST_CASE(is_permutation_int)
26 {
27     bc::int_ dataset1[] = {1, 3, 1, 2, 5};
28     bc::vector<bc::int_> vector1(dataset1, dataset1 + 5, queue);
29 
30     bc::int_ dataset2[] = {3, 1, 5, 1, 2};
31     bc::vector<bc::int_> vector2(dataset2, dataset2 + 5, queue);
32 
33     bool result =
34         bc::is_permutation(vector1.begin(), vector1.begin() + 5,
35                            vector2.begin(), vector2.begin() + 5, queue);
36 
37     BOOST_VERIFY(result == true);
38 
39     vector2.begin().write(bc::int_(1), queue);
40 
41     result = bc::is_permutation(vector1.begin(), vector1.begin() + 5,
42                                 vector2.begin(), vector2.begin() + 5,
43                                 queue);
44 
45     BOOST_VERIFY(result == false);
46 }
47 
BOOST_AUTO_TEST_CASE(is_permutation_string)48 BOOST_AUTO_TEST_CASE(is_permutation_string)
49 {
50     bc::char_ dataset1[] = "abade";
51     bc::vector<bc::char_> vector1(dataset1, dataset1 + 5, queue);
52 
53     bc::char_ dataset2[] = "aadeb";
54     bc::vector<bc::char_> vector2(dataset2, dataset2 + 5, queue);
55 
56     bool result =
57         bc::is_permutation(vector1.begin(), vector1.begin() + 5,
58                            vector2.begin(), vector2.begin() + 5, queue);
59 
60     BOOST_VERIFY(result == true);
61 
62     vector2.begin().write(bc::char_('b'), queue);
63 
64     result = bc::is_permutation(vector1.begin(), vector1.begin() + 5,
65                                 vector2.begin(), vector2.begin() + 5,
66                                 queue);
67 
68     BOOST_VERIFY(result == false);
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
72