]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 TestFlatSet | |
12 | #include <boost/test/unit_test.hpp> | |
13 | ||
14 | #include <utility> | |
15 | ||
16 | #include <boost/concept_check.hpp> | |
17 | ||
18 | #include <boost/compute/system.hpp> | |
19 | #include <boost/compute/command_queue.hpp> | |
20 | #include <boost/compute/container/flat_set.hpp> | |
21 | ||
22 | #include "context_setup.hpp" | |
23 | ||
24 | namespace bc = boost::compute; | |
25 | ||
26 | BOOST_AUTO_TEST_CASE(concept_check) | |
27 | { | |
28 | BOOST_CONCEPT_ASSERT((boost::Container<bc::flat_set<int> >)); | |
29 | // BOOST_CONCEPT_ASSERT((boost::SimpleAssociativeContainer<bc::flat_set<int> >)); | |
30 | // BOOST_CONCEPT_ASSERT((boost::UniqueAssociativeContainer<bc::flat_set<int> >)); | |
31 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<bc::flat_set<int>::iterator>)); | |
32 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<bc::flat_set<int>::const_iterator>)); | |
33 | } | |
34 | ||
35 | BOOST_AUTO_TEST_CASE(insert) | |
36 | { | |
37 | bc::flat_set<int> set(context); | |
38 | typedef bc::flat_set<int>::iterator iterator; | |
39 | std::pair<iterator, bool> location = set.insert(12, queue); | |
b32b8144 | 40 | queue.finish(); |
7c673cae FG |
41 | BOOST_CHECK(location.first == set.begin()); |
42 | BOOST_CHECK(location.second == true); | |
43 | BOOST_CHECK_EQUAL(*location.first, 12); | |
44 | BOOST_CHECK_EQUAL(set.size(), size_t(1)); | |
45 | ||
46 | location = set.insert(12, queue); | |
b32b8144 | 47 | queue.finish(); |
7c673cae FG |
48 | BOOST_CHECK(location.first == set.begin()); |
49 | BOOST_CHECK(location.second == false); | |
50 | BOOST_CHECK_EQUAL(set.size(), size_t(1)); | |
51 | ||
52 | location = set.insert(4, queue); | |
b32b8144 | 53 | queue.finish(); |
7c673cae FG |
54 | BOOST_CHECK(location.first == set.begin()); |
55 | BOOST_CHECK(location.second == true); | |
56 | BOOST_CHECK_EQUAL(set.size(), size_t(2)); | |
57 | ||
58 | location = set.insert(12, queue); | |
b32b8144 | 59 | queue.finish(); |
7c673cae FG |
60 | BOOST_CHECK(location.first == set.begin() + 1); |
61 | BOOST_CHECK(location.second == false); | |
62 | BOOST_CHECK_EQUAL(set.size(), size_t(2)); | |
63 | ||
64 | location = set.insert(9, queue); | |
b32b8144 | 65 | queue.finish(); |
7c673cae FG |
66 | BOOST_CHECK(location.first == set.begin() + 1); |
67 | BOOST_CHECK(location.second == true); | |
68 | BOOST_CHECK_EQUAL(set.size(), size_t(3)); | |
69 | } | |
70 | ||
71 | BOOST_AUTO_TEST_CASE(erase) | |
72 | { | |
73 | bc::flat_set<int> set(context); | |
74 | typedef bc::flat_set<int>::iterator iterator; | |
75 | set.insert(1, queue); | |
76 | set.insert(2, queue); | |
77 | set.insert(3, queue); | |
78 | set.insert(4, queue); | |
79 | set.insert(5, queue); | |
b32b8144 | 80 | queue.finish(); |
7c673cae FG |
81 | BOOST_CHECK_EQUAL(set.size(), size_t(5)); |
82 | ||
83 | iterator i = set.erase(set.begin(), queue); | |
84 | queue.finish(); | |
85 | BOOST_CHECK(i == set.begin() + 1); | |
86 | BOOST_CHECK_EQUAL(set.size(), size_t(4)); | |
87 | BOOST_CHECK_EQUAL(*set.begin(), 2); | |
88 | ||
89 | size_t count = set.erase(3, queue); | |
90 | queue.finish(); | |
91 | BOOST_CHECK_EQUAL(count, size_t(1)); | |
92 | BOOST_CHECK_EQUAL(set.size(), size_t(3)); | |
93 | BOOST_CHECK_EQUAL(*set.begin(), 2); | |
94 | ||
95 | count = set.erase(9, queue); | |
96 | queue.finish(); | |
97 | BOOST_CHECK_EQUAL(count, size_t(0)); | |
98 | BOOST_CHECK_EQUAL(set.size(), size_t(3)); | |
99 | BOOST_CHECK_EQUAL(*set.begin(), 2); | |
100 | ||
101 | i = set.erase(set.begin() + 1, queue); | |
102 | queue.finish(); | |
103 | BOOST_CHECK(i == set.begin() + 2); | |
104 | BOOST_CHECK_EQUAL(set.size(), size_t(2)); | |
105 | BOOST_CHECK_EQUAL(*set.begin(), 2); | |
106 | BOOST_CHECK_EQUAL(*(set.end() - 1), 5); | |
107 | ||
108 | set.erase(set.begin(), set.end(), queue); | |
109 | queue.finish(); | |
110 | BOOST_CHECK_EQUAL(set.size(), size_t(0)); | |
111 | } | |
112 | ||
113 | BOOST_AUTO_TEST_CASE(clear) | |
114 | { | |
115 | bc::flat_set<float> set; | |
116 | BOOST_CHECK(set.empty() == true); | |
117 | BOOST_CHECK_EQUAL(set.size(), size_t(0)); | |
118 | ||
119 | set.clear(); | |
120 | BOOST_CHECK(set.empty() == true); | |
121 | BOOST_CHECK_EQUAL(set.size(), size_t(0)); | |
122 | ||
123 | set.insert(3.14f); | |
124 | BOOST_CHECK(set.empty() == false); | |
125 | BOOST_CHECK_EQUAL(set.size(), size_t(1)); | |
126 | ||
127 | set.insert(4.184f); | |
128 | BOOST_CHECK(set.empty() == false); | |
129 | BOOST_CHECK_EQUAL(set.size(), size_t(2)); | |
130 | ||
131 | set.clear(); | |
132 | BOOST_CHECK(set.empty() == true); | |
133 | BOOST_CHECK_EQUAL(set.size(), size_t(0)); | |
134 | } | |
135 | ||
136 | BOOST_AUTO_TEST_SUITE_END() |