diff options
Diffstat (limited to 'tests/gtests/functions/FN_spans_test.cc')
-rw-r--r-- | tests/gtests/functions/FN_spans_test.cc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/gtests/functions/FN_spans_test.cc b/tests/gtests/functions/FN_spans_test.cc index 551918a3aae..59797f69309 100644 --- a/tests/gtests/functions/FN_spans_test.cc +++ b/tests/gtests/functions/FN_spans_test.cc @@ -71,6 +71,11 @@ TEST(virtual_span, EmptyConstructor) VSpan<int> span; EXPECT_EQ(span.size(), 0); EXPECT_TRUE(span.is_empty()); + EXPECT_FALSE(span.is_single_element()); + + GVSpan converted(span); + EXPECT_EQ(converted.type(), CPPType::get<int>()); + EXPECT_EQ(converted.size(), 0); } TEST(virtual_span, SpanConstructor) @@ -83,6 +88,11 @@ TEST(virtual_span, SpanConstructor) EXPECT_EQ(virtual_span[0], 7); EXPECT_EQ(virtual_span[2], 8); EXPECT_EQ(virtual_span[3], 6); + EXPECT_FALSE(virtual_span.is_single_element()); + + GVSpan converted(span); + EXPECT_EQ(converted.type(), CPPType::get<int>()); + EXPECT_EQ(converted.size(), 5); } TEST(virtual_span, PointerSpanConstructor) @@ -98,6 +108,14 @@ TEST(virtual_span, PointerSpanConstructor) EXPECT_EQ(span[1], 7); EXPECT_EQ(span[2], 6); EXPECT_EQ(&span[1], &x2); + EXPECT_FALSE(span.is_single_element()); + + GVSpan converted(span); + EXPECT_EQ(converted.type(), CPPType::get<int>()); + EXPECT_EQ(converted.size(), 3); + EXPECT_EQ(converted[0], &x0); + EXPECT_EQ(converted[1], &x2); + EXPECT_EQ(converted[2], &x1); } TEST(virtual_span, SingleConstructor) @@ -112,6 +130,14 @@ TEST(virtual_span, SingleConstructor) EXPECT_EQ(&span[0], &value); EXPECT_EQ(&span[1], &value); EXPECT_EQ(&span[2], &value); + EXPECT_TRUE(span.is_single_element()); + + GVSpan converted(span); + EXPECT_EQ(converted.type(), CPPType::get<int>()); + EXPECT_EQ(converted.size(), 3); + EXPECT_EQ(converted[0], &value); + EXPECT_EQ(converted[1], &value); + EXPECT_EQ(converted[2], &value); } TEST(generic_virtual_span, TypeConstructor) @@ -119,6 +145,10 @@ TEST(generic_virtual_span, TypeConstructor) GVSpan span(CPPType_int32); EXPECT_EQ(span.size(), 0); EXPECT_TRUE(span.is_empty()); + EXPECT_FALSE(span.is_single_element()); + + VSpan<int> converted = span.typed<int>(); + EXPECT_EQ(converted.size(), 0); } TEST(generic_virtual_span, GenericSpanConstructor) @@ -131,6 +161,21 @@ TEST(generic_virtual_span, GenericSpanConstructor) EXPECT_EQ(span[1], &values[1]); EXPECT_EQ(span[2], &values[2]); EXPECT_EQ(span[3], &values[3]); + EXPECT_FALSE(span.is_single_element()); + + int materialized[4] = {0}; + span.materialize_to_uninitialized(materialized); + EXPECT_EQ(materialized[0], 3); + EXPECT_EQ(materialized[1], 4); + EXPECT_EQ(materialized[2], 5); + EXPECT_EQ(materialized[3], 6); + + VSpan<int> converted = span.typed<int>(); + EXPECT_EQ(converted.size(), 4); + EXPECT_EQ(converted[0], 3); + EXPECT_EQ(converted[1], 4); + EXPECT_EQ(converted[2], 5); + EXPECT_EQ(converted[3], 6); } TEST(generic_virtual_span, SpanConstructor) @@ -142,6 +187,19 @@ TEST(generic_virtual_span, SpanConstructor) EXPECT_EQ(span[0], &values[0]); EXPECT_EQ(span[1], &values[1]); EXPECT_EQ(span[2], &values[2]); + EXPECT_FALSE(span.is_single_element()); + + int materialized[3] = {0}; + span.materialize_to_uninitialized(materialized); + EXPECT_EQ(materialized[0], 6); + EXPECT_EQ(materialized[1], 7); + EXPECT_EQ(materialized[2], 8); + + VSpan<int> converted = span.typed<int>(); + EXPECT_EQ(converted.size(), 3); + EXPECT_EQ(converted[0], 6); + EXPECT_EQ(converted[1], 7); + EXPECT_EQ(converted[2], 8); } TEST(generic_virtual_span, SingleConstructor) @@ -153,6 +211,20 @@ TEST(generic_virtual_span, SingleConstructor) EXPECT_EQ(span[0], &value); EXPECT_EQ(span[1], &value); EXPECT_EQ(span[2], &value); + EXPECT_TRUE(span.is_single_element()); + EXPECT_EQ(span.as_single_element(), &value); + + int materialized[3] = {0}; + span.materialize_to_uninitialized({1, 2}, materialized); + EXPECT_EQ(materialized[0], 0); + EXPECT_EQ(materialized[1], 5); + EXPECT_EQ(materialized[2], 5); + + VSpan<int> converted = span.typed<int>(); + EXPECT_EQ(converted.size(), 3); + EXPECT_EQ(converted[0], 5); + EXPECT_EQ(converted[1], 5); + EXPECT_EQ(converted[2], 5); } } // namespace fn |