Repository: apache/arrow
File: cpp/src/parquet/encoding_test.cc (C++)

Code before:
  const auto encoder = MakeTypedEncoder<TypeParam>(
      Encoding::DELTA_BINARY_PACKED, /*use_dictionary=*/false, this->descr_.get());
  encoder->Put(int_values, num_values);
  const auto encoded = encoder->FlushValues();

  ASSERT_EQ(encoded->size(), encoded_size);
}

TYPED_TEST(TestDeltaBitPackEncoding, ZeroDeltaBitWidth) {
  // Exercise ranges of zero deltas interspersed between ranges of non-zero deltas.
  // This checks that the zero bit-width optimization in GH-49266 doesn't mess
  // decoder state.
  using T = typename TypeParam::c_type;

  // At least the size of a block
  constexpr int kRangeSize = 256;

  std::vector<T> int_values;
  for (int i = 0; i < kRangeSize; ++i) {
    int_values.push_back((i * 7) % 11);
  }
  // Range of equal values, should emit zero-width deltas
  for (int i = 0; i < kRangeSize * 2; ++i) {
    int_values.push_back(42);
  }
  // int_values.insert(int_values.end(), /*count=*/kRangeSize * k, /*value=*/42);
  for (int i = 0; i < kRangeSize; ++i) {
    int_values.push_back((i * 5) % 7);
  }
  this->CheckRoundtripWithValues(int_values);
}

// ----------------------------------------------------------------------
// Rle for Boolean encode/decode tests.

class TestRleBooleanEncoding : public TestEncodingBase<BooleanType> {
 public:
  using c_type = bool;
  static constexpr int TYPE = Type::BOOLEAN;

  virtual void CheckRoundtrip() {
    auto encoder = MakeTypedEncoder<BooleanType>(Encoding::RLE,
                                                 /*use_dictionary=*/false, descr_.get());
    auto decoder = MakeTypedDecoder<BooleanType>(Encoding::RLE, descr_.get());

    for (int i = 0; i < 3; ++i) {
      encoder->Put(draws_, num_values_);
      encode_buffer_ = encoder->FlushValues();

      decoder->SetData(num_values_, encode_buffer_->data(),
                       static_cast<int>(encode_buffer_->size()));

Review comment (suggestion):
This commented-out line should be removed. It appears to be leftover code from development that was replaced by the explicit loop above.
```suggestion

```

Code after:
  const auto encoder = MakeTypedEncoder<TypeParam>(
      Encoding::DELTA_BINARY_PACKED, /*use_dictionary=*/false, this->descr_.get());
  encoder->Put(int_values, num_values);
  const auto encoded = encoder->FlushValues();

  ASSERT_EQ(encoded->size(), encoded_size);
}

TYPED_TEST(TestDeltaBitPackEncoding, ZeroDeltaBitWidth) {
  // Exercise ranges of zero deltas interspersed between ranges of non-zero deltas.
  // This checks that the zero bit-width optimization in GH-49266 doesn't mess
  // decoder state.
  using T = typename TypeParam::c_type;

  // At least the size of a block
  constexpr int kRangeSize = 256;

  std::vector<T> int_values;
  for (int i = 0; i < kRangeSize; ++i) {
    int_values.push_back((i * 7) % 11);
  }
  // Range of equal values, should emit zero-width deltas
  for (int i = 0; i < kRangeSize * 2; ++i) {
    int_values.push_back(42);
  }
  for (int i = 0; i < kRangeSize; ++i) {
    int_values.push_back((i * 5) % 7);
  }
  this->CheckRoundtripWithValues(int_values);
}

// ----------------------------------------------------------------------
// Rle for Boolean encode/decode tests.

class TestRleBooleanEncoding : public TestEncodingBase<BooleanType> {
 public:
  using c_type = bool;
  static constexpr int TYPE = Type::BOOLEAN;

  virtual void CheckRoundtrip() {
    auto encoder = MakeTypedEncoder<BooleanType>(Encoding::RLE,
                                                 /*use_dictionary=*/false, descr_.get());
    auto decoder = MakeTypedDecoder<BooleanType>(Encoding::RLE, descr_.get());

    for (int i = 0; i < 3; ++i) {
      encoder->Put(draws_, num_values_);
      encode_buffer_ = encoder->FlushValues();

      decoder->SetData(num_values_, encode_buffer_->data(),
                       static_cast<int>(encode_buffer_->size()));
      int values_decoded = decoder->Decode(decode_buf_, num_values_);