Actual value equals expected value but still got failure

527 views
Skip to first unread message

Qun Zhang

unread,
May 31, 2014, 6:54:41 AM5/31/14
to googletes...@googlegroups.com
Hi all,

Simply put, in the gtest I am using

ASSERT_EQ(1.069, tf::getYaw(node.position.pose.orientation));

The test result:

test_planner.cpp:41: Failure
Value of: tf::getYaw(node.position.pose.orientation)
Actual: 1.069
Expected: 1.069

How come the equality of both value still generates failure result?

Any inputs would be appreciated. Thanks all.

Best Regards, ZQ

Keith Ray

unread,
May 31, 2014, 4:38:33 PM5/31/14
to Qun Zhang, googletes...@googlegroups.com
Floating-point values are imprecise.

instead of
ASSERT_EQ(1.069, tf::getYaw(node.position.pose.orientation));
use this
ASSERT_NEAR(val1, val2, abs_error);
or this:
ASSERT_DOUBLE_EQ(expected, actual);

Please see this reference:

--
C. Keith Ray
(650) 539-4729



--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vlad Losev

unread,
May 31, 2014, 4:39:12 PM5/31/14
to Google C++ Testing Framework
Welcome to the brave new world of floating point math!

Most likely, the result of your computation is very close to the expected value - close enough to be printed as one - but doesn't match it exactly. You should look into Google Test's wiki's section on floating point comparison to learn how to do it best.


--
Reply all
Reply to author
Forward
0 new messages