1

If I have something like:

ASSERT_TRUE(RANGE(val1, val2, abs_err) || RANGE(val1, val3, abs_err));

How would I use ASSERT_NEAR instead of ASSERT_TRUE?

I've attempted to break up the statement into two ASSERT_NEAR statements, like below, but the test fails.

ASSERT_NEAR(val1, val2, abs_err);
ASSERT_NEAR(val1, val3, abs_err);
PiotrNycz
  • 23,099
  • 7
  • 66
  • 112
Irfan Hossain
  • 59
  • 1
  • 10

1 Answers1

1

Your use case is: any of these two condition should be true. So use ::testing::AnyOf(m1,m2,...)!

Equivalent of ASSERT_NEAR(lhs,rhs,max_error) in matchers world is ::testing::DoubleNear(rhs,max_error) - so your example will look like this:

ASSERT_THAT(val1, AnyOf(DoubleNear(val2, abs_err),
                        DoubleNear(val3, abs_err)));

If you need both of your conditions are true - use ::testing::AllOf - actually your attempt is just equivalent of AllOf - that is why it failed.

PiotrNycz
  • 23,099
  • 7
  • 66
  • 112