Is there a support for testing double or float comparisons?

153 views
Skip to first unread message

brubelsabs

unread,
May 12, 2011, 5:13:23 AM5/12/11
to Google C++ Testing Framework
Hi list,

If I want to check that two doubles are nearly the same, I am used to
have a TS_ASSERT_DELTA macro, does GTest provide something similar? If
not how to add it?

EXPECT_EQ_DELTA( 1.001, 1.002, 0.001 )

Thanks for your reply

Pat Notz

unread,
May 12, 2011, 10:43:43 AM5/12/11
to brubelsabs, Google C++ Testing Framework
It's called ASSERT_NEAR(val1, val2, abs_err). You should also checkout
the ASSERT_DOUBLE_EQ(expected, actual) macro. It does something more
savvy than tolerance based diffs.

See http://code.google.com/p/googletest/wiki/AdvancedGuide

~ Pat

Reply all
Reply to author
Forward
0 new messages