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

Function TestBitArrayValues

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

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

Source from the content-addressed store, hash-verified

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