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

Function TestPutValue

cpp/src/arrow/util/rle_encoding_test.cc:181–205  ·  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

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