kotest
kotest copied to clipboard
Tolerance matchers fail on edge-case numeric inputs
While working on #3096, the property-based checker found some edge cases for tolerance matchers which don't appear to work correctly (or at least have somewhat strange behavior).
Cases where we should probably throw an IllegalArgumentException
:
(Float.NaN).shouldBeWithinPercentageOf(Float.NaN, 1.0) // => NaN should be in NaN..NaN
(Double.NaN).shouldBeWithinPercentageOf(Double.NaN, 1.0) // => NaN should be in NaN..NaN
0.shouldBeWithinPercentageOf(0, Double.POSITIVE_INFINITY) // => 0 should be in NaN..NaN
0L.shouldBeWithinPercentageOf(0L, Double.POSITIVE_INFINITY) // => 0 should be in NaN..NaN
0f.shouldBeWithinPercentageOf(0f, Double.POSITIVE_INFINITY) // => 0.0 should be in NaN..NaN
0.0.shouldBeWithinPercentageOf(0.0, Double.POSITIVE_INFINITY) // => 0.0 should be in NaN..NaN
Cases where behavior differs from x shouldBe (y plusOrMinus z.percent)
:
// Applies to both Double and Float
NEGATIVE_INFINITY shouldBe (NEGATIVE_INFINITY plusOrMinus 1.percent) // OK
POSITIVE_INFINITY shouldBe (POSITIVE_INFINITY plusOrMinus 1.percent) // OK
NEGATIVE_INFINITY.shouldBeWithinPercentageOf(NEGATIVE_INFINITY, 1.0) // -Infinity should be in -Infinity..NaN
POSITIVE_INFINITY.shouldBeWithinPercentageOf(POSITIVE_INFINITY, 1.0) // Infinity should be in NaN..Infinity
Which version of Kotest are you using #3096 - branched from 56573a7
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Nice catch!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Was fixed in 5.6.0