MadsKirkFoged / EngineeringUnits

Working with units made easy with automatic unit-check and converting between units
MIT License
41 stars 10 forks source link

.Average() for Temperature fixed #53

Closed mschmitz2 closed 3 months ago

mschmitz2 commented 3 months ago

The issue comes from Sum(), which only makes sense for absolute temperature (Kelvin).

The added Average() methods also work for relative temperatures, e.g. °C.

Maybe there is a "cleaner" fix for this... like replacing the current return list.Sum() / list.Count(); in the generic Average method by something that does the right thing in case of Temperature.

mschmitz2 commented 3 months ago

Guess I forgot to check some of the other unit tests. It seems like, although the results of a division of BaseUnit / BaseUnit is UnknownUnit, the examples in the failing tests default to using the new Average(Temperature) methods instead of the original Average(UnknownUnit) methods... Not sure why this would be the case.

MadsKirkFoged commented 3 months ago

Great job spotting the bugs! Maybe we should make it a rule always to make a test for every new feature that also include temperature in degree - cause that is where most of the bugs is :-)