Skip to content

Commit

Permalink
Add an option to run brute-force test for JSON round-trip (#5804)
Browse files Browse the repository at this point in the history
* 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 c97b2c7.

* Revert "Add exhaustive test to CI"

This reverts commit c149c2c.

Co-authored-by: fis <jm.yuan@outlook.com>
  • Loading branch information
hcho3 and trivialfis authored Jun 18, 2020
1 parent abdf894 commit a67bc64
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/cpp/common/test_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,32 @@ TEST(Json, RoundTrip) {
}

auto t = i;
i+= static_cast<uint32_t>(dist(&rng));
i += static_cast<uint32_t>(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<Number const>(loaded)));
} else {
EXPECT_EQ(get<Number const>(loaded), f);
}
};
int64_t int32_max = static_cast<int64_t>(std::numeric_limits<uint32_t>::max());
#pragma omp parallel for schedule(static)
for (int64_t i = 0; i <= int32_max; ++i) {
test(static_cast<uint32_t>(i));
}
}
} // namespace xgboost

0 comments on commit a67bc64

Please sign in to comment.