aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/udf/arrow/ut/bit_util_ut.cpp
blob: 601d3be7c86a731ab4046438be177d9f6aa6e216 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <library/cpp/testing/unittest/registar.h>

#include <yql/essentials/public/udf/arrow/bit_util.h>
#include <util/random/random.h>

#include <arrow/util/bit_util.h>

using namespace NYql::NUdf;

namespace {
    void PerformTest(const ui8* testData, size_t offset, size_t length) {
        std::vector<ui8> copied(arrow::BitUtil::BytesForBits(length) + 1, 0);
        CopyDenseBitmap(copied.data(), testData, offset, length);

        std::vector<ui8> origSparse(length), copiedSparse(length);
        DecompressToSparseBitmap(origSparse.data(), testData, offset, length);
        DecompressToSparseBitmap(copiedSparse.data(), copied.data(), 0, length);
        for (size_t i = 0; i < length; i++) {
            UNIT_ASSERT_EQUAL_C(origSparse[i], copiedSparse[i], "Expected the same data");
        }
    }
}

Y_UNIT_TEST_SUITE(CopyDenseBitmapTest) {
    constexpr size_t testSize = 32;

    Y_UNIT_TEST(Test) {
        SetRandomSeed(0);

        std::vector<ui8> testData(testSize);
        for (size_t i = 0; i < testSize; i++) {
            testData[i] = RandomNumber<ui8>();
        }

        for (size_t offset = 0; offset < testSize * 8; offset++) {
            for (size_t length = 0; length <= testSize * 8 - offset; length++) {
                PerformTest(testData.data(), offset, length);
            }
        }
    }
}