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 TestMismatch
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/algorithm/fill.hpp>
15 #include <boost/compute/algorithm/mismatch.hpp>
16 #include <boost/compute/container/vector.hpp>
17
18 #include "context_setup.hpp"
19
BOOST_AUTO_TEST_CASE(mismatch_int)20 BOOST_AUTO_TEST_CASE(mismatch_int)
21 {
22 int data1[] = { 1, 2, 3, 4, 5, 6 };
23 int data2[] = { 1, 2, 3, 7, 5, 6 };
24
25 boost::compute::vector<int> vector1(data1, data1 + 6, queue);
26 boost::compute::vector<int> vector2(data2, data2 + 6, queue);
27
28 typedef boost::compute::vector<int>::iterator iter;
29
30 std::pair<iter, iter> location =
31 boost::compute::mismatch(vector1.begin(), vector1.end(),
32 vector2.begin(), queue);
33 BOOST_CHECK(location.first == vector1.begin() + 3);
34 BOOST_CHECK_EQUAL(int(*location.first), int(4));
35 BOOST_CHECK(location.second == vector2.begin() + 3);
36 BOOST_CHECK_EQUAL(int(*location.second), int(7));
37 }
38
BOOST_AUTO_TEST_CASE(mismatch_different_range_sizes)39 BOOST_AUTO_TEST_CASE(mismatch_different_range_sizes)
40 {
41 boost::compute::vector<int> a(10, context);
42 boost::compute::vector<int> b(20, context);
43
44 boost::compute::fill(a.begin(), a.end(), 3, queue);
45 boost::compute::fill(b.begin(), b.end(), 3, queue);
46
47 typedef boost::compute::vector<int>::iterator iter;
48
49 std::pair<iter, iter> location;
50
51 location = boost::compute::mismatch(
52 a.begin(), a.end(), b.begin(), b.end(), queue
53 );
54 BOOST_CHECK(location.first == a.end());
55 BOOST_CHECK(location.second == b.begin() + 10);
56
57 location = boost::compute::mismatch(
58 b.begin(), b.end(), a.begin(), a.end(), queue
59 );
60 BOOST_CHECK(location.first == b.begin() + 10);
61 BOOST_CHECK(location.second == a.end());
62 }
63
64 BOOST_AUTO_TEST_SUITE_END()
65