* Remove f-string, since it's not supported by Python 3.5 (#5330) * Remove f-string, since it's not supported by Python 3.5 * Add Python 3.5 to CI, to ensure compatibility * Remove duplicated matplotlib * Show deprecation notice for Python 3.5 * Fix lint * Fix lint * Fix a unit test that mistook MINOR ver for PATCH ver * Enforce only major version in JSON model schema * Bump version to 1.1.0-SNAPSHOT
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
/*!
|
|
* Copyright 2019 XGBoost contributors
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <dmlc/filesystem.h>
|
|
#include <dmlc/io.h>
|
|
|
|
#include <xgboost/version_config.h>
|
|
#include <xgboost/json.h>
|
|
#include <xgboost/base.h>
|
|
|
|
#include <string>
|
|
|
|
#include "../../../src/common/version.h"
|
|
|
|
namespace xgboost {
|
|
TEST(Version, Basic) {
|
|
Json j_ver { Object() };
|
|
Version::Save(&j_ver);
|
|
auto triplet { Version::Load(j_ver) };
|
|
ASSERT_TRUE(Version::Same(triplet));
|
|
|
|
dmlc::TemporaryDirectory tempdir;
|
|
const std::string fname = tempdir.path + "/version";
|
|
|
|
{
|
|
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(fname.c_str(), "w"));
|
|
Version::Save(fo.get());
|
|
}
|
|
|
|
{
|
|
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(fname.c_str(), "r"));
|
|
auto triplet { Version::Load(fi.get())};;
|
|
ASSERT_TRUE(Version::Same(triplet));
|
|
}
|
|
|
|
std::string str { Version::String(triplet) };
|
|
|
|
size_t ptr {0};
|
|
XGBoostVersionT v {0};
|
|
v = std::stoi(str, &ptr);
|
|
ASSERT_EQ(str.at(ptr), '.');
|
|
ASSERT_EQ(v, XGBOOST_VER_MAJOR) << "major: " << v;
|
|
|
|
str = str.substr(ptr+1);
|
|
|
|
ptr = 0;
|
|
v = std::stoi(str, &ptr);
|
|
ASSERT_EQ(str.at(ptr), '.');
|
|
ASSERT_EQ(v, XGBOOST_VER_MINOR) << "minor: " << v;;
|
|
|
|
str = str.substr(ptr+1);
|
|
|
|
ptr = 0;
|
|
v = std::stoi(str, &ptr);
|
|
ASSERT_EQ(v, XGBOOST_VER_PATCH) << "patch: " << v;;
|
|
|
|
str = str.substr(ptr);
|
|
ASSERT_EQ(str.size(), 0);
|
|
}
|
|
} // namespace xgboost
|