#include "mkql_saturated_math.h" #include #include namespace NKikimr::NMiniKQL { Y_UNIT_TEST_SUITE(SaturatedMathTest) { Y_UNIT_TEST(IsBelongToInterval_RightDirection_Normal) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10, 5, 15)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10, 5, 10)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10, 5, 0)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10, 5, 16)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10, 5, 15)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10, 5, 16)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10, 5, 14)); } Y_UNIT_TEST(IsBelongToInterval_RightDirection_Overflow) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 1U, std::numeric_limits::max())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 1U, 0U)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 1U, 100U)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 1U, std::numeric_limits::max())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 1U, 0U)); } Y_UNIT_TEST(IsBelongToInterval_LeftDirection_Normal) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10, 5, 5)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10, 5, 0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10, 5, -100)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10, 5, 6)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10, 5, 10)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10, 5, 5)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10, 5, 10)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10, 5, 4)); } Y_UNIT_TEST(IsBelongToInterval_LeftDirection_Underflow_Unsigned) { UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 5U, 10U, 0U)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 5U, 10U, 1U)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 5U, 10U, 0U)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 5U, 10U, 100U)); } Y_UNIT_TEST(IsBelongToInterval_LeftDirection_Underflow_Signed) { UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), 1, std::numeric_limits::min())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), 1, 0)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), 1, std::numeric_limits::min() + 1)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::min(), 1, std::numeric_limits::min())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::min(), 1, 0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::min(), 1, std::numeric_limits::max())); } Y_UNIT_TEST(IsBelongToInterval_BoundaryValues_ui64) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), ui64(0), std::numeric_limits::max())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), ui64(0), ui64(0))); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 0UL, 0UL, 0UL)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 0UL, 0UL, 1UL)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), ui64(0), std::numeric_limits::max())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), ui64(0), ui64(0))); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 0UL, 0UL, 0UL)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 0UL, 0UL, 1UL)); } Y_UNIT_TEST(IsBelongToInterval_BoundaryValues_i64) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), i64(0), std::numeric_limits::max()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), i64(0), i64(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), i64(0), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), i64(0), std::numeric_limits::min()))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), i64(0), std::numeric_limits::min() + 1))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), i64(0), std::numeric_limits::max()))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), i64(0), i64(0)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), i64(0), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::min(), i64(0), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::min(), i64(0), std::numeric_limits::min() + 1))); } Y_UNIT_TEST(IsBelongToInterval_Float) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0F, 5.0F, 15.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0F, 5.0F, 10.0F)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0F, 5.0F, 15.1F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0F, 5.0F, 5.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0F, 5.0F, 0.0F)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0F, 5.0F, 5.1F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0F, 5.0F, 15.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0F, 5.0F, 15.1F)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0F, 5.0F, 14.9F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0F, 5.0F, 5.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0F, 5.0F, 5.1F)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0F, 5.0F, 4.9F)); } Y_UNIT_TEST(IsBelongToInterval_Double) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0, 5.0, 15.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0, 5.0, 10.0)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0, 5.0, 15.1)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0, 5.0, 5.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0, 5.0, 0.0)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0, 5.0, 5.1)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0, 15.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0, 15.1)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0, 14.9)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0, 5.0, 5.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0, 5.0, 5.1)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0, 5.0, 4.9)); } Y_UNIT_TEST(IsBelongToInterval_Float_BoundaryValues) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 5.F, std::numeric_limits::max())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 0.0F, 0.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::lowest(), 0.0F, std::numeric_limits::lowest())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 7.0, std::numeric_limits::max())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 0.0F, 0.0F)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::lowest(), 0.0F, std::numeric_limits::lowest())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::lowest(), 0.0F, 0.0F)); } Y_UNIT_TEST(IsBelongToInterval_Double_BoundaryValues) { UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 0.0, std::numeric_limits::max())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), 0.0, 0.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::lowest(), 0.0, std::numeric_limits::lowest())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 0.0, std::numeric_limits::max())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), 0.0, 0.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::lowest(), 0.0, std::numeric_limits::lowest())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits::lowest(), 0.0, 0.0)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::infinity())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::infinity())); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max())); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max())); } Y_UNIT_TEST(IsBelongToInterval_MixedTypes_i64_ui32) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i64(1000000000000LL), ui32(500), i64(1000000000500LL)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i64(1000000000000LL), ui32(500), i64(1000000000501LL)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i64(1000000000000LL), ui32(500), i64(999999999500LL)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i64(-100), ui32(50), i64(-50)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i64(-100), ui32(50), i64(-49)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i64(-100), ui32(50), i64(-150)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()))); UNIT_ASSERT(!(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), std::numeric_limits::max(), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i64(0), ui32(0), i64(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i64(0), ui32(0), i64(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i64(1000000000000LL), ui32(500), i64(1000000000500LL)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i64(1000000000000LL), ui32(500), i64(1000000000501LL)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i64(1000000000000LL), ui32(500), i64(1000000000499LL)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i64(1000000000000LL), ui32(500), i64(999999999500LL)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i64(1000000000000LL), ui32(500), i64(999999999499LL)))); } Y_UNIT_TEST(IsBelongToInterval_MixedTypes_i16_ui64) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i16(100), ui64(50), i16(150)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i16(100), ui64(50), i16(151)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i16(100), ui64(50), i16(50)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i16(-50), ui64(100), i16(50)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i16(-50), ui64(100), i16(-150)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()))); UNIT_ASSERT(!(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), std::numeric_limits::max(), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i16(0), ui64(0), i16(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i16(0), ui64(0), i16(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i16(100), ui64(50), i16(150)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i16(100), ui64(50), i16(151)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i16(100), ui64(50), i16(149)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i16(100), ui64(50), i16(50)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i16(100), ui64(50), i16(49)))); } Y_UNIT_TEST(IsBelongToInterval_MixedTypes_float_i32) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.5F, i32(5), 15.5F))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.5F, i32(5), 15.6F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.5F, i32(5), 5.5F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, -10.5F, i32(5), -5.5F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, -10.5F, i32(5), -15.5F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::lowest(), std::numeric_limits::max(), std::numeric_limits::lowest()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 0.0F, i32(0), 0.0F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 0.0F, i32(0), 0.0F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.5F, i32(5), 15.5F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.5F, i32(5), 15.6F))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.5F, i32(5), 15.4F))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.5F, i32(5), 5.5F))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.5F, i32(5), 5.4F))); } Y_UNIT_TEST(IsBelongToInterval_MixedTypes_i32_float) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i32(10), 5.5F, i32(15)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i32(10), 5.5F, i32(16)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i32(10), 5.5F, i32(5)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i32(-10), 5.5F, i32(-5)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i32(-10), 5.5F, i32(-15)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::min(), std::numeric_limits::max(), std::numeric_limits::min()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, i32(0), 0.0F, i32(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, i32(0), 0.0F, i32(0)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i32(10), 5.5F, i32(16)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, i32(10), 5.5F, i32(15)))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i32(10), 5.5F, i32(5)))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, i32(10), 5.5F, i32(4)))); } Y_UNIT_TEST(IsBelongToInterval_MixedTypes_double_float) { UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0, 5.0F, 15.0))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 10.0, 5.0F, 15.1))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 10.0, 5.0F, 5.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, -10.0, 5.0F, -5.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, -10.0, 5.0F, -15.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits::lowest(), std::numeric_limits::max(), std::numeric_limits::lowest()))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, 0.0, 0.0F, 0.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, 0.0, 0.0F, 0.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0F, 15.0))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0F, 15.1))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, 10.0, 5.0F, 14.9))); UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0, 5.0F, 5.0))); UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, 10.0, 5.0F, 4.9))); } Y_UNIT_TEST(IsBelongToInterval_Decimal_NormalNumbers) { using T = NYql::NDecimal::TInt128; const ui8 prec = 10; UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(10), T(5), T(15), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(10), T(5), T(16), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(10), T(5), T(14), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(10), T(5), T(15), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(10), T(5), T(0), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(10), T(5), T(16), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(10), T(5), T(5), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(10), T(5), T(10), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(10), T(5), T(4), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(10), T(5), T(5), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(10), T(5), T(-100), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(10), T(5), T(6), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(-10), T(5), T(-5), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(-10), T(5), T(-6), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(-10), T(5), T(-15), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(-10), T(5), T(-16), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(7), T(0), T(7), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(7), T(0), T(7), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(7), T(0), T(6), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(7), T(0), T(8), prec)); } Y_UNIT_TEST(IsBelongToInterval_Decimal_InfiniteFrom) { using T = NYql::NDecimal::TInt128; const ui8 prec = 10; UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, NYql::NDecimal::Inf(), T(5), T(100), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, NYql::NDecimal::Inf(), T(5), T(100), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, NYql::NDecimal::Inf(), T(5), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, -NYql::NDecimal::Inf(), T(5), T(100), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, -NYql::NDecimal::Inf(), T(5), -NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, -NYql::NDecimal::Inf(), T(5), T(100), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, -NYql::NDecimal::Inf(), T(5), -NYql::NDecimal::Inf(), prec)); } Y_UNIT_TEST(IsBelongToInterval_Decimal_InfiniteX) { using T = NYql::NDecimal::TInt128; const ui8 prec = 10; UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(10), T(5), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(10), T(5), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(10), T(5), -NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(10), T(5), -NYql::NDecimal::Inf(), prec)); } Y_UNIT_TEST(IsBelongToInterval_Decimal_BoundaryBecomesInfinite) { using T = NYql::NDecimal::TInt128; const ui8 prec = 5; UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, T(99998), T(3), T(99999), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(99998), T(3), T(99999), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, T(99998), T(3), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, T(-99998), T(3), T(-99999), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(-99998), T(3), T(-99999), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, T(-99998), T(3), -NYql::NDecimal::Inf(), prec)); } Y_UNIT_TEST(IsBelongToInterval_Decimal_InfinityIsStable) { using T = NYql::NDecimal::TInt128; const ui8 prec = 10; UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, NYql::NDecimal::Inf(), T(99999), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, NYql::NDecimal::Inf(), T(99999), T(0), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, -NYql::NDecimal::Inf(), T(99999), -NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, -NYql::NDecimal::Inf(), T(99999), T(0), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, NYql::NDecimal::Inf(), T(0), NYql::NDecimal::Inf(), prec)); UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, NYql::NDecimal::Inf(), T(0), NYql::NDecimal::Inf(), prec)); } } // Y_UNIT_TEST_SUITE(SaturatedMathTest) } // namespace NKikimr::NMiniKQL