MCPcopy Create free account
hub / github.com/apache/arrow / TestBitArrayValues

Function TestBitArrayValues

cpp/src/arrow/util/rle_encoding_test.cc:110–132  ·  view source on GitHub ↗

Writes 'num_vals' values with width 'bit_width' and reads them back.

Source from the content-addressed store, hash-verified

108
109// Writes 'num_vals' values with width 'bit_width' and reads them back.
110void TestBitArrayValues(int bit_width, int num_vals) {
111 int len = static_cast<int>(bit_util::BytesForBits(bit_width * num_vals));
112 EXPECT_GT(len, 0);
113 const uint64_t mod = bit_width == 64 ? 1 : 1LL << bit_width;
114
115 std::vector<uint8_t> buffer(len);
116 bit_util::BitWriter writer(buffer.data(), len);
117 for (int i = 0; i < num_vals; ++i) {
118 bool result = writer.PutValue(i % mod, bit_width);
119 EXPECT_TRUE(result);
120 }
121 writer.Flush();
122 EXPECT_EQ(writer.bytes_written(), len);
123
124 bit_util::BitReader reader(buffer.data(), len);
125 for (int i = 0; i < num_vals; ++i) {
126 int64_t val = 0;
127 bool result = reader.GetValue(bit_width, &val);
128 EXPECT_TRUE(result);
129 EXPECT_EQ(val, i % mod);
130 }
131 EXPECT_EQ(reader.bytes_left(), 0);
132}
133
134TEST(BitArray, TestValues) {
135 for (int width = 1; width <= MAX_WIDTH; ++width) {

Callers 1

TESTFunction · 0.85

Calls 7

BytesForBitsFunction · 0.85
PutValueMethod · 0.80
bytes_writtenMethod · 0.80
bytes_leftMethod · 0.80
dataMethod · 0.45
FlushMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected