Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param_TEST: test parsing +Inf and -Inf #277

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
1. Change bitbucket links to GitHub.
* [Pull request 240](https://github.com/osrf/sdformat/pull/240)

1. Param_TEST: test parsing +Inf and -Inf.
* [Pull request 277](https://github.com/osrf/sdformat/pull/277)

1. Observe the CMake variable `BUILD_TESTING` if it is defined.
* [Pull request 269](https://github.com/osrf/sdformat/pull/269)

1. Collision: don't load Surface without `<surface>`.
* [Pull request 268](https://github.com/osrf/sdformat/pull/268)

Expand Down
39 changes: 38 additions & 1 deletion src/Param_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <any>
#include <cstdint>
#include <limits>

#include <gtest/gtest.h>

Expand All @@ -25,7 +26,7 @@
#include "sdf/Exception.hh"
#include "sdf/Param.hh"

bool check_double(std::string num)
bool check_double(const std::string &num)
{
const std::string name = "number";
const std::string type = "double";
Expand Down Expand Up @@ -100,6 +101,42 @@ TEST(SetFromString, Decimals)
ASSERT_TRUE(check_double("0.2345"));
}

////////////////////////////////////////////////////
/// Test Inf
TEST(SetFromString, DoublePositiveInf)
{
ASSERT_TRUE(std::numeric_limits<double>::has_infinity);
std::vector<std::string> positiveInfStrings{
"inf", "Inf", "INF", "+inf", "+Inf", "+INF"};
for (const auto &infString : positiveInfStrings)
{
sdf::Param doubleParam("key", "double", "0", false, "description");
double value = 0.;

EXPECT_TRUE(doubleParam.SetFromString(infString));
doubleParam.Get<double>(value);
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), value);
}
}

////////////////////////////////////////////////////
/// Test -Inf
TEST(SetFromString, DoubleNegativeInf)
{
ASSERT_TRUE(std::numeric_limits<double>::is_iec559);
std::vector<std::string> negativeInfStrings{
"-inf", "-Inf", "-INF"};
for (const auto &infString : negativeInfStrings)
{
sdf::Param doubleParam("key", "double", "0", false, "description");
double value = 0.;

EXPECT_TRUE(doubleParam.SetFromString(infString));
doubleParam.Get<double>(value);
EXPECT_DOUBLE_EQ(- std::numeric_limits<double>::infinity(), value);
}
}

////////////////////////////////////////////////////
/// Test setting and reading hex int values.
TEST(Param, HexInt)
Expand Down