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 TestSearch
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/search.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(search_int)25 BOOST_AUTO_TEST_CASE(search_int)
26 {
27 int data[] = {1, 4, 2, 6, 3, 2, 6, 3, 4, 6, 6};
28 bc::vector<bc::int_> vectort(data, data + 11, queue);
29
30 int datap[] = {2, 6};
31 bc::vector<bc::int_> vectorp(datap, datap + 2, queue);
32
33 bc::vector<bc::int_>::iterator iter =
34 bc::search(vectort.begin(), vectort.end(),
35 vectorp.begin(), vectorp.end(), queue);
36
37 BOOST_CHECK(iter == vectort.begin() + 2);
38
39 vectorp[1] = 9;
40
41 iter =
42 bc::search(vectort.begin(), vectort.end(),
43 vectorp.begin(), vectorp.end(), queue);
44
45 BOOST_CHECK(iter == vectort.begin() + 11);
46
47 vectorp[0] = 6;
48 vectorp[1] = 6;
49
50 iter =
51 bc::search(vectort.begin(), vectort.end(),
52 vectorp.begin(), vectorp.end(), queue);
53
54 BOOST_CHECK(iter == vectort.begin() + 9);
55 }
56
BOOST_AUTO_TEST_CASE(search_string)57 BOOST_AUTO_TEST_CASE(search_string)
58 {
59 char text[] = "sdabababacabskjabacab";
60 bc::vector<bc::char_> vectort(text, text + 21, queue);
61
62 char pattern[] = "aba";
63 bc::vector<bc::char_> vectorp(pattern, pattern + 3, queue);
64
65 bc::vector<bc::char_>::iterator iter =
66 bc::search(vectort.begin(), vectort.end(),
67 vectorp.begin(), vectorp.end(), queue);
68
69 BOOST_CHECK(iter == vectort.begin() + 2);
70 }
71
72 BOOST_AUTO_TEST_SUITE_END()
73