googletest icon indicating copy to clipboard operation
googletest copied to clipboard

resolve #4612 Feature add EXPECT/ASSERT_FLOAT/DOUBLE_NE (not equal)

Open daniel10015 opened this issue 11 months ago • 0 comments
trafficstars

A "not equal" feature was added to complement the "equal" feature for float and double. A simple way to negate the *_EQ is to use an internal macro, EXPECT_NONFATAL_FAILURE(stmt, substr):

// A macro for testing Google Test assertions or code that's expected to
// generate Google Test non-fatal failures (e.g. a failure from an EXPECT_EQ,
// but not from an ASSERT_EQ). It asserts that the given statement will cause
// exactly one non-fatal Google Test failure with 'substr' being part of the
// failure message.

This is not meant to be used when using gtest. Instead, what is proposed is a way of testing for inequality that follows equality. Test cases were made that test the semantics of the macro. Test cases were not made where the internal testing is computed, since the underlying code for both are the same, except for minor adjustments that don't modify the underlying flow of the program.

The following macros were created:

EXPECT_FLOAT_NE
EXPECT_DOUBLE_NE
ASSERT_FLOAT_NE
ASSERT_DOUBLE_NE

Two helper functions were created:

::testing::internal::CmpHelperFloatingPointNE<float>
::testing::internal::CmpHelperFloatingPointNE<double>

fixes #4612

daniel10015 avatar Nov 26 '24 19:11 daniel10015