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 TestFindEnd
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/command_queue.hpp>
15 #include <boost/compute/algorithm/copy_n.hpp>
16 #include <boost/compute/algorithm/find_end.hpp>
17 #include <boost/compute/container/vector.hpp>
18 #include <boost/compute/types/fundamental.hpp>
19
20 #include "check_macros.hpp"
21 #include "context_setup.hpp"
22
23 namespace bc = boost::compute;
24
BOOST_AUTO_TEST_CASE(find_end_int)25 BOOST_AUTO_TEST_CASE(find_end_int)
26 {
27 bc::int_ data[] = {1, 4, 2, 6, 3, 2, 6, 3, 4, 6};
28 bc::vector<bc::int_> vectort(data, data + 10, queue);
29
30 bc::int_ datap[] = {2, 6};
31 bc::vector<bc::int_> vectorp(datap, datap + 2, queue);
32
33 bc::vector<bc::int_>::iterator iter =
34 bc::find_end(vectort.begin(), vectort.end(),
35 vectorp.begin(), vectorp.end(), queue);
36
37 BOOST_CHECK(iter == vectort.begin() + 5);
38
39 vectorp.insert(vectorp.begin() + 1, bc::int_(9), queue);
40
41 iter =
42 bc::find_end(vectort.begin(), vectort.end(),
43 vectorp.begin(), vectorp.end(), queue);
44
45 BOOST_CHECK(iter == vectort.end());
46 }
47
BOOST_AUTO_TEST_CASE(find_end_string)48 BOOST_AUTO_TEST_CASE(find_end_string)
49 {
50 bc::char_ text[] = "sdabababacabskjabacab";
51 bc::vector<bc::char_> vectort(text, text + 21, queue);
52
53 bc::char_ pattern[] = "aba";
54 bc::vector<bc::char_> vectorp(pattern, pattern + 3, queue);
55
56 bc::vector<bc::char_>::iterator iter =
57 bc::find_end(vectort.begin(), vectort.end(),
58 vectorp.begin(), vectorp.end(), queue);
59
60 BOOST_CHECK(iter == (vectort.begin() + 15));
61 }
62
63 BOOST_AUTO_TEST_SUITE_END()
64