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

Function TestPutValue

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

Write up to 'num_vals' values with width 'bit_width' and reads them back.

Source from the content-addressed store, hash-verified

180
181// Write up to 'num_vals' values with width 'bit_width' and reads them back.
182static void TestPutValue(int bit_width, uint64_t num_vals) {
183 // The max value representable in `bit_width` bits.
184 const uint64_t max = std::numeric_limits<uint64_t>::max() >> (64 - bit_width);
185 num_vals = std::min(num_vals, max);
186 int len = static_cast<int>(bit_util::BytesForBits(bit_width * num_vals));
187 EXPECT_GT(len, 0);
188
189 std::vector<uint8_t> buffer(len);
190 bit_util::BitWriter writer(buffer.data(), len);
191 for (uint64_t i = max - num_vals; i < max; i++) {
192 bool result = writer.PutValue(i, bit_width);
193 EXPECT_TRUE(result);
194 }
195 writer.Flush();
196 EXPECT_EQ(writer.bytes_written(), len);
197
198 bit_util::BitReader reader(buffer.data(), len);
199 for (uint64_t i = max - num_vals; i < max; i++) {
200 int64_t val = 0;
201 bool result = reader.GetValue(bit_width, &val);
202 EXPECT_TRUE(result);
203 EXPECT_EQ(val, i);
204 }
205 EXPECT_EQ(reader.bytes_left(), 0);
206}
207
208TEST(BitUtil, RoundTripIntValues) {
209 for (int width = 1; width < 64; 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