2 * Copyright 2015 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <folly/SparseByteSet.h>
22 #include <gtest/gtest.h>
25 using namespace folly;
29 class SparseByteSetTest : public testing::Test {
31 using lims = numeric_limits<uint8_t>;
37 TEST_F(SparseByteSetTest, empty) {
38 for (auto c = lims::min(); c < lims::max(); ++c) {
39 EXPECT_FALSE(s.contains(c));
43 TEST_F(SparseByteSetTest, each) {
44 for (auto c = lims::min(); c < lims::max(); ++c) {
45 EXPECT_TRUE(s.add(c));
46 EXPECT_TRUE(s.contains(c));
48 for (auto c = lims::min(); c < lims::max(); ++c) {
49 EXPECT_FALSE(s.add(c));
50 EXPECT_TRUE(s.contains(c));
54 TEST_F(SparseByteSetTest, each_random) {
56 uniform_int_distribution<uint8_t> dist;
58 while (added.size() <= lims::max()) {
60 EXPECT_EQ(added.count(c), s.contains(c));
61 EXPECT_EQ(!added.count(c), s.add(c));
63 EXPECT_TRUE(added.count(c)); // sanity
64 EXPECT_TRUE(s.contains(c));