Skip to content

Commit

Permalink
Param_TEST: test parsing +Inf and -Inf
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed May 18, 2020
1 parent e33839f commit 404a32f
Showing 1 changed file with 38 additions and 1 deletion.
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

0 comments on commit 404a32f

Please sign in to comment.