jeudi 1 septembre 2016

GTest Floats less or close with absolute error

The assertion macros of googletest are pretty great because they provide with nice messages in case of failure. I am looking for a nice possibility for a more complicated float comparison: "Less than or close with given accuracy for the latter" So according to the Advanced Guide on github this is at least possible without giving a maximum absolute error for how close the floats may be:

EXPECT_PRED_FORMAT2(::testing::FloatLE, val1, val2);

Just right above they say how "close with given error" works:

EXPECT_NEAR(val1, val2, abs_error);

So I thought a combination must work, too. Looking at the source code, how the EXPECT_NEAR expands I see that there are higher order macros like

EXPECT_PRED_FORMAT3

which accept again another value. However, I could not get this combination to work in a straight forward way.

So the question is: Is this possible at all and how?

Of course one can do a workaround, coding the comparison and just comparing a boolean. However, this lacks the nice gtest output in case of failure.

Aucun commentaire:

Enregistrer un commentaire