-
Notifications
You must be signed in to change notification settings - Fork 397
Description
Describe the bug
Temperature.Equals(Temperature other, Temperature tolerance)
does the wrong conversion, and should be Temperature.Equals(Temperature other, TemperatureDelta tolerance)
To Reproduce
var t1 = Temperature.FromDegreesCelsius(10);
var t2 = Temperature.FromDegreesCelsius(10);
var equals = t1.Equals(t2, tolerance: Temperature.Zero);
Expected behavior
equals should be true
Actual behavior
throws System.ArgumentOutOfRangeException
"Tolerance must be greater than or equal to 0 (Parameter 'tolerance')"
Additional context
So the problem is that Temperature.Zero
is converterd from TemperatureUnit.Kelvin
to TemperatureUnit.DegreeCelsius
because t1
was specified using Temperature.FromDegreesCelsius
.
This uses the wrong conversion, the tolerance parameter should be of type TemperatureDelta
which converts correctly.
To fix this I see two problems that have to be solved:
- The Generation of the
Equals
method is not done such that a special delta unit can be specified in the quantity json, so the schema would need to be adapted - TemperatureDelta does not support the conversion of
tolerance.As(this.Unit)
becausethis.Unit
is of typeTemperatureUnit
and notTemperatureDeltaUnit
- To implement this Conversion as a custom method, one would need to match all Units between
TemperatureUnit
andTemperatureDeltaUnit
. ButTemperatureDeltaUnit
has no equivalent forTemperatureUnit.SolarTemperature
, which would have to be added
- To implement this Conversion as a custom method, one would need to match all Units between