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 TestEqual
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/algorithm/equal.hpp>
15 #include <boost/compute/algorithm/fill.hpp>
16 #include <boost/compute/container/string.hpp>
17 #include <boost/compute/container/vector.hpp>
18
19 #include "context_setup.hpp"
20
BOOST_AUTO_TEST_CASE(equal_int)21 BOOST_AUTO_TEST_CASE(equal_int)
22 {
23 int data1[] = { 1, 2, 3, 4, 5, 6 };
24 int data2[] = { 1, 2, 3, 7, 5, 6 };
25
26 boost::compute::vector<int> vector1(data1, data1 + 6, queue);
27 boost::compute::vector<int> vector2(data2, data2 + 6, queue);
28
29 BOOST_CHECK(boost::compute::equal(vector1.begin(), vector1.end(),
30 vector2.begin(), queue) == false);
31 BOOST_CHECK(boost::compute::equal(vector1.begin(), vector1.begin() + 2,
32 vector2.begin(), queue) == true);
33 BOOST_CHECK(boost::compute::equal(vector1.begin() + 4, vector1.end(),
34 vector2.begin() + 4, queue) == true);
35 }
36
BOOST_AUTO_TEST_CASE(equal_string)37 BOOST_AUTO_TEST_CASE(equal_string)
38 {
39 boost::compute::string a = "abcdefghijk";
40 boost::compute::string b = "abcdefghijk";
41 boost::compute::string c = "abcdezghijk";
42
43 BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), b.begin(), queue) == true);
44 BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), c.begin(), queue) == false);
45 }
46
BOOST_AUTO_TEST_CASE(equal_different_range_sizes)47 BOOST_AUTO_TEST_CASE(equal_different_range_sizes)
48 {
49 boost::compute::vector<int> a(10, context);
50 boost::compute::vector<int> b(20, context);
51
52 boost::compute::fill(a.begin(), a.end(), 3, queue);
53 boost::compute::fill(b.begin(), b.end(), 3, queue);
54
55 BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), b.begin(), b.end(), queue) == false);
56 BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), a.begin(), a.end(), queue) == true);
57 BOOST_CHECK(boost::compute::equal(b.begin(), b.end(), a.begin(), a.end(), queue) == false);
58 BOOST_CHECK(boost::compute::equal(b.begin(), b.end(), b.begin(), b.end(), queue) == true);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()
62