I tried to use google test framework and can’t see why the following code:
TEST(MathTest, BelowZeroCandF)
{
EXPECT_DOUBLE_EQ(convertCtoF(-1), 30.2);
}
where
double convertCtoF(double c)
{
return 32+1.8*c;
}
fails:
Failure
Value of: -30.20
Actual: -30.199999999999999
Expected: tc.convertCtoF(-1)
Which is: 30.199999999999999
[ FAILED ] MathTest.belowZeroCaboveZeroF (1 ms)
I know I could use EXPECT_NEAR, but don’t see why the above does not work…
(Adding the answer to complete the post, as OP confirmed the error in the comment.)
As shown in the error report, OP accidentally added a minus sign to the result, which is surely wrong. Removing the typo solved the problem.
Also, in GTest and many other unit testing frameworks (JUnit, etc.), the parameter order of the assertion is
otherwise the error report will have the input description flipped, just like what OP demonstrated.