aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/formats/ut_round.cpp
blob: 9070e0ef32e42242ce99a74e0642c70890473e02 (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
42
43
44
45
46
47
48
49
50
51
52
53
#include <cmath>
#include <cstdint>
#include <iterator>
#include <library/cpp/testing/unittest/registar.h>
#include <ctime>
#include <vector>
#include <algorithm>

#include <contrib/libs/apache/arrow/cpp/src/arrow/api.h>
#include <contrib/libs/apache/arrow/cpp/src/arrow/compute/api.h>

#include "func_common.h"
#include "functions.h"
#include "custom_registry.h"
#include "arrow_helpers.h"


namespace NKikimr::NArrow { 

namespace cp = ::arrow::compute;


Y_UNIT_TEST_SUITE(RoundsTest) {
    Y_UNIT_TEST(RoundTest) {
        for (auto ty : cp::internal::FloatingPointTypes()) {
            auto arg = NumVecToArray(ty, {2.34, 5.65, 10.01, 100.0});
            auto expRes = NumVecToArray(ty, {2, 6, 10, 100});
            auto res = arrow::compute::CallFunction(TRound::Name, {arg}, GetCustomExecContext());
            UNIT_ASSERT(res->Equals(expRes));
        }
    }

    Y_UNIT_TEST(RoundBankersTest) {
        for (auto ty : cp::internal::FloatingPointTypes()) {
            auto arg = NumVecToArray(ty, {2.34, 5.5, 6.5, 100.7});
            auto expRes = NumVecToArray(ty, {2, 6, 6, 101});
            auto res = arrow::compute::CallFunction(TRoundBankers::Name, {arg}, GetCustomExecContext());
            UNIT_ASSERT(res->Equals(expRes));
        }
    }

    Y_UNIT_TEST(RoundToExp2Test) {
        for (auto ty : cp::internal::NumericTypes()) {
            auto arg = NumVecToArray(ty, {2.34, 5.5, 6.5, 100.7, 54});
            auto expRes = NumVecToArray(ty, {2, 4, 4, 64, 32});
            auto res = arrow::compute::CallFunction(TRoundToExp2::Name, {arg}, GetCustomExecContext());
            UNIT_ASSERT(res->Equals(expRes));
        }
    }

}

}