Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add LapseRate extensions #324

Merged
merged 1 commit into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions UnitsNet.Tests/CustomCode/LapseRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,40 @@


using System;
using Xunit;

namespace UnitsNet.Tests.CustomCode
{
public class LapseRateTests : LapseRateTestsBase
{
protected override double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer => 1e0;

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

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

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

[Fact]
public void LapseRateMultipliedByLengthEqualsTemperatureDelta()
{
TemperatureDelta temperatureDelta = LapseRate.FromDegreesCelciusPerKilometer(5) * Length.FromKilometers(10);
Assert.Equal(temperatureDelta, TemperatureDelta.FromDegreesCelsiusDelta(50));
}
}
}
48 changes: 48 additions & 0 deletions UnitsNet/CustomCode/Quantities/LapseRate.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
// https://github.com/angularsen/UnitsNet
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

namespace UnitsNet
{
// Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
// Public structures can't have any members other than public fields, and those fields must be value types or strings.
// Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
#if WINDOWS_UWP
public sealed partial class LapseRate
#else
public partial struct LapseRate
#endif
{
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
public static Length operator /(TemperatureDelta left, LapseRate right)
{
return Length.FromKilometers(left.KelvinsDelta / right.DegreesCelciusPerKilometer);
}

public static TemperatureDelta operator *(Length left, LapseRate right) => right * left;

public static TemperatureDelta operator *(LapseRate left, Length right)
{
return TemperatureDelta.FromDegreesCelsiusDelta(left.DegreesCelciusPerKilometer * right.Kilometers);
}
#endif
}
}
43 changes: 43 additions & 0 deletions UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
// https://github.com/angularsen/UnitsNet
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using UnitsNet.Units;

namespace UnitsNet
{
// Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
// Public structures can't have any members other than public fields, and those fields must be value types or strings.
// Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
#if WINDOWS_UWP
public sealed partial class TemperatureDelta
#else
public partial struct TemperatureDelta
#endif
{
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
public static LapseRate operator /(TemperatureDelta left, Length right)
{
return LapseRate.FromDegreesCelciusPerKilometer(left.DegreesCelsiusDelta / right.Kilometers);
}
#endif
}
}
2 changes: 1 addition & 1 deletion UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new CulturesForEnumValue((int) LapseRateUnit.DegreeCelsiusPerKilometer,
new[]
{
new AbbreviationsForCulture("en-US", "°C/m"),
new AbbreviationsForCulture("en-US", "°C/km"),
}),
}),
new UnitLocalization(typeof (LengthUnit),
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/UnitDefinitions/LapseRate.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "°C/m" ]
"Abbreviations": [ "°C/km" ]
}
]
}
Expand Down