MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/parquet/statistics_test.cc:81–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81TEST(Comparison, SignedByteArray) {
82 // Signed byte array comparison is only used for Decimal comparison. When
83 // decimals are encoded as byte arrays they use twos complement big-endian
84 // encoded values. Comparisons of byte arrays of unequal types need to handle
85 // sign extension.
86 auto comparator = MakeComparator<ByteArrayType>(Type::BYTE_ARRAY, SortOrder::SIGNED);
87 struct Case {
88 std::vector<uint8_t> bytes;
89 int order;
90 ByteArray ToByteArray() const {
91 return ByteArray(static_cast<int>(bytes.size()), bytes.data());
92 }
93 };
94
95 // Test a mix of big-endian comparison values that are both equal and
96 // unequal after sign extension.
97 std::vector<Case> cases = {
98 {{0x80, 0x80, 0, 0}, 0}, {{/*0xFF,*/ 0x80, 0, 0}, 1},
99 {{0xFF, 0x80, 0, 0}, 1}, {{/*0xFF,*/ 0xFF, 0x01, 0}, 2},
100 {{/*0xFF, 0xFF,*/ 0x80, 0}, 3}, {{/*0xFF,*/ 0xFF, 0x80, 0}, 3},
101 {{0xFF, 0xFF, 0x80, 0}, 3}, {{/*0xFF,0xFF,0xFF,*/ 0x80}, 4},
102 {{/*0xFF, 0xFF, 0xFF,*/ 0xFF}, 5}, {{/*0, 0,*/ 0x01, 0x01}, 6},
103 {{/*0,*/ 0, 0x01, 0x01}, 6}, {{0, 0, 0x01, 0x01}, 6},
104 {{/*0,*/ 0x01, 0x01, 0}, 7}, {{0x01, 0x01, 0, 0}, 8}};
105
106 for (size_t x = 0; x < cases.size(); x++) {
107 const auto& case1 = cases[x];
108 // Empty array is always the smallest values
109 EXPECT_TRUE(comparator->Compare(ByteArray(), case1.ToByteArray())) << x;
110 EXPECT_FALSE(comparator->Compare(case1.ToByteArray(), ByteArray())) << x;
111 // Equals is always false.
112 EXPECT_FALSE(comparator->Compare(case1.ToByteArray(), case1.ToByteArray())) << x;
113
114 for (size_t y = 0; y < cases.size(); y++) {
115 const auto& case2 = cases[y];
116 if (case1.order < case2.order) {
117 EXPECT_TRUE(comparator->Compare(case1.ToByteArray(), case2.ToByteArray()))
118 << x << " (order: " << case1.order << ") " << y << " (order: " << case2.order
119 << ")";
120 } else {
121 EXPECT_FALSE(comparator->Compare(case1.ToByteArray(), case2.ToByteArray()))
122 << x << " (order: " << case1.order << ") " << y << " (order: " << case2.order
123 << ")";
124 }
125 }
126 }
127}
128
129TEST(Comparison, UnsignedByteArray) {
130 // Check if UTF-8 is compared using unsigned correctly

Callers

nothing calls this directly

Calls 15

ByteArrayClass · 0.85
ByteArrayFromStringFunction · 0.85
FLBAFromStringFunction · 0.85
Int96SetNanoSecondsFunction · 0.85
AssertStatsSetFunction · 0.85
AssertUnsetMinMaxFunction · 0.85
get_data_dirFunction · 0.85
OpenFileFunction · 0.85
ToByteArrayMethod · 0.80
emplace_backMethod · 0.80
push_backMethod · 0.80
strMethod · 0.80

Tested by

no test coverage detected