Skip to content

Commit

Permalink
Add operators extensions to TemperatureGradient and remove duplicates…
Browse files Browse the repository at this point in the history
… from LapseRate

I have removed the TemperatureDelta/Length = LapseRate operator since it
would collide with the same overload that equals TemperatureGradient. This is
a breaking change, but it was decided that we can do it anyways since
it's easy to replace and you will get a compiler error.
  • Loading branch information
dglozano committed Nov 23, 2021
1 parent 04a3d21 commit 99b8a6e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
7 changes: 0 additions & 7 deletions UnitsNet.Tests/CustomCode/LapseRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ public void TemperatureDeltaDividedByLapseRateEqualsLength()
Assert.Equal(length, Length.FromKilometers(10));
}

[Fact]
public void TemperatureDeltaDividedByLengthEqualsLapseRate()
{
LapseRate lapseRate = TemperatureDelta.FromDegreesCelsius(50) / Length.FromKilometers(10);
Assert.Equal(lapseRate, LapseRate.FromDegreesCelciusPerKilometer(5));
}

[Fact]
public void LengthMultipliedByLapseRateEqualsTemperatureDelta()
{
Expand Down
28 changes: 28 additions & 0 deletions UnitsNet.Tests/CustomCode/TemperatureGradientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,33 @@ public class TemperatureGradientTests : TemperatureGradientTestsBase
protected override double DegreesFahrenheitPerFootInOneKelvinPerMeter => 0.54864;

protected override double KelvinsPerMeterInOneKelvinPerMeter => 1;

[Fact]
public void TemperatureDeltaDividedByTemperatureGradientEqualsLength()
{
Length length = TemperatureDelta.FromDegreesCelsius(50) / TemperatureGradient.FromDegreesCelciusPerKilometer(5);
Assert.Equal(length, Length.FromKilometers(10));
}

[Fact]
public void TemperatureDeltaDividedByLengthEqualsTemperatureGradient()
{
TemperatureGradient lapseRate = TemperatureDelta.FromDegreesCelsius(50) / Length.FromKilometers(10);
Assert.Equal(lapseRate, TemperatureGradient.FromDegreesCelciusPerKilometer(5));
}

[Fact]
public void LengthMultipliedByTemperatureGradientEqualsTemperatureDelta()
{
TemperatureDelta temperatureDelta = Length.FromKilometers(10) * TemperatureGradient.FromDegreesCelciusPerKilometer(5);
Assert.Equal(temperatureDelta, TemperatureDelta.FromDegreesCelsius(50));
}

[Fact]
public void TemperatureGradientMultipliedByLengthEqualsTemperatureDelta()
{
TemperatureDelta temperatureDelta = TemperatureGradient.FromDegreesCelciusPerKilometer(5) * Length.FromKilometers(10);
Assert.Equal(temperatureDelta, TemperatureDelta.FromDegreesCelsius(50));
}
}
}
6 changes: 3 additions & 3 deletions UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace UnitsNet
{
public partial struct TemperatureDelta
{
/// <summary>Get <see cref="LapseRate"/> from <see cref="TemperatureDelta"/> divided by <see cref="Length"/>.</summary>
public static LapseRate operator /(TemperatureDelta left, Length right)
/// <summary>Get <see cref="TemperatureGradient"/> from <see cref="TemperatureDelta"/> divided by <see cref="Length"/>.</summary>
public static TemperatureGradient operator /(TemperatureDelta left, Length right)
{
return LapseRate.FromDegreesCelciusPerKilometer(left.DegreesCelsius / right.Kilometers);
return TemperatureGradient.FromKelvinsPerMeter(left.Kelvins / right.Meters);
}

/// <summary>Get <see cref="SpecificEnergy"/> from <see cref="SpecificEntropy"/> times <see cref="TemperatureDelta"/>.</summary>
Expand Down
23 changes: 23 additions & 0 deletions UnitsNet/CustomCode/Quantities/TemperatureGradient.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

namespace UnitsNet
{
public partial struct TemperatureGradient
{
/// <summary>Get <see cref="Length"/> from <see cref="TemperatureDelta"/> divided by <see cref="TemperatureGradient"/>.</summary>
public static Length operator /(TemperatureDelta left, TemperatureGradient right)
{
return Length.FromKilometers(left.Kelvins / right.DegreesCelciusPerKilometer);
}

/// <summary>Get <see cref="TemperatureDelta"/> from <see cref="Length"/> times <see cref="TemperatureGradient"/>.</summary>
public static TemperatureDelta operator *(Length left, TemperatureGradient right) => right * left;

/// <summary>Get <see cref="TemperatureDelta"/> from <see cref="TemperatureGradient"/> times <see cref="Length"/>.</summary>
public static TemperatureDelta operator *(TemperatureGradient left, Length right)
{
return TemperatureDelta.FromDegreesCelsius(left.DegreesCelciusPerKilometer * right.Kilometers);
}
}
}

0 comments on commit 99b8a6e

Please sign in to comment.