kotest-assertions-core / io.kotest.matchers.doubles / between

between

fun between(a: Double, b: Double, tolerance: Double): Matcher<Double>

Matcher that matches doubles and intervals

Verifies that a specific Double is in the interval [a - tolerance , b + tolerance].

For example:

0.5 is in the interval 0.4,0.6, because 0.4 <= 0.5 <= 0.6.

This matcher also includes the bonds of the interval, so:

0.5 is in the interval 0.5,0.6 because 0.5 <= 0.5 <= 0.6.

The parameter tolerance is used to allow a slightly wider range, to include possible imprecision, and can be 0.0.

0.5 is in the interval 0.6,0.7 when there's a tolerance of 0.1, because (0.6 - 0.1) <= 0.5 <= (0.7 + 0.1)

0.5 shouldBe between(0.1, 1.0, 0.0)     // Assertion passes
0.5 shouldNotBe between(1.0, 2.0, 0.1)  // Assertion passes

See Also

Double.shouldBeBetween

Double.shouldNotBeBetween