Fix empty subspan. (#4151)

* Silent the death tests.
This commit is contained in:
Jiaming Yuan
2019-02-17 04:48:03 +08:00
committed by GitHub
parent ff2d4c99fa
commit 1fe874e58a
3 changed files with 51 additions and 9 deletions

View File

@@ -419,5 +419,29 @@ TEST(Span, AsWritableBytes) {
ASSERT_EQ(status, 1);
}
TEST(Span, Empty) {
{
Span<float> s {nullptr, static_cast<Span<float>::index_type>(0)};
auto res = s.subspan(0);
ASSERT_EQ(res.data(), nullptr);
ASSERT_EQ(res.size(), 0);
res = s.subspan(0, 0);
ASSERT_EQ(res.data(), nullptr);
ASSERT_EQ(res.size(), 0);
}
{
Span<float, 0> s {nullptr, static_cast<Span<float>::index_type>(0)};
auto res = s.subspan(0);
ASSERT_EQ(res.data(), nullptr);
ASSERT_EQ(res.size(), 0);
res = s.subspan(0, 0);
ASSERT_EQ(res.data(), nullptr);
ASSERT_EQ(res.size(), 0);
}
}
} // namespace common
} // namespace xgboost