Equals and IsEqualTo unexpected behaviour with nullable floating point numbers
MaciekSwiszczowski opened this issue · 3 comments
MaciekSwiszczowski commented
Equals and IsEqualTo don't fire exceptions when the expected value is an integer and the checked value is nullable floating point.
Expected Behavior
They should fire an exception.
Current Behavior
double? number = 2.2;
Check.That(number).Equals(2); // OK
Check.That(number).IsEqualTo(2); // OK
Your Environment
- Version used: 2.6
- Framework version: e.g. .NET Core 3.1
dupdob commented
The situation evolves with the upcoming version V2.7 due to the significant rewriting of equality comparison and mutant tests that helped identify some issues.
double? number = 2.2;
Check.That(number).Equals(2); // OK
Check.That(number).IsEqualTo(2); // fails
I need to review why it works of Equals
dupdob commented
There is an issue with the numerical type resolution logic.
Workaround:
double? number = 2.2;
Check.That(number).Equals(2.0); //fails
Check.That(number).IsEqualTo(2.0); // fails
Check.That(number).IsEqualTo(2d); // fails
Check.That(number).IsEqualTo(2f); // fails
dupdob commented
fixed in V 2.7.0