feat: add IsCloseTo and IsWithinPercentOf numeric assertions#4940
feat: add IsCloseTo and IsWithinPercentOf numeric assertions#4940
Conversation
Code ReviewOverall this is a well-structured addition with good test coverage and proper NaN/infinity handling. Two bugs need addressing before merge. Bug 1 (High): Integer overflow in
|
00f9e5a to
49924bb
Compare
49924bb to
e8e6bbf
Compare
e8e6bbf to
9187312
Compare
9187312 to
bfe1e2e
Compare
Add relative and absolute tolerance assertions for numeric types (double, float, int, long, decimal): - IsCloseTo(expected, tolerance): asserts |actual - expected| <= tolerance - IsWithinPercentOf(expected, percent): asserts |actual - expected| <= |expected * percent / 100| Both assertions follow the existing pattern using [AssertionExtension] for source-generated extension methods. Includes proper handling of NaN, infinity, and edge cases for floating-point types. Closes #4870
…o double Cast `value` to `double` before subtraction and compare against `(double)_tolerance` so that extreme long values (e.g., MaxValue vs MinValue) no longer silently wrap around.
4c70fbe to
80e92bc
Compare
Summary
IsCloseTo(expected, tolerance)assertion for absolute tolerance comparison:|actual - expected| <= toleranceIsWithinPercentOf(expected, percent)assertion for relative tolerance comparison:|actual - expected| <= |expected * percent / 100|double,float,int,long, anddecimaltypes[AssertionExtension]for source-generated extension methodsUsage
Test plan
Closes #4870