diff options
author | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:00:23 +0300 |
---|---|---|
committer | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:12:13 +0300 |
commit | a784a2f943d6e15caa6241e2e96d80aac6dbf375 (patch) | |
tree | 05f1e5366c916b988a8afb75bdab8ddeee0f6e6d /yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp | |
parent | d70137a7b530ccaa52834274913bbb5a3d1ca06e (diff) | |
download | ydb-a784a2f943d6e15caa6241e2e96d80aac6dbf375.tar.gz |
Move yql/udfs/common/ to /yql/essentials YQL-19206
Except the following directories:
* clickhouse/client
* datetime
* knn
* roaring
commit_hash:c7da95636144d28db109d6b17ddc762e9bacb59f
Diffstat (limited to 'yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp')
-rw-r--r-- | yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp b/yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp new file mode 100644 index 0000000000..8388c110f3 --- /dev/null +++ b/yql/essentials/udfs/common/python/bindings/py_decimal_ut.cpp @@ -0,0 +1,122 @@ +#include "ut3/py_test_engine.h" + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NPython; + +Y_UNIT_TEST_SUITE(TPyDecimalTest) { + Y_UNIT_TEST(FromPyZero) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TDecimalDataType<12,5>>( + R"( +from decimal import Decimal +def Test(): return Decimal() + )", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT(!value.GetInt128()); + }); + } + + Y_UNIT_TEST(FromPyPi) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TDecimalDataType<28,18>>( + R"( +from decimal import Decimal +def Test(): return Decimal('3.141592653589793238') + )", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT(value.GetInt128() == 3141592653589793238LL); + }); + } + + Y_UNIT_TEST(FromPyTini) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TDecimalDataType<35,35>>( + R"( +from decimal import Decimal +def Test(): return Decimal('-.00000000000000000000000000000000001') + )", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT(value.GetInt128() == -1); + }); + } + + Y_UNIT_TEST(FromPyNan) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TDecimalDataType<35,34>>( + R"( +from decimal import Decimal +def Test(): return Decimal('NaN') + )", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT(value.GetInt128() == NYql::NDecimal::Nan()); + }); + } + + Y_UNIT_TEST(FromPyInf) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TDecimalDataType<35,34>>( + R"( +from decimal import Decimal +def Test(): return Decimal('-inf') + )", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT(value.GetInt128() == -NYql::NDecimal::Inf()); + }); + } + + Y_UNIT_TEST(ToPyZero) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TDecimalDataType<7,7>>( + [](const TType*, const NUdf::IValueBuilder&) { + return NUdf::TUnboxedValuePod::Zero(); + }, + "def Test(value): assert value.is_zero()" + ); + } + + Y_UNIT_TEST(ToPyPi) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TDecimalDataType<20,18>>( + [](const TType*, const NUdf::IValueBuilder&) { + return NUdf::TUnboxedValuePod(NYql::NDecimal::TInt128(3141592653589793238LL)); + }, + "def Test(value): assert str(value) == '3.141592653589793238'" + ); + } + + Y_UNIT_TEST(ToPyTini) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TDecimalDataType<35,35>>( + [](const TType*, const NUdf::IValueBuilder&) { + return NUdf::TUnboxedValuePod(NYql::NDecimal::TInt128(-1)); + }, + "def Test(value): assert format(value, '.35f') == '-0.00000000000000000000000000000000001'" + ); + } + + Y_UNIT_TEST(ToPyNan) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TDecimalDataType<2,2>>( + [](const TType*, const NUdf::IValueBuilder&) { + return NUdf::TUnboxedValuePod(NYql::NDecimal::Nan()); + }, + "def Test(value): assert value.is_nan()" + ); + } + + Y_UNIT_TEST(ToPyInf) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TDecimalDataType<30,0>>( + [](const TType*, const NUdf::IValueBuilder&) { + return NUdf::TUnboxedValuePod(-NYql::NDecimal::Inf()); + }, + "def Test(value): assert value.is_infinite() and value.is_signed()" + ); + } +} |