Convenient method in GoogleTest for a double comparison of not equal?

后端 未结 3 1391
挽巷
挽巷 2021-01-18 01:00

I\'m looking for something similar to the ASSERT_EQ / ASSERT_NE for ASSERT_DOUBLE_EQ.

Maybe I\'m missing an easy way of doing this without having a ASSERT_DOUBLE_NE?

3条回答
  •  一个人的身影
    2021-01-18 01:23

    instead of creating a new CmpHelperFloatingPointNE helper, you can just define the macro as the inverse of the existing helper:

    #include "gtest/gtest.h"
    
    #define ASSERT_FLOAT_NE(val1, val2) ASSERT_PRED_FORMAT2( \
      !::testing::internal::CmpHelperFloatingPointEQ, val1, val2 \
    )
    
    #define ASSERT_DOUBLE_NE(val1, val2) ASSERT_PRED_FORMAT2( \
      !::testing::internal::CmpHelperFloatingPointEQ, val1, val2 \
    )
    

    This is not as graceful as deft_code's solution because when the assertion fails, there are no specific details like "expected value" and "actual value", just the line number and file of the assertion. For my purposes, though, the line number was enough.

提交回复
热议问题