Skip to content

Commit

Permalink
Adding tests for new traits and is...Finite functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaltyagi committed Oct 15, 2019
1 parent da3ba9d commit 1eae214
Showing 1 changed file with 112 additions and 9 deletions.
121 changes: 112 additions & 9 deletions test/common/test_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,129 @@

#include <pcl/pcl_macros.h>
#include <pcl/point_traits.h>
#include <pcl/point_types.h>

#include <gtest/gtest.h>

TEST (TypeTraits, HasCustomAllocatorTrait)
{
struct Foo
{
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};

struct Bar
{
};

struct Foo
EXPECT_TRUE(pcl::has_custom_allocator<Foo>::value);
EXPECT_FALSE(pcl::has_custom_allocator<Bar>::value);
}

TEST (TypeTraits, HasXY)
{
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
static_assert(!pcl::traits::has_xy_v<pcl::Normal>,
"has_xy<> should detect lack of x and y fields");
static_assert(pcl::traits::has_xy_v<pcl::PointXYZ>,
"has_xy<> should detect x and y fields");
}

struct Bar
TEST (TypeTraits, HasXYZ)
{
};
static_assert(!pcl::traits::has_xyz_v<pcl::Normal>,
"has_xyz<> should detect lack of x or y or z fields");
static_assert(pcl::traits::has_xyz_v<pcl::PointXYZ>,
"has_xyz<> should detect x, y and z fields");
}

TEST (TypeTraits, HasCustomAllocatorTrait)
TEST (TypeTraits, HasNormal)
{
EXPECT_TRUE(pcl::has_custom_allocator<Foo>::value);
EXPECT_FALSE(pcl::has_custom_allocator<Bar>::value);
static_assert(!pcl::traits::has_normal_v<pcl::PointXYZ>,
"has_normal<> should detect lack of normal_{x or y or z} fields");
static_assert(pcl::traits::has_normal_v<pcl::Axis>,
"has_normal<> should detect normal_{x, y and z} fields");
}

TEST (TypeTraits, HasCurvature)
{
static_assert(!pcl::traits::has_curvature_v<pcl::PointXYZ>,
"has_curvature<> should detect lack of curvature field");
static_assert(pcl::traits::has_curvature_v<pcl::Normal>,
"has_curvature<> should detect curvature field");
}

TEST (TypeTraits, HasIntensity)
{
static_assert(!pcl::traits::has_intensity_v<pcl::InterestPoint>,
"has_intensity<> should detect lack of intensity field");
static_assert(pcl::traits::has_intensity_v<pcl::PointXYZI>,
"has_intensity<> should detect intensity field");
}

TEST (TypeTraits, HasColor)
{
static_assert(!pcl::traits::has_color_v<pcl::PointXYZ>,
"has_color<> should detect lack of rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGB>,
"has_color<> should detect rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGBA>,
"has_color<> should detect rgb field");
}

TEST (TypeTraits, HasLabel)
{
static_assert(!pcl::traits::has_label_v<pcl::PointXYZRGB>,
"has_label<> should detect lack of label field");
static_assert(pcl::traits::has_label_v<pcl::PointXYZRGBL>,
"has_label<> should detect label field");
}

TEST (TypeTests, IsXYFinite)
{
EXPECT_TRUE(pcl::isXYFinite(pcl::RGB {}));
EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {2,3,4}));

EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits<float>::max(), 3, 4}));
EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits<float>::min(), 3, 4}));

EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits<float>::infinity(), 3, 4}));
EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {-std::numeric_limits<float>::infinity(), 3, 4}));

EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits<float>::quiet_NaN(), 3, 4}));
EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {-std::numeric_limits<float>::signaling_NaN(), 3, 4}));
}


TEST (TypeTests, IsXYZFinite)
{
EXPECT_TRUE(pcl::isXYZFinite(pcl::RGB {}));
EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {2,3,4}));

EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits<float>::max(), 3, 4}));
EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits<float>::min(), 3, 4}));

EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits<float>::infinity(), 3, 4}));
EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {-std::numeric_limits<float>::infinity(), 3, 4}));

EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits<float>::quiet_NaN(), 3, 4}));
EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {-std::numeric_limits<float>::signaling_NaN(), 3, 4}));
}

TEST (TypeTests, IsNormalFinite)
{
EXPECT_TRUE(pcl::isNormalFinite(pcl::RGB {}));
EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {2,3,4}));

EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits<float>::max(), 3, 4}));
EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits<float>::min(), 3, 4}));

EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits<float>::infinity(), 3, 4}));
EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {-std::numeric_limits<float>::infinity(), 3, 4}));

EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits<float>::quiet_NaN(), 3, 4}));
EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {-std::numeric_limits<float>::signaling_NaN(), 3, 4}));
}

int
main (int argc, char** argv)
Expand Down

0 comments on commit 1eae214

Please sign in to comment.