#3035

Comparing floating point containers without `Approx`

Openhughcarsopened 1y ago

Before the move away from Approx, the way of absolutely comparing two std::vector<double> was to my understanding

std::vector<double> sample, truth;
constexpr double delta = 1e-12;
CHECK_THAT(sample, Approx(truth).margin(delta));

using the WithinAbs comparison however, seems to require unrolling:

      for (size_t i = 0; i < sample.size(); ++i)
      {
        CHECK_THAT(sample[i],
                   Catch::Matchers::WithinAbs(truth[i], delta));
      }

or

CHECK_THAT(sample, Catch::Matchers::RangeEquals(truth, [](auto x, auto y){ return std::abs(x-y) < delta;}));

We're wanting to follow the deprecation guidance, and are moving away from Approx, but is there a recommended way of doing a floating point comparison on a container that I missed? Having a single check for a container was quite elegant.

Activity

0

No activity yet.