Extract make metric name from ranking metric. (#8768)

- Extract the metric parsing routine from ranking.
- Add a test.
- Accept null for string view.
This commit is contained in:
Jiaming Yuan
2023-02-09 18:30:21 +08:00
committed by GitHub
parent 4ead65a28c
commit 5f76edd296
9 changed files with 142 additions and 34 deletions

View File

@@ -1,9 +1,13 @@
/*!
* Copyright (c) by XGBoost Contributors 2021
/**
* Copyright 2021-2023 by XGBoost Contributors
*/
#include <gtest/gtest.h>
#include <xgboost/string_view.h>
#include <string_view>
#include <algorithm> // std::equal
#include <sstream> // std::stringstream
#include <string> // std::string
namespace xgboost {
TEST(StringView, Basic) {
StringView str{"This is a string."};
@@ -24,5 +28,16 @@ TEST(StringView, Basic) {
ASSERT_FALSE(substr == "i");
ASSERT_TRUE(std::equal(substr.crbegin(), substr.crend(), StringView{"si"}.cbegin()));
{
StringView empty{nullptr};
ASSERT_TRUE(empty.empty());
}
{
StringView empty{""};
ASSERT_TRUE(empty.empty());
StringView empty2{nullptr};
ASSERT_EQ(empty, empty2);
}
}
} // namespace xgboost