pitrou commented on code in PR #14191:
URL: https://github.com/apache/arrow/pull/14191#discussion_r1048503894


##########
cpp/src/arrow/util/rle_encoding_test.cc:
##########
@@ -173,6 +173,39 @@ TEST(BitArray, TestMixed) {
   }
 }
 
+// Writes 'num_vals' values with width 'bit_width' and reads them back.
+static void TestPutValue(int bit_width, uint64_t num_vals) {
+  const uint64_t max = uint64_t(2) << (bit_width - 1);
+  num_vals = std::min(num_vals, max);
+  int len = static_cast<int>(bit_util::BytesForBits(bit_width * num_vals));
+  EXPECT_GT(len, 0);
+
+  std::vector<uint8_t> buffer(len);
+  bit_util::BitWriter writer(buffer.data(), len);
+  for (uint64_t i = max - num_vals; i < max; i++) {
+    bool result = writer.PutValue(i, bit_width);
+    EXPECT_TRUE(result);
+  }
+  writer.Flush();
+  EXPECT_EQ(writer.bytes_written(), len);
+
+  bit_util::BitReader reader(buffer.data(), len);
+  for (uint64_t i = max - num_vals; i < max; i++) {
+    int64_t val = 0;
+    bool result = reader.GetValue(bit_width, &val);
+    EXPECT_TRUE(result);
+    EXPECT_EQ(val, i);
+  }
+  EXPECT_EQ(reader.bytes_left(), 0);
+}
+
+TEST(BitUtil, RoundTripIntValues) {
+  for (int width = 1; width < 64; width++) {

Review Comment:
   What do you mean? Testing that we are able to write 64-bit values makes 
sense.
   
   Perhaps you want something like:
   ```c++
     // The max value representable in `bit_width` bits.
     const uint64_t max = std::numeric_limits<uint64_t>::max() >> (64 - 
bit_width);
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to