test_ros_conversor.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2022 Firefly Automatix Inc., - All Rights Reserved
3 // Author: Vinny Ruia
4 // BSD-3 License
5 //=============================================================================
6 
7 
8 #include <gtest/gtest.h>
9 
10 #include <fields2cover.h>
11 #include "ros/conversor.h"
12 
13 #include <tuple>
14 
15 constexpr static float_t FLOAT_TOL = 1e-6;
16 
18  : public ::testing::TestWithParam<std::tuple<float_t, float_t, float_t>> {
19 };
20 
21 TEST_P(ToPointTest, testConvertPoint) {
22  auto params = GetParam();
23  auto x = std::get<0>(params);
24  auto y = std::get<1>(params);
25  auto z = std::get<2>(params);
26  conversor::GeometryMsgs::Point point;
27  F2CPoint p1(x, y, z);
28  conversor::ROS::to(p1, point);
29 
30  EXPECT_NEAR(x, point.x, FLOAT_TOL);
31  EXPECT_NEAR(y, point.y, FLOAT_TOL);
32  EXPECT_NEAR(z, point.z, FLOAT_TOL);
33 }
34 
35 TEST_P(ToPointTest, testConvertPoint32) {
36  auto params = GetParam();
37  auto x = std::get<0>(params);
38  auto y = std::get<1>(params);
39  auto z = std::get<2>(params);
40  conversor::GeometryMsgs::Point32 point;
41  F2CPoint p1(x, y, z);
42  conversor::ROS::to(p1, point);
43 
44  EXPECT_NEAR(x, point.x, FLOAT_TOL);
45  EXPECT_NEAR(y, point.y, FLOAT_TOL);
46  EXPECT_NEAR(z, point.z, FLOAT_TOL);
47 }
48 
50  ParametrizedToPointTest,
52  ::testing::Values(
53  std::tuple<float_t, float_t, float_t>{0.0, 0.0, 0.0},
54  std::tuple<float_t, float_t, float_t>{1.2, 3.456, -7.9},
55  std::tuple<float_t, float_t, float_t>{20001.2787878, -3.456, -0.0}
56  )
57 );
58 
60  : public ::testing::Test {
61 };
62 
63 TEST_F(ToPolyTest, testToPoly) {
64  F2CLinearRing outer_ring{
65  F2CPoint(0, 0), F2CPoint(2, 0), F2CPoint(2, 2), F2CPoint(0, 2), F2CPoint(0, 0)};
66  F2CLinearRing inner_ring{
67  F2CPoint(0.5, 0.5), F2CPoint(1.5, 0.5), F2CPoint(1.5, 1.5),
68  F2CPoint(0.5, 1.5), F2CPoint(0.5, 0.5)};
69  F2CCell cell;
70  cell.addRing(outer_ring);
71  cell.addRing(inner_ring);
72 
73  std::vector<conversor::GeometryMsgs::Polygon> polygons;
74 
75  conversor::ROS::to(cell, polygons);
76 
77  EXPECT_NEAR(polygons[0].points[0].x, 0, FLOAT_TOL);
78  EXPECT_NEAR(polygons[0].points[0].y, 0, FLOAT_TOL);
79  EXPECT_NEAR(polygons[0].points[1].x, 2, FLOAT_TOL);
80  EXPECT_NEAR(polygons[0].points[1].y, 0, FLOAT_TOL);
81  EXPECT_NEAR(polygons[0].points[2].x, 2, FLOAT_TOL);
82  EXPECT_NEAR(polygons[0].points[2].y, 2, FLOAT_TOL);
83  EXPECT_NEAR(polygons[0].points[3].x, 0, FLOAT_TOL);
84  EXPECT_NEAR(polygons[0].points[3].y, 2, FLOAT_TOL);
85 
86  EXPECT_NEAR(polygons[1].points[0].x, 0.5, FLOAT_TOL);
87  EXPECT_NEAR(polygons[1].points[0].y, 0.5, FLOAT_TOL);
88  EXPECT_NEAR(polygons[1].points[1].x, 1.5, FLOAT_TOL);
89  EXPECT_NEAR(polygons[1].points[1].y, 0.5, FLOAT_TOL);
90  EXPECT_NEAR(polygons[1].points[2].x, 1.5, FLOAT_TOL);
91  EXPECT_NEAR(polygons[1].points[2].y, 1.5, FLOAT_TOL);
92  EXPECT_NEAR(polygons[1].points[3].x, 0.5, FLOAT_TOL);
93  EXPECT_NEAR(polygons[1].points[3].y, 1.5, FLOAT_TOL);
94  EXPECT_NEAR(polygons[1].points[4].x, 0.5, FLOAT_TOL);
95  EXPECT_NEAR(polygons[1].points[4].y, 0.5, FLOAT_TOL);
96 };
97 
conversor.h
FLOAT_TOL
constexpr static float_t FLOAT_TOL
Definition: test_ros_conversor.cpp:15
conversor::ROS::to
static void to(const F2CPoint &_point, GeometryMsgs::Point32 &_p32)
Definition: conversor.cpp:12
ToPolyTest
Definition: test_ros_conversor.cpp:59
TEST_P
TEST_P(ToPointTest, testConvertPoint)
Definition: test_ros_conversor.cpp:21
ToPointTest
Definition: test_ros_conversor.cpp:17
TEST_F
TEST_F(ToPolyTest, testToPoly)
Definition: test_ros_conversor.cpp:63
INSTANTIATE_TEST_SUITE_P
INSTANTIATE_TEST_SUITE_P(ParametrizedToPointTest, ToPointTest, ::testing::Values(std::tuple< float_t, float_t, float_t >{0.0, 0.0, 0.0}, std::tuple< float_t, float_t, float_t >{1.2, 3.456, -7.9}, std::tuple< float_t, float_t, float_t >{20001.2787878, -3.456, -0.0}))


fields2cover_ros
Author(s):
autogenerated on Tue Feb 7 2023 03:46:06