1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Mageswaran.D <mageswaran1989@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 TestLexicographicalCompare
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/container/string.hpp>
15 #include <boost/compute/container/basic_string.hpp>
16 #include <boost/compute/algorithm/lexicographical_compare.hpp>
17
18 #include "context_setup.hpp"
19 #include "check_macros.hpp"
20
BOOST_AUTO_TEST_CASE(lexicographical_compare_string)21 BOOST_AUTO_TEST_CASE(lexicographical_compare_string)
22 {
23 boost::compute::string a = "abcdefghijk";
24 boost::compute::string b = "abcdefghijk";
25 boost::compute::string c = "abcdefghija";
26 boost::compute::string d = "zabcdefghij";
27
28 BOOST_CHECK(boost::compute::lexicographical_compare(a.begin(),
29 a.end(),
30 b.begin(),
31 b.end()) == false);
32
33 BOOST_CHECK(boost::compute::lexicographical_compare(c.begin(),
34 c.end(),
35 a.begin(),
36 a.end()) == true);
37
38 BOOST_CHECK(boost::compute::lexicographical_compare(c.begin(),
39 c.end(),
40 d.begin(),
41 d.end()) == true);
42 }
43
BOOST_AUTO_TEST_CASE(lexicographical_compare_number)44 BOOST_AUTO_TEST_CASE(lexicographical_compare_number)
45 {
46 int data1[] = { 1, 2, 3, 4, 5, 6 };
47 int data2[] = { 9, 2, 3, 4, 5, 6 };
48 int data3[] = { 1, 2, 3, 4, 5 };
49 int data4[] = { 9, 2, 3, 4, 5, 100 };
50
51 boost::compute::vector<int> vector1(data1, data1 + 6, queue);
52 boost::compute::vector<int> vector2(data2, data2 + 6, queue);
53 boost::compute::vector<int> vector3(data3, data3 + 5, queue);
54 boost::compute::vector<int> vector4(data4, data4 + 6, queue);
55
56 BOOST_CHECK(boost::compute::lexicographical_compare(vector1.begin(),
57 vector1.end(),
58 vector2.begin(),
59 vector2.end(),
60 queue) == true);
61
62 BOOST_CHECK(boost::compute::lexicographical_compare(vector1.begin(),
63 vector1.end(),
64 vector3.begin(),
65 vector3.end(),
66 queue) == false);
67
68 BOOST_CHECK(boost::compute::lexicographical_compare(vector3.begin(),
69 vector3.end(),
70 vector4.begin(),
71 vector4.end(),
72 queue) == true);
73 }
74
75 BOOST_AUTO_TEST_SUITE_END()
76