bit_util_ut.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include <yql/essentials/public/udf/arrow/bit_util.h>
  3. #include <util/random/random.h>
  4. #include <arrow/util/bit_util.h>
  5. using namespace NYql::NUdf;
  6. namespace {
  7. void PerformTest(const ui8* testData, size_t offset, size_t length) {
  8. std::vector<ui8> copied(arrow::BitUtil::BytesForBits(length) + 1, 0);
  9. CopyDenseBitmap(copied.data(), testData, offset, length);
  10. std::vector<ui8> origSparse(length), copiedSparse(length);
  11. DecompressToSparseBitmap(origSparse.data(), testData, offset, length);
  12. DecompressToSparseBitmap(copiedSparse.data(), copied.data(), 0, length);
  13. for (size_t i = 0; i < length; i++) {
  14. UNIT_ASSERT_EQUAL_C(origSparse[i], copiedSparse[i], "Expected the same data");
  15. }
  16. }
  17. }
  18. Y_UNIT_TEST_SUITE(CopyDenseBitmapTest) {
  19. constexpr size_t testSize = 32;
  20. Y_UNIT_TEST(Test) {
  21. SetRandomSeed(0);
  22. std::vector<ui8> testData(testSize);
  23. for (size_t i = 0; i < testSize; i++) {
  24. testData[i] = RandomNumber<ui8>();
  25. }
  26. for (size_t offset = 0; offset < testSize * 8; offset++) {
  27. for (size_t length = 0; length <= testSize * 8 - offset; length++) {
  28. PerformTest(testData.data(), offset, length);
  29. }
  30. }
  31. }
  32. }