/*! * Copyright 2020 XGBoost contributors */ #ifndef XGBOOST_TEST_JSON_IO_H_ #define XGBOOST_TEST_JSON_IO_H_ #include #include #include #include "../helpers.h" #include "../../../src/gbm/gblinear_model.h" namespace xgboost { inline void TestUpdaterJsonIO(std::string updater_str) { auto runtime = xgboost::CreateEmptyGenericParam(GPUIDX); Json config_0 {Object() }; { auto updater = std::unique_ptr( xgboost::LinearUpdater::Create(updater_str, &runtime)); updater->Configure({{"eta", std::to_string(3.14)}}); updater->SaveConfig(&config_0); } { auto updater = std::unique_ptr( xgboost::LinearUpdater::Create(updater_str, &runtime)); updater->LoadConfig(config_0); Json config_1 { Object() }; updater->SaveConfig(&config_1); ASSERT_EQ(config_0, config_1); auto eta = atof(get(config_1["linear_train_param"]["eta"]).c_str()); ASSERT_NEAR(eta, 3.14, kRtEps); } } } // namespace xgboost #endif // XGBOOST_TEST_JSON_IO_H_