• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 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 TestDynamicBitset
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/algorithm/copy.hpp>
15 #include <boost/compute/container/dynamic_bitset.hpp>
16 
17 #include "check_macros.hpp"
18 #include "context_setup.hpp"
19 
20 namespace compute = boost::compute;
21 
BOOST_AUTO_TEST_CASE(set_and_test)22 BOOST_AUTO_TEST_CASE(set_and_test)
23 {
24     compute::dynamic_bitset<> bits(1024, queue);
25 
26     bits.set(1, queue);
27     BOOST_CHECK(bits.test(1, queue) == true);
28     BOOST_CHECK(bits.test(2, queue) == false);
29 
30     bits.set(1, false, queue);
31     BOOST_CHECK(bits.test(1, queue) == false);
32     BOOST_CHECK(bits.test(2, queue) == false);
33 }
34 
BOOST_AUTO_TEST_CASE(count)35 BOOST_AUTO_TEST_CASE(count)
36 {
37     compute::dynamic_bitset<> bits(1024, queue);
38     BOOST_CHECK_EQUAL(bits.count(queue), size_t(0));
39 
40     bits.set(1, queue);
41     bits.set(8, queue);
42     bits.set(129, queue);
43     BOOST_CHECK_EQUAL(bits.count(queue), size_t(3));
44 
45     bits.set(8, false, queue);
46     BOOST_CHECK_EQUAL(bits.count(queue), size_t(2));
47 
48     bits.reset(queue);
49     BOOST_CHECK_EQUAL(bits.count(queue), size_t(0));
50 }
51 
BOOST_AUTO_TEST_CASE(resize)52 BOOST_AUTO_TEST_CASE(resize)
53 {
54     compute::dynamic_bitset<> bits(0, queue);
55     BOOST_CHECK_EQUAL(bits.size(), size_t(0));
56     BOOST_CHECK_EQUAL(bits.empty(), true);
57     BOOST_CHECK_EQUAL(bits.count(queue), size_t(0));
58 
59     bits.resize(100, queue);
60     BOOST_CHECK_EQUAL(bits.size(), size_t(100));
61     BOOST_CHECK_EQUAL(bits.empty(), false);
62     BOOST_CHECK_EQUAL(bits.count(queue), size_t(0));
63 
64     bits.set(42, true, queue);
65     BOOST_CHECK_EQUAL(bits.count(queue), size_t(1));
66 
67     bits.resize(0, queue);
68     BOOST_CHECK_EQUAL(bits.size(), size_t(0));
69     BOOST_CHECK_EQUAL(bits.empty(), true);
70     BOOST_CHECK_EQUAL(bits.count(queue), size_t(0));
71 }
72 
BOOST_AUTO_TEST_CASE(none_and_any)73 BOOST_AUTO_TEST_CASE(none_and_any)
74 {
75     compute::dynamic_bitset<> bits(1024, queue);
76     BOOST_CHECK(bits.any(queue) == false);
77     BOOST_CHECK(bits.none(queue) == true);
78 
79     bits.set(1023, queue);
80     BOOST_CHECK(bits.any(queue) == true);
81     BOOST_CHECK(bits.none(queue) == false);
82 
83     bits.set(1023, false, queue);
84     BOOST_CHECK(bits.any(queue) == false);
85     BOOST_CHECK(bits.none(queue) == true);
86 
87     bits.set(1, queue);
88     BOOST_CHECK(bits.any(queue) == true);
89     BOOST_CHECK(bits.none(queue) == false);
90 
91     bits.reset(queue);
92     BOOST_CHECK(bits.any(queue) == false);
93     BOOST_CHECK(bits.none(queue) == true);
94 }
95 
96 BOOST_AUTO_TEST_SUITE_END()
97