Comparison of floating point arrays using google test and google mock
arrays, c++, floating-point, googlemock, googletest
Solution
The following works for me:
using ::testing::Pointwise;
using ::testing::FloatNear;
auto const max_abs_error = 1 / 1024.f;
ASSERT_THAT(
test,
Pointwise(FloatNear(max_abs_error), ref));
Where `test` and `ref` are of type `std::vector<float>`.
Problem
I am new to Google's test products and trying them out with some signal processing code. I am trying to assert that to floating point arrays are equal to within some bounds, using google mock as suggested by the answer to this question. I would like to know the recommended method for adding some error tolerance to an expression like the following . . . ``` EXPECT_THAT( impulse, testing::ElementsAreArray( std::vector<float>({ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) ) ); ``` I want the test to pass if the element-wise values in the arrays are within 10-8 of one another.