]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 TestSearchN | |
12 | #include <boost/test/unit_test.hpp> | |
13 | ||
14 | #include <boost/compute/command_queue.hpp> | |
15 | #include <boost/compute/algorithm/search_n.hpp> | |
16 | #include <boost/compute/container/vector.hpp> | |
17 | #include <boost/compute/types/fundamental.hpp> | |
18 | ||
19 | #include "check_macros.hpp" | |
20 | #include "context_setup.hpp" | |
21 | ||
22 | namespace bc = boost::compute; | |
23 | ||
24 | BOOST_AUTO_TEST_CASE(search_int) | |
25 | { | |
26 | int data[] = {1, 2, 2, 2, 3, 2, 2, 2, 4, 6, 6}; | |
27 | bc::vector<bc::int_> vectort(data, data + 11, queue); | |
28 | ||
29 | bc::vector<bc::int_>::iterator iter = | |
30 | bc::search_n(vectort.begin(), vectort.end(), 3, 2, queue); | |
31 | ||
32 | BOOST_CHECK(iter == vectort.begin() + 1); | |
33 | ||
34 | iter = | |
35 | bc::search_n(vectort.begin(), vectort.end(), 5, 2, queue); | |
36 | ||
37 | BOOST_CHECK(iter == vectort.begin() + 11); | |
38 | ||
39 | iter = | |
40 | bc::search_n(vectort.begin(), vectort.end(), 2, 6, queue); | |
41 | ||
42 | BOOST_CHECK(iter == vectort.begin() + 9); | |
43 | } | |
44 | ||
45 | BOOST_AUTO_TEST_CASE(search_string) | |
46 | { | |
47 | char text[] = "asaaababaaca"; | |
48 | bc::vector<bc::char_> vectort(text, text + 12, queue); | |
49 | ||
50 | bc::vector<bc::char_>::iterator iter = | |
51 | bc::search_n(vectort.begin(), vectort.end(), 2, 'a', queue); | |
52 | ||
53 | BOOST_CHECK(iter == vectort.begin() + 2); | |
54 | } | |
55 | ||
56 | BOOST_AUTO_TEST_SUITE_END() |