gpt4 book ai didi

c++ - Google Test Check for Float Not Equality

转载 作者:行者123 更新时间:2023-12-02 09:59:53 26 4
gpt4 key购买 nike

是否期望浮点值不等于第二个值?
例如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是将在断言消息中使用的float参数的字符串表示形式。

关于c++ - Google Test Check for Float Not Equality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63189300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com