From 83422a986b4f75192796f39c618ede26f3ec0b0d Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Mon, 7 Feb 2022 14:53:56 +0100 Subject: [PATCH 1/3] Fixes for tests on i386: relax SphericalCoordinates and workaround for negative zero Signed-off-by: Jose Luis Rivero --- src/OrientedBox_TEST.cc | 9 +++++++-- src/SphericalCoordinates_TEST.cc | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/OrientedBox_TEST.cc b/src/OrientedBox_TEST.cc index d3442ce30..2a6d63256 100644 --- a/src/OrientedBox_TEST.cc +++ b/src/OrientedBox_TEST.cc @@ -331,8 +331,13 @@ TEST(OrientedBoxTest, OperatorStreamOut) Pose3d(3.4, 4.5, 5.6, 0.0, -0.1, 0.2)); std::ostringstream stream; stream << b; - EXPECT_EQ(stream.str(), - "Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6 0 -0.1 0.2] Material[]"); + + // some compiler optimizations returns negative zero (-0) in the stream, workaround + // using prefix and postfix check. Not nice I know + EXPECT_TRUE(stream.str().find("Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6") != std::string::npos) << + "stream.str is: " << stream.str(); + EXPECT_TRUE(stream.str().find("0 -0.1 0.2] Material[]") != std::string::npos) << + "stream.str is: " << stream.str(); } ////////////////////////////////////////////////// diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 9af116ec9..ee0702540 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -448,7 +448,7 @@ TEST(SphericalCoordinatesTest, NoHeading) auto latLonAlt = sc.SphericalFromLocalPosition({0, 0, 0}); EXPECT_DOUBLE_EQ(lat.Degree(), latLonAlt.X()); EXPECT_DOUBLE_EQ(lon.Degree(), latLonAlt.Y()); - EXPECT_DOUBLE_EQ(elev, latLonAlt.Z()); + EXPECT_NEAR(elev, latLonAlt.Z(), 1e-6); auto xyzOrigin = sc.LocalFromSphericalPosition(latLonAlt); EXPECT_EQ(math::Vector3d::Zero, xyzOrigin); @@ -556,7 +556,7 @@ TEST(SphericalCoordinatesTest, WithHeading) auto latLonAlt = sc.SphericalFromLocalPosition({0, 0, 0}); EXPECT_DOUBLE_EQ(lat.Degree(), latLonAlt.X()); EXPECT_DOUBLE_EQ(lon.Degree(), latLonAlt.Y()); - EXPECT_DOUBLE_EQ(elev, latLonAlt.Z()); + EXPECT_NEAR(elev, latLonAlt.Z(), 1e-6); auto xyzOrigin = sc.LocalFromSphericalPosition(latLonAlt); EXPECT_EQ(math::Vector3d::Zero, xyzOrigin); From dce92770be42bacf804a1b375b4cc6e1d0b08cde Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Mon, 7 Feb 2022 14:59:47 +0100 Subject: [PATCH 2/3] Fix linter Signed-off-by: Jose Luis Rivero --- src/OrientedBox_TEST.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/OrientedBox_TEST.cc b/src/OrientedBox_TEST.cc index 2a6d63256..77e6cb7a8 100644 --- a/src/OrientedBox_TEST.cc +++ b/src/OrientedBox_TEST.cc @@ -332,12 +332,14 @@ TEST(OrientedBoxTest, OperatorStreamOut) std::ostringstream stream; stream << b; - // some compiler optimizations returns negative zero (-0) in the stream, workaround - // using prefix and postfix check. Not nice I know - EXPECT_TRUE(stream.str().find("Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6") != std::string::npos) << - "stream.str is: " << stream.str(); - EXPECT_TRUE(stream.str().find("0 -0.1 0.2] Material[]") != std::string::npos) << - "stream.str is: " << stream.str(); + // some compiler optimizations returns negative zero (-0) in the stream, + // workaround using prefix and postfix check. Not nice I know + EXPECT_TRUE(stream.str().find( + "Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6") != std::string::npos) << + "stream.str is: " << stream.str(); + EXPECT_TRUE(stream.str().find( + "0 -0.1 0.2] Material[]") != std::string::npos) << + "stream.str is: " << stream.str(); } ////////////////////////////////////////////////// From cea52b5b6b23eefc05161bb3e4364b811aaf10ec Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 24 Mar 2022 18:04:22 -0700 Subject: [PATCH 3/3] Don't use zero in test Signed-off-by: Louise Poubel --- src/OrientedBox_TEST.cc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/OrientedBox_TEST.cc b/src/OrientedBox_TEST.cc index 77e6cb7a8..41c935dbd 100644 --- a/src/OrientedBox_TEST.cc +++ b/src/OrientedBox_TEST.cc @@ -328,18 +328,12 @@ TEST(OrientedBoxTest, ContainsOrientedRotation) TEST(OrientedBoxTest, OperatorStreamOut) { OrientedBoxd b(Vector3d(0.1, 1.2, 2.3), - Pose3d(3.4, 4.5, 5.6, 0.0, -0.1, 0.2)); + Pose3d(3.4, 4.5, 5.6, 0.1, -0.1, 0.2)); std::ostringstream stream; stream << b; - // some compiler optimizations returns negative zero (-0) in the stream, - // workaround using prefix and postfix check. Not nice I know - EXPECT_TRUE(stream.str().find( - "Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6") != std::string::npos) << - "stream.str is: " << stream.str(); - EXPECT_TRUE(stream.str().find( - "0 -0.1 0.2] Material[]") != std::string::npos) << - "stream.str is: " << stream.str(); + EXPECT_EQ(stream.str(), + "Size[0.1 1.2 2.3] Pose[3.4 4.5 5.6 0.1 -0.1 0.2] Material[]"); } //////////////////////////////////////////////////