Scope: Using Google Test and OpenCV.
I’d like to test that my Vec3f equals another Vec3f. Vec3f is a vector in OpenCV of dimension 3 and type float. The ==-operator is defined, so EXPECT_EQ(Vec3f(), Vec3f()) works.
But as they are floats, I’d like to use the EXPECT_NEAR(float a, float b, float delta) macro. What can I do so that I can use it like EXPECT_NEAR(vec_a, vec_b, float delta)?
At the moment I am looping through each element of the vector and doing an EXPECT_NEAR there.
This might be related: Convenient method in GoogleTest for a double comparison of not equal?
You are doing basically the correct thing. However, I would use a custom assertion function like:
MAGIC would then include your code to e.g. compare if both vectors have the same size, followed by iterating over all elements and mutually check if the elements at the same index differ by no more than the delta. Note that the code assumes that the << operator is provided for Vec3f.
The function then is used:
If the expect fails the output might be: