|
| 1 | +#include <ydb/core/scheme/scheme_tabledefs.h> |
| 2 | + |
| 3 | +#include <ydb/core/scheme_types/scheme_types.h> |
| 4 | + |
| 5 | +#include <library/cpp/testing/unittest/registar.h> |
| 6 | + |
| 7 | +#include <util/generic/vector.h> |
| 8 | + |
| 9 | +namespace NKikimr { |
| 10 | + |
| 11 | +Y_UNIT_TEST_SUITE(SchemeRanges) { |
| 12 | + |
| 13 | + TVector<NScheme::TTypeInfo> MakeTypes(size_t keysCount) { |
| 14 | + TVector<NScheme::TTypeInfo> types; |
| 15 | + types.reserve(keysCount); |
| 16 | + for (size_t i = 0; i < keysCount; ++i) { |
| 17 | + types.push_back(NScheme::TTypeInfo(NScheme::NTypeIds::Uint32)); |
| 18 | + } |
| 19 | + return types; |
| 20 | + } |
| 21 | + |
| 22 | + TCell MakeUi32(ui32 key) { |
| 23 | + return TCell::Make(ui32(key)); |
| 24 | + } |
| 25 | + |
| 26 | + TCell MakeNull() { |
| 27 | + return TCell(); |
| 28 | + } |
| 29 | + |
| 30 | + Y_UNIT_TEST(RangesBorders) { |
| 31 | + auto types = MakeTypes(1); |
| 32 | + |
| 33 | + for (ui32 flags = 0; flags < (1 << 4); ++flags) { |
| 34 | + TVector<TCell> firstLeft = {MakeUi32(1)}; |
| 35 | + TVector<TCell> firstRight = {MakeUi32(10)}; |
| 36 | + TVector<TCell> secondLeft = {MakeUi32(1)}; |
| 37 | + TVector<TCell> sedondRight = {MakeUi32(10)}; |
| 38 | + TTableRange first(firstLeft, ((flags >> 0) & 1), firstRight, ((flags >> 1) & 1)); |
| 39 | + TTableRange second(secondLeft, ((flags >> 2) & 1), sedondRight, ((flags >> 3) & 1)); |
| 40 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), 0); |
| 41 | + } |
| 42 | + |
| 43 | + TVector<TCell> firstLeft = {MakeUi32(1)}; |
| 44 | + TVector<TCell> firstRight = {MakeUi32(10)}; |
| 45 | + TVector<TCell> secondLeft = {MakeUi32(10)}; |
| 46 | + TVector<TCell> sedondRight = {MakeUi32(100)}; |
| 47 | + |
| 48 | + { |
| 49 | + TTableRange first(firstLeft, true, firstRight, true); |
| 50 | + TTableRange second(secondLeft, true, sedondRight, true); |
| 51 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), 0); |
| 52 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 0); |
| 53 | + } |
| 54 | + |
| 55 | + { |
| 56 | + TTableRange first(firstLeft, true, firstRight, false); |
| 57 | + TTableRange second(secondLeft, true, sedondRight, true); |
| 58 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 59 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + TTableRange first(firstLeft, true, firstRight, true); |
| 64 | + TTableRange second(secondLeft, false, sedondRight, true); |
| 65 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 66 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 67 | + } |
| 68 | + |
| 69 | + { |
| 70 | + TTableRange first(firstLeft, true, firstRight, false); |
| 71 | + TTableRange second(secondLeft, false, sedondRight, true); |
| 72 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 73 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 74 | + } |
| 75 | + |
| 76 | + { |
| 77 | + TTableRange first(firstLeft, false, firstRight, false); |
| 78 | + TTableRange second(secondLeft, false, sedondRight, false); |
| 79 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 80 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 81 | + } |
| 82 | + |
| 83 | + { |
| 84 | + TTableRange first(firstLeft, false, firstRight, true); |
| 85 | + TTableRange second(secondLeft, false, sedondRight, false); |
| 86 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 87 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 88 | + } |
| 89 | + |
| 90 | + { |
| 91 | + TTableRange first(firstLeft, false, firstRight, false); |
| 92 | + TTableRange second(secondLeft, true, sedondRight, false); |
| 93 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), -1); |
| 94 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 1); |
| 95 | + } |
| 96 | + |
| 97 | + { |
| 98 | + TTableRange first(firstLeft, false, firstRight, true); |
| 99 | + TTableRange second(secondLeft, true, sedondRight, false); |
| 100 | + UNIT_ASSERT_EQUAL(CompareRanges(first, second, types), 0); |
| 101 | + UNIT_ASSERT_EQUAL(CompareRanges(second, first, types), 0); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + Y_UNIT_TEST(CmpBorders) { |
| 106 | + auto types = MakeTypes(1); |
| 107 | + |
| 108 | + TVector<TCell> b1 = {MakeUi32(1)}; |
| 109 | + TVector<TCell> b10 = {MakeUi32(10)}; |
| 110 | + TVector<TCell> b100 = {MakeUi32(100)}; |
| 111 | + |
| 112 | + for (ui32 flags = 0; flags < (1 << 2); ++flags) { |
| 113 | + UNIT_ASSERT_EQUAL((CompareBorders<false, true>(b1, b10, ((flags >> 0) & 1), ((flags >> 1) & 1), types)), -1); |
| 114 | + UNIT_ASSERT_EQUAL((CompareBorders<true, false>(b100, b10, ((flags >> 0) & 1), ((flags >> 1) & 1), types)), 1); |
| 115 | + } |
| 116 | + |
| 117 | + UNIT_ASSERT_EQUAL((CompareBorders<true, true>(b10, b10, true, true, types)), 0); |
| 118 | + UNIT_ASSERT_EQUAL((CompareBorders<true, true>(b10, b10, false, true, types)), -1); |
| 119 | + UNIT_ASSERT_EQUAL((CompareBorders<true, true>(b10, b10, true, false, types)), 1); |
| 120 | + UNIT_ASSERT_EQUAL((CompareBorders<true, true>(b10, b10, false, false, types)), 0); |
| 121 | + |
| 122 | + UNIT_ASSERT_EQUAL((CompareBorders<false, false>(b10, b10, true, true, types)), 0); |
| 123 | + UNIT_ASSERT_EQUAL((CompareBorders<false, false>(b10, b10, false, true, types)), 1); |
| 124 | + UNIT_ASSERT_EQUAL((CompareBorders<false, false>(b10, b10, true, false, types)), -1); |
| 125 | + UNIT_ASSERT_EQUAL((CompareBorders<false, false>(b10, b10, false, false, types)), 0); |
| 126 | + |
| 127 | + UNIT_ASSERT_EQUAL((CompareBorders<true, false>(b10, b10, true, true, types)), 0); |
| 128 | + UNIT_ASSERT_EQUAL((CompareBorders<true, false>(b10, b10, false, true, types)), -1); |
| 129 | + UNIT_ASSERT_EQUAL((CompareBorders<true, false>(b10, b10, true, false, types)), -1); |
| 130 | + UNIT_ASSERT_EQUAL((CompareBorders<true, false>(b10, b10, false, false, types)), -1); |
| 131 | + |
| 132 | + UNIT_ASSERT_EQUAL((CompareBorders<false, true>(b10, b10, true, true, types)), 0); |
| 133 | + UNIT_ASSERT_EQUAL((CompareBorders<false, true>(b10, b10, false, true, types)), 1); |
| 134 | + UNIT_ASSERT_EQUAL((CompareBorders<false, true>(b10, b10, true, false, types)), 1); |
| 135 | + UNIT_ASSERT_EQUAL((CompareBorders<false, true>(b10, b10, false, false, types)), 1); |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +} |
0 commit comments