Skip to content

Temperature.Equals method uses the wrong Unit for the tolerance parameter #1325

@park-jasper

Description

@park-jasper

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) because this.Unit is of type TemperatureUnit and not TemperatureDeltaUnit
    • To implement this Conversion as a custom method, one would need to match all Units between TemperatureUnit and TemperatureDeltaUnit. But TemperatureDeltaUnit has no equivalent for TemperatureUnit.SolarTemperature, which would have to be added

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions