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