diff --git a/UnitsNet.Tests/CustomCode/LapseRateTests.cs b/UnitsNet.Tests/CustomCode/LapseRateTests.cs index 3dddefd80d..0347e63740 100644 --- a/UnitsNet.Tests/CustomCode/LapseRateTests.cs +++ b/UnitsNet.Tests/CustomCode/LapseRateTests.cs @@ -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)); + } } } diff --git a/UnitsNet/CustomCode/Quantities/LapseRate.extra.cs b/UnitsNet/CustomCode/Quantities/LapseRate.extra.cs new file mode 100644 index 0000000000..a0a4d02cf1 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/LapseRate.extra.cs @@ -0,0 +1,48 @@ +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// 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 + } +} diff --git a/UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs b/UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs new file mode 100644 index 0000000000..46ce1a5986 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs @@ -0,0 +1,43 @@ +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// 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 + } +} \ No newline at end of file diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 47e966ae13..83e5c788e4 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection DefaultLocalization new CulturesForEnumValue((int) LapseRateUnit.DegreeCelsiusPerKilometer, new[] { - new AbbreviationsForCulture("en-US", "°C/m"), + new AbbreviationsForCulture("en-US", "∆°C/km"), }), }), new UnitLocalization(typeof (LengthUnit), diff --git a/UnitsNet/UnitDefinitions/LapseRate.json b/UnitsNet/UnitDefinitions/LapseRate.json index cfeee74c90..f612cb4ebe 100644 --- a/UnitsNet/UnitDefinitions/LapseRate.json +++ b/UnitsNet/UnitDefinitions/LapseRate.json @@ -11,7 +11,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "°C/m" ] + "Abbreviations": [ "∆°C/km" ] } ] }