Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 361
Brandon Leiran Avatar asked Aug 18 '10 18:08

Brandon Leiran


People also ask

What is EXPECT_ call in gmock?

EXPECT_CALL not only defines the behavior, but also sets an expectation that the method will be called with the given arguments, for the given number of times (and in the given order when you specify the order too).

How do you mock in Gmock?

first, you use some simple macros to describe the interface you want to mock, and they will expand to the implementation of your mock class; next, you create some mock objects and specify its expectations and behavior using an intuitive syntax; then you exercise code that uses the mock objects.

How do you write a value parameterized test?

To write value-parameterized tests, first you should define a fixture class. It must be derived from both testing::Test and testing::WithParamInterface<T> (the latter is a pure interface), where T is the type of your parameter values.


1 Answers

You can use the companion mocking framework Google Mock. It has a powerful library of matchers (a la Hamcrest), which you can use with the EXPECT_THAT/ASSERT_THAT macros:

EXPECT_THAT(value, FloatEq(1));
EXPECT_THAT(another_value, Not(DoubleEq(3.14)));
like image 158
VladLosev Avatar answered Oct 23 '22 06:10

VladLosev