c++ - 谷歌测试检查 float 不等于

标签 c++ googletest

是否期望浮点值不等于第二个值?

例如,与 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);

其中 expr1expr2 是将在断言消息中使用的浮点参数的字符串表示形式。

关于c++ - 谷歌测试检查 float 不等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63189300/

相关文章:

c++ - Google Mock 单元测试静态方法 c++

c++ - 使用 Gtest 如何在 ON_CALL 中返回不同的值?

c++ - 检查函数是否在解决方案中被调用

.net - 将 char* 传递给 .Net 的最佳方式

c++ - C++如何继承Template类

c++ - 单元测试时从哪里加载 stub 数据

c++ - 如何使用 CMake 在 C++ 代码中运行 gtest? (未见测试)

c++ - 将公共(public)属性设置为私有(private)

java - 如何通过JNI分享进度更新?

c++ - CMake 在 Ubuntu 中找不到 GoogleTest 所需的库