|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +#include "roaring/roaring.hh" |
| 20 | + |
| 21 | +#include <gtest/gtest.h> |
| 22 | + |
| 23 | +#include "roaring/roaring64map.hh" |
| 24 | + |
| 25 | +namespace iceberg { |
| 26 | + |
| 27 | +TEST(CRoaringTest, Basic32Bit) { |
| 28 | + roaring::Roaring r1; |
| 29 | + for (uint32_t i = 100; i < 1000; i++) { |
| 30 | + r1.add(i); |
| 31 | + } |
| 32 | + ASSERT_EQ(r1.cardinality(), 900); |
| 33 | + ASSERT_TRUE(r1.contains(500)); |
| 34 | + ASSERT_FALSE(r1.contains(50)); |
| 35 | + ASSERT_FALSE(r1.isEmpty()); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(CRoaringTest, Basic64Bit) { |
| 39 | + roaring::Roaring64Map r2; |
| 40 | + for (uint64_t i = 18000000000000000100ull; i < 18000000000000001000ull; i++) { |
| 41 | + r2.add(i); |
| 42 | + } |
| 43 | + ASSERT_EQ(r2.cardinality(), 900); |
| 44 | + ASSERT_TRUE(r2.contains(18000000000000000500ull)); |
| 45 | + ASSERT_FALSE(r2.contains(18000000000000000050ull)); |
| 46 | + ASSERT_FALSE(r2.isEmpty()); |
| 47 | +} |
| 48 | + |
| 49 | +TEST(CRoaringTest, ConstructorWithInitializerList) { |
| 50 | + roaring::Roaring r1 = roaring::Roaring::bitmapOf(5, 1, 2, 3, 5, 6); |
| 51 | + ASSERT_EQ(r1.cardinality(), 5); |
| 52 | + ASSERT_TRUE(r1.contains(1)); |
| 53 | + ASSERT_TRUE(r1.contains(2)); |
| 54 | + ASSERT_TRUE(r1.contains(3)); |
| 55 | + ASSERT_TRUE(r1.contains(5)); |
| 56 | + ASSERT_TRUE(r1.contains(6)); |
| 57 | + ASSERT_FALSE(r1.contains(4)); |
| 58 | +} |
| 59 | + |
| 60 | +} // namespace iceberg |
0 commit comments