1 /*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <folly/ConcurrentBitSet.h>
18
19 #include <glog/logging.h>
20
21 #include <folly/portability/GFlags.h>
22 #include <folly/portability/GTest.h>
23
24 namespace folly {
25 namespace test {
26
TEST(ConcurrentBitSet,Simple)27 TEST(ConcurrentBitSet, Simple) {
28 constexpr size_t kSize = 1000;
29 ConcurrentBitSet<kSize> bs;
30
31 EXPECT_EQ(kSize, bs.size());
32
33 for (size_t i = 0; i < kSize; ++i) {
34 EXPECT_FALSE(bs[i]);
35 }
36
37 bs.set(42);
38 for (size_t i = 0; i < kSize; ++i) {
39 EXPECT_EQ(i == 42, bs[i]);
40 }
41
42 bs.set(43);
43 for (size_t i = 0; i < kSize; ++i) {
44 EXPECT_EQ((i == 42 || i == 43), bs[i]);
45 }
46
47 bs.reset(42);
48 for (size_t i = 0; i < kSize; ++i) {
49 EXPECT_EQ((i == 43), bs[i]);
50 }
51
52 bs.reset(43);
53 for (size_t i = 0; i < kSize; ++i) {
54 EXPECT_FALSE(bs[i]);
55 }
56
57 bs.set(268);
58 for (size_t i = 0; i < kSize; ++i) {
59 EXPECT_EQ(i == 268, bs[i]);
60 }
61
62 bs.reset(268);
63 for (size_t i = 0; i < kSize; ++i) {
64 EXPECT_FALSE(bs[i]);
65 }
66 }
67
68 } // namespace test
69 } // namespace folly
70
main(int argc,char * argv[])71 int main(int argc, char* argv[]) {
72 testing::InitGoogleTest(&argc, argv);
73 gflags::ParseCommandLineFlags(&argc, &argv, true);
74 return RUN_ALL_TESTS();
75 }
76