From a67bc6481905f7cc4c0a9551c32ea86815a66d85 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Wed, 17 Jun 2020 23:46:02 -0700 Subject: [PATCH] Add an option to run brute-force test for JSON round-trip (#5804) * Add an option to run brute-force test for JSON round-trip * Apply reviewer's feedback * Remove unneeded objects * Parallel run. * Max. * Use signed 64-bit loop var, to support MSVC * Add exhaustive test to CI * Run JSON test in Win build worker * Revert "Run JSON test in Win build worker" This reverts commit c97b2c7dda37b3585b445d36961605b79552ca89. * Revert "Add exhaustive test to CI" This reverts commit c149c2ce9971a07a7289f9b9bc247818afd5a667. Co-authored-by: fis --- tests/cpp/common/test_json.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/cpp/common/test_json.cc b/tests/cpp/common/test_json.cc index 6974b9f07..ba3b12e33 100644 --- a/tests/cpp/common/test_json.cc +++ b/tests/cpp/common/test_json.cc @@ -545,10 +545,32 @@ TEST(Json, RoundTrip) { } auto t = i; - i+= static_cast(dist(&rng)); + i += static_cast(dist(&rng)); if (i < t) { break; } } } + +TEST(Json, DISABLED_RoundTripExhaustive) { + auto test = [](uint32_t i) { + float f; + std::memcpy(&f, &i, sizeof(f)); + + Json jf{f}; + std::string str; + Json::Dump(jf, &str); + auto loaded = Json::Load({str.c_str(), str.size()}); + if (XGBOOST_EXPECT(std::isnan(f), false)) { + EXPECT_TRUE(std::isnan(get(loaded))); + } else { + EXPECT_EQ(get(loaded), f); + } + }; + int64_t int32_max = static_cast(std::numeric_limits::max()); +#pragma omp parallel for schedule(static) + for (int64_t i = 0; i <= int32_max; ++i) { + test(static_cast(i)); + } +} } // namespace xgboost