summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/mkql_saturated_math_ut.cpp
blob: 0eefb20e783bd792ccfe4b4ac81b8f5364563f78 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include "mkql_saturated_math.h"

#include <library/cpp/testing/unittest/registar.h>
#include <limits>

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<ui32>::max(), 1U, std::numeric_limits<ui32>::max()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<ui32>::max(), 1U, 0U));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<ui32>::max(), 1U, 100U));

    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<ui32>::max(), 1U, std::numeric_limits<ui32>::max()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<ui32>::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<i32>::min(), 1, std::numeric_limits<i32>::min()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i32>::min(), 1, 0));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i32>::min(), 1, std::numeric_limits<i32>::min() + 1));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<i32>::min(), 1, std::numeric_limits<i32>::min()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<i32>::min(), 1, 0));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<i32>::min(), 1, std::numeric_limits<i32>::max()));
}

Y_UNIT_TEST(IsBelongToInterval_BoundaryValues_ui64) {
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<ui64>::max(), ui64(0), std::numeric_limits<ui64>::max()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<ui64>::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<ui64>::max(), ui64(0), std::numeric_limits<ui64>::max()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<ui64>::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<i64>::max(), i64(0), std::numeric_limits<i64>::max())));
    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<i64>::max(), i64(0), i64(0))));
    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<i64>::max(), i64(0), std::numeric_limits<i64>::min())));

    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i64>::min(), i64(0), std::numeric_limits<i64>::min())));
    UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i64>::min(), i64(0), std::numeric_limits<i64>::min() + 1)));

    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<i64>::max(), i64(0), std::numeric_limits<i64>::max())));
    UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<i64>::max(), i64(0), i64(0))));
    UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<i64>::max(), i64(0), std::numeric_limits<i64>::min())));

    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<i64>::min(), i64(0), std::numeric_limits<i64>::min())));
    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<i64>::min(), i64(0), std::numeric_limits<i64>::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<float>::max(), 5.F, std::numeric_limits<float>::max()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<float>::max(), 0.0F, 0.0F));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<float>::lowest(), 0.0F, std::numeric_limits<float>::lowest()));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<float>::max(), 7.0, std::numeric_limits<float>::max()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<float>::max(), 0.0F, 0.0F));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<float>::lowest(), 0.0F, std::numeric_limits<float>::lowest()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<float>::lowest(), 0.0F, 0.0F));
}

Y_UNIT_TEST(IsBelongToInterval_Double_BoundaryValues) {
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<double>::max(), 0.0, std::numeric_limits<double>::max()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<double>::max(), 0.0, 0.0));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<double>::lowest(), 0.0, std::numeric_limits<double>::lowest()));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<double>::max(), 0.0, std::numeric_limits<double>::max()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<double>::max(), 0.0, 0.0));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<double>::lowest(), 0.0, std::numeric_limits<double>::lowest()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Preceding, std::numeric_limits<double>::lowest(), 0.0, 0.0));

    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::infinity()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::infinity()));
    UNIT_ASSERT(!IsBelongToInterval(EInfBoundary::Right, EDirection::Following, std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()));
    UNIT_ASSERT(IsBelongToInterval(EInfBoundary::Left, EDirection::Following, std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::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<i64>::max(), std::numeric_limits<ui32>::max(), std::numeric_limits<i64>::max())));
    UNIT_ASSERT(!(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i64>::min(), std::numeric_limits<ui32>::max(), std::numeric_limits<i64>::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<i16>::max(), std::numeric_limits<ui64>::max(), std::numeric_limits<i16>::max())));
    UNIT_ASSERT(!(IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i16>::min(), std::numeric_limits<ui64>::max(), std::numeric_limits<i16>::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<float>::max(), std::numeric_limits<i32>::max(), std::numeric_limits<float>::max())));
    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<float>::lowest(), std::numeric_limits<i32>::max(), std::numeric_limits<float>::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<i32>::max(), std::numeric_limits<float>::max(), std::numeric_limits<i32>::max())));
    UNIT_ASSERT((!IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<i32>::min(), std::numeric_limits<float>::max(), std::numeric_limits<i32>::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<double>::max(), std::numeric_limits<float>::max(), std::numeric_limits<double>::max())));
    UNIT_ASSERT((IsBelongToInterval(EInfBoundary::Left, EDirection::Preceding, std::numeric_limits<double>::lowest(), std::numeric_limits<float>::max(), std::numeric_limits<double>::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