Skip to content

Commit 64b8f92

Browse files
committed
Better tests for ColumnArray::Slice for 2D arrays.
1 parent 7ef2752 commit 64b8f92

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

ut/column_array_ut.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ TEST(ColumnArray, Slice) {
134134
}
135135

136136
TEST(ColumnArray, Slice_2D) {
137+
// Verify that ColumnArray::Slice on 2D Array produces a 2D Array of proper type, size and contents.
138+
// Also check that slices can be of any size.
137139
const std::vector<std::vector<std::vector<uint64_t>>> values = {
138140
{{1u, 2u}, {3u}},
139141
{{4u}, {5u, 6u, 7u}, {8u, 9u}, {}},
@@ -144,14 +146,19 @@ TEST(ColumnArray, Slice_2D) {
144146

145147
std::shared_ptr<ColumnArray> untyped_array = Create2DArray<ColumnUInt64>(values);
146148
for (size_t i = 0; i < values.size() - 1; ++i) {
147-
auto slice = untyped_array->Slice(i, 1)->AsStrict<ColumnArray>();
148-
EXPECT_EQ(1u, slice->Size());
149-
150-
auto val = slice->GetAsColumnTyped<ColumnArray>(0);
151-
ASSERT_EQ(values[i].size(), val->Size());
152-
153-
for (size_t j = 0; j < values[i].size(); ++j) {
154-
ASSERT_TRUE(CompareRecursive(values[i][j], *val->GetAsColumnTyped<ColumnUInt64>(j)));
149+
for (size_t slice_size = 0; slice_size < values.size() - i; ++slice_size) {
150+
auto slice = untyped_array->Slice(i, slice_size)->AsStrict<ColumnArray>();
151+
EXPECT_EQ(slice_size, slice->Size());
152+
153+
for (size_t slice_row = 0; slice_row < slice_size; ++slice_row) {
154+
SCOPED_TRACE(::testing::Message() << "i: " << i << " slice_size:" << slice_size << " row:" << slice_row);
155+
auto val = slice->GetAsColumnTyped<ColumnArray>(slice_row);
156+
ASSERT_EQ(values[i + slice_row].size(), val->Size());
157+
158+
for (size_t j = 0; j < values[i + slice_row].size(); ++j) {
159+
ASSERT_TRUE(CompareRecursive(values[i + slice_row][j], *val->GetAsColumnTyped<ColumnUInt64>(j)));
160+
}
161+
}
155162
}
156163
}
157164
}

0 commit comments

Comments
 (0)