Skip to content

Commit

Permalink
Merge pull request #2043 from dota17/unit-constructor1
Browse files Browse the repository at this point in the history
Add missing testcase about NaN in unit-constructor1.cpp
  • Loading branch information
nlohmann authored Apr 21, 2020
2 parents a29e3b1 + c379d02 commit 63afc8e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,21 @@ TEST_CASE("constructors")
CHECK(j.type() == json::value_t::number_float);
}

SECTION("NaN")
{
// NaN is stored properly, but serialized to null
json::number_float_t n(std::numeric_limits<json::number_float_t>::quiet_NaN());
json j(n);
CHECK(j.type() == json::value_t::number_float);

// check round trip of NaN
json::number_float_t d = j;
CHECK((std::isnan(d) and std::isnan(n)) == true);

// check that NaN is serialized to null
CHECK(j.dump() == "null");
}

SECTION("infinity")
{
// infinity is stored properly, but serialized to null
Expand Down

0 comments on commit 63afc8e

Please sign in to comment.