| 285 | } |
| 286 | |
| 287 | void CheckArray(const Array& array) { |
| 288 | ASSERT_OK(array.ValidateFull()); |
| 289 | |
| 290 | const auto& type = checked_cast<const DecimalType&>(*array.type()); |
| 291 | const auto& values = checked_cast<const ArrayType&>(array); |
| 292 | |
| 293 | const DecimalValue limit = DecimalValue::GetScaleMultiplier(type.precision()); |
| 294 | const DecimalValue neg_limit = DecimalValue(limit).Negate(); |
| 295 | const DecimalValue half_limit = limit / DecimalValue(2); |
| 296 | const DecimalValue neg_half_limit = DecimalValue(half_limit).Negate(); |
| 297 | |
| 298 | // Check that random-generated values: |
| 299 | // - satisfy the requested precision |
| 300 | // - at least sometimes are close to the max allowable values for precision |
| 301 | // - sometimes are negative |
| 302 | int64_t non_nulls = 0; |
| 303 | int64_t over_half = 0; |
| 304 | int64_t negative = 0; |
| 305 | |
| 306 | for (int64_t i = 0; i < values.length(); ++i) { |
| 307 | if (values.IsNull(i)) { |
| 308 | continue; |
| 309 | } |
| 310 | ++non_nulls; |
| 311 | const DecimalValue value(values.GetValue(i)); |
| 312 | ASSERT_LT(value, limit); |
| 313 | ASSERT_GT(value, neg_limit); |
| 314 | if (value >= half_limit || value <= neg_half_limit) { |
| 315 | ++over_half; |
| 316 | } |
| 317 | if (value.Sign() < 0) { |
| 318 | ++negative; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | ASSERT_GE(over_half, non_nulls * 0.3); |
| 323 | ASSERT_LE(over_half, non_nulls * 0.7); |
| 324 | ASSERT_GE(negative, non_nulls * 0.3); |
| 325 | ASSERT_LE(negative, non_nulls * 0.7); |
| 326 | } |
| 327 | }; |
| 328 | |
| 329 | using DecimalTypes = |
no test coverage detected