File: urdf_double_convert.cpp

package info (click to toggle)
urdfdom 4.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 380 kB
  • sloc: cpp: 2,541; sh: 32; xml: 29; makefile: 8
file content (27 lines) | stat: -rw-r--r-- 669 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <gtest/gtest.h>

#include <urdf_model/utils.h>

TEST(URDF_DOUBLE_CONVERT, test_successful_conversion)
{
  std::string easy{"1.0"};
  double conv = urdf::strToDouble(easy.c_str());
  EXPECT_EQ(1.0, conv);

  std::string scientific{"0.00006"};
  double sconv = urdf::strToDouble(scientific.c_str());
  EXPECT_NEAR(0.00006, sconv, 0.00001);
}

TEST(URDF_DOUBLE_CONVERT, test_failed_conversion)
{
  std::string invalid{"foo"};
  EXPECT_THROW({
      try {
        urdf::strToDouble(invalid.c_str());
    } catch(const std::runtime_error& e) {
        EXPECT_STREQ("Failed converting string to double", e.what());
        throw;
    }
    }, std::runtime_error);
}