是否期望浮点值不等于第二个值?
例如,与 EXPECT_FLOAT_EQ(val1,val2) 相反
最佳答案
我不认为 GTest 有这个功能,他们在 documentation 中解释道。
Some floating-point operations are useful, but not that often used. In order to avoid an explosion of new macros, we provide them as predicate-format functions that can be used in predicate assertion macros (e.g. EXPECT_PRED_FORMAT2, etc).
您可以按照@idclev 463035818的建议定义一个谓词,并将其传递到EXPECT_PRED_FORMAT2(pred, val1, val2)
。谓词必须符合签名:
testing::AssertionResult pred(const char* expr1, const char* expr2,
double val1, double val2);
其中 expr1
和 expr2
是将在断言消息中使用的浮点参数的字符串表示形式。
关于c++ - 谷歌测试检查 float 不等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63189300/