assertEqualsWithTolerance function

void assertEqualsWithTolerance(
  1. double a,
  2. double b,
  3. double tolerance
)

Throws an AssertionError when a and b differ by more than tolerance.

Use for comparing floating-point values where exact equality is unreliable.

Example:

assertEqualsWithTolerance(0.1 + 0.2, 0.3, 1e-9); // passes

Implementation

void assertEqualsWithTolerance(double a, double b, double tolerance) {
  if ((a - b).abs() > tolerance) throw AssertionError('Expected $a ≈ $b (tolerance $tolerance)');
}