google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.75k stars 10.14k forks source link

Generalize EXPECT_NEAR/ASSERT_NEAR to work with arbitrary floating-point like types #890

Open helloworld922 opened 8 years ago

helloworld922 commented 8 years ago

The EXPECT_NEAR and ASSERT_NEAR macros expect double parameters, which potentially means loss of precision or for types with greater accuracy than double, or compile errors for types not implicitly convertible to double (gcc/intel quad precision long double, Boost.MultiPrecision, etc.).

I've attached a patch which demonstrates a working example fix which generalizes this to work with arbitrary types as long as the required basic operations are available (can find an abs function, subtraction operator, comparison operator).

fp_fix.txt

chiphogg commented 5 years ago

So, was this closed because the fix was merged? Closed because it won't be fixed? @gennadiycivil -- can you please elaborate?

gennadiycivil commented 5 years ago

I have to say that I dont know. I have been doing a lot of cleanup, this was back in August and it is possible that I simply clicked the wrong button. Sorry about that Thanks G

On Thu, Jan 24, 2019 at 1:38 PM Chip Hogg notifications@github.com wrote:

So, was this closed because the fix was merged? Closed because it won't be fixed? @gennadiycivil https://github.com/gennadiycivil -- can you please elaborate?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/googletest/issues/890#issuecomment-457308244, or mute the thread https://github.com/notifications/unsubscribe-auth/AMJSMnXKSsCQBhNLqeWKda6ZQ2P-DSn5ks5vGf2OgaJpZM4KJGnT .

chiphogg commented 5 years ago

It seems there is an open pull request. Perhaps this issue should be reopened?

gennadiycivil commented 5 years ago

Re-Opening. Please read https://github.com/google/googletest/pull/2077#issuecomment-460729350.

chiphogg commented 5 years ago

Even though it looks like I shouldn't expect this to close any time soon, I'm still happy the issue is in the correct state. :slightly_smiling_face: Thanks!

chiphogg commented 4 years ago

Perhaps a good way to move this forward would be:

What do you think?

EvanHonnold commented 3 years ago

I am encountering similar issues with EXPECT_NEAR. Looks like there was some recent discussion in https://github.com/google/googletest/pull/2077#issuecomment-783465831 about a possible fix -- might this be a way forward?