I have recently started using googletest to set up some unit-testing and ran into a situation which I don't understand. The test fails but everything looks like it would pass.
I have a small struct similar to this:
struct vec2 { float x, y; }
a function:
vec2 vec2_add_scalar (vec2 v, float scalar) {
return {v.x + scalar, v.y + scalar};
}
and the test:
TEST (math_test, add_scalar) {
vec2 v {4.0f, -4.0f};
float s = 3.14f;
vec2 r = vec2_add_scalar(v, s);
EXPECT_EQ (7.14f, r.x);
EXPECT_EQ (-0.86f, r.y);
}
When running the test this is what I get:
[ RUN ] vector2_test.add_scalar
vec2_test.cpp: Failure
Expected: 7.14
To be equal to: r.x
Which is: 7.14
I don't understand why the test fails, and would appreciate help in figuring out what might make the test fail.