From 696898937a56352a92172d062f6ffeaaa2bf8ac8 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 14:01:57 -0400 Subject: [PATCH 01/15] Add JSON file for the ReciprocalLength quantity. --- Common/UnitDefinitions/ReciprocalLength.json | 131 +++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Common/UnitDefinitions/ReciprocalLength.json diff --git a/Common/UnitDefinitions/ReciprocalLength.json b/Common/UnitDefinitions/ReciprocalLength.json new file mode 100644 index 0000000000..a31980b9f5 --- /dev/null +++ b/Common/UnitDefinitions/ReciprocalLength.json @@ -0,0 +1,131 @@ +{ + "Name": "ReciprocalLength", + "BaseUnit": "InverseMeter", + "XmlDoc": "Reciprocal (Inverse) Length is used in various fields of science and mathematics. It is defined as the inverse value of a length unit.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Reciprocal_length", + "BaseDimensions": { + "L": -1 + }, + "Units": [ + { + "SingularName": "InverseMeter", + "PluralName": "InverseMeter", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "m⁻¹", "1/m" ] + } + ] + }, + { + "SingularName": "InverseCentimeter", + "PluralName": "InverseCentimeter", + "FromUnitToBaseFunc": "x*1e2", + "FromBaseToUnitFunc": "x/1e2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "cm⁻¹", "1/cm" ] + } + ] + }, + { + "SingularName": "InverseMillimeter", + "PluralName": "InverseMillimeter", + "FromUnitToBaseFunc": "x*1e3", + "FromBaseToUnitFunc": "x/1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "mm⁻¹", "1/mm" ] + } + ] + }, + { + "SingularName": "InverseMile", + "PluralName": "InverseMile", + "FromUnitToBaseFunc": "x/1609.34", + "FromBaseToUnitFunc": "x*1609.34", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "mi⁻¹", "1/mi" ] + } + ] + }, + { + "SingularName": "InverseYard", + "PluralName": "InverseYard", + "FromUnitToBaseFunc": "x/0.9144", + "FromBaseToUnitFunc": "x*0.9144", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "yd⁻¹", "1/yd" ] + } + ] + }, + { + "SingularName": "InverseFoot", + "PluralName": "InverseFoot", + "FromUnitToBaseFunc": "x/0.3048", + "FromBaseToUnitFunc": "x*0.3048", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ft⁻¹", "1/ft" ] + } + ] + }, + { + "SingularName": "InverseUsSurveyFoot", + "PluralName": "InverseUsSurveyFeet", + "FromUnitToBaseFunc": "x*3937/1200", + "FromBaseToUnitFunc": "x*1200/3937", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ftUS⁻¹", "1/ftUS" ] + } + ] + }, + { + "SingularName": "InverseInch", + "PluralName": "InverseInch", + "FromUnitToBaseFunc": "x/2.54e-2", + "FromBaseToUnitFunc": "x*2.54e-2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "in⁻¹", "1/in" ] + } + ] + }, + { + "SingularName": "InverseMil", + "PluralName": "InverseMil", + "FromUnitToBaseFunc": "x/2.54e-5", + "FromBaseToUnitFunc": "x*2.54e-5", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "mil⁻¹", "1/mil" ] + } + ] + }, + { + "SingularName": "InverseMicroinch", + "PluralName": "InverseMicroinch", + "FromUnitToBaseFunc": "x/2.54e-8", + "FromBaseToUnitFunc": "x*2.54e-8", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "µin⁻¹", "1/µin" ] + } + ] + } + ] +} From c30702444436b0af6823d4eec18c89489c3bd292 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 14:22:22 -0400 Subject: [PATCH 02/15] Add generated code for ReciprocalLength quantity. --- .../Quantities/ReciprocalLength.g.cs | 283 +++++ .../ReciprocalLength/ReciprocalLength.nfproj | 42 + ...sNet.NanoFramework.ReciprocalLength.nuspec | 26 + .../ReciprocalLength/packages.config | 4 + .../Units/ReciprocalLengthUnit.g.cs | 42 + .../GeneratedCode/UnitsNet.nanoFramework.sln | 8 + ...umberToReciprocalLengthExtensionsTest.g.cs | 68 ++ .../NumberToReciprocalLengthExtensions.g.cs | 72 ++ .../CustomCode/ReciprocalLengthTests.cs | 43 + .../GeneratedCode/IQuantityTests.g.cs | 4 + .../TestsBase/ReciprocalLengthTestsBase.g.cs | 713 ++++++++++++ .../Quantities/ReciprocalLength.g.cs | 736 ++++++++++++ .../GeneratedCode/Quantity.g.cs | 6 + .../GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 10 + .../Units/ReciprocalLengthUnit.g.cs | 42 + .../Quantities/ReciprocalLength.g.cs | 1013 +++++++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 11 + UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 10 + UnitsNet/GeneratedCode/UnitConverter.g.cs | 19 + .../Units/ReciprocalLengthUnit.g.cs | 42 + 22 files changed, 3196 insertions(+) create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs create mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/ReciprocalLength.nfproj create mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/UnitsNet.NanoFramework.ReciprocalLength.nuspec create mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/packages.config create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ReciprocalLengthUnit.g.cs create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ReciprocalLengthUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ReciprocalLengthUnit.g.cs diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs new file mode 100644 index 0000000000..ca9773d06b --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -0,0 +1,283 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using System; +using UnitsNet.Units; + +namespace UnitsNet +{ + /// + /// + /// Reciprocal (Inverse) Length is used in various fields of science and mathematics. It is defined as the inverse value of a length unit. + /// + /// + /// https://en.wikipedia.org/wiki/Reciprocal_length + /// + public struct ReciprocalLength + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ReciprocalLengthUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ReciprocalLengthUnit Unit => _unit; + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public ReciprocalLength(double value, ReciprocalLengthUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of Duration, which is Second. All conversions go via this value. + /// + public static ReciprocalLengthUnit BaseUnit { get; } = ReciprocalLengthUnit.InverseMeter; + + /// + /// Represents the largest possible value of Duration + /// + public static ReciprocalLength MaxValue { get; } = new ReciprocalLength(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Duration + /// + public static ReciprocalLength MinValue { get; } = new ReciprocalLength(double.MinValue, BaseUnit); + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ReciprocalLength Zero { get; } = new ReciprocalLength(0, BaseUnit); + #region Conversion Properties + + /// + /// Get ReciprocalLength in InverseCentimeter. + /// + public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + + /// + /// Get ReciprocalLength in InverseFoot. + /// + public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + + /// + /// Get ReciprocalLength in InverseInch. + /// + public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + + /// + /// Get ReciprocalLength in InverseMeter. + /// + public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + + /// + /// Get ReciprocalLength in InverseMicroinch. + /// + public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + + /// + /// Get ReciprocalLength in InverseMil. + /// + public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + + /// + /// Get ReciprocalLength in InverseMile. + /// + public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + + /// + /// Get ReciprocalLength in InverseMillimeter. + /// + public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + + /// + /// Get ReciprocalLength in InverseUsSurveyFeet. + /// + public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); + + /// + /// Get ReciprocalLength in InverseYard. + /// + public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + + #endregion + + #region Static Factory Methods + + /// + /// Get ReciprocalLength from InverseCentimeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseCentimeter(double inversecentimeter) => new ReciprocalLength(inversecentimeter, ReciprocalLengthUnit.InverseCentimeter); + + /// + /// Get ReciprocalLength from InverseFoot. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseFoot(double inversefoot) => new ReciprocalLength(inversefoot, ReciprocalLengthUnit.InverseFoot); + + /// + /// Get ReciprocalLength from InverseInch. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseInch(double inverseinch) => new ReciprocalLength(inverseinch, ReciprocalLengthUnit.InverseInch); + + /// + /// Get ReciprocalLength from InverseMeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMeter(double inversemeter) => new ReciprocalLength(inversemeter, ReciprocalLengthUnit.InverseMeter); + + /// + /// Get ReciprocalLength from InverseMicroinch. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMicroinch(double inversemicroinch) => new ReciprocalLength(inversemicroinch, ReciprocalLengthUnit.InverseMicroinch); + + /// + /// Get ReciprocalLength from InverseMil. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMil(double inversemil) => new ReciprocalLength(inversemil, ReciprocalLengthUnit.InverseMil); + + /// + /// Get ReciprocalLength from InverseMile. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMile(double inversemile) => new ReciprocalLength(inversemile, ReciprocalLengthUnit.InverseMile); + + /// + /// Get ReciprocalLength from InverseMillimeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMillimeter(double inversemillimeter) => new ReciprocalLength(inversemillimeter, ReciprocalLengthUnit.InverseMillimeter); + + /// + /// Get ReciprocalLength from InverseUsSurveyFeet. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseUsSurveyFeet(double inverseussurveyfeet) => new ReciprocalLength(inverseussurveyfeet, ReciprocalLengthUnit.InverseUsSurveyFoot); + + /// + /// Get ReciprocalLength from InverseYard. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseYard(double inverseyard) => new ReciprocalLength(inverseyard, ReciprocalLengthUnit.InverseYard); + + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ReciprocalLength unit value. + public static ReciprocalLength From(double value, ReciprocalLengthUnit fromUnit) + { + return new ReciprocalLength(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ReciprocalLengthUnit unit) => GetValueAs(unit); + + /// + /// Converts this Duration to another Duration with the unit representation . + /// + /// A Duration with the specified unit. + public ReciprocalLength ToUnit(ReciprocalLengthUnit unit) + { + + var convertedValue = GetValueAs(unit); + return new ReciprocalLength(convertedValue, unit); + } + + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return _value*1e2; + case ReciprocalLengthUnit.InverseFoot: return _value/0.3048; + case ReciprocalLengthUnit.InverseInch: return _value/2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return _value; + case ReciprocalLengthUnit.InverseMicroinch: return _value/2.54e-8; + case ReciprocalLengthUnit.InverseMil: return _value/2.54e-5; + case ReciprocalLengthUnit.InverseMile: return _value/1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return _value*1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return _value*3937/1200; + case ReciprocalLengthUnit.InverseYard: return _value/0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double GetValueAs(ReciprocalLengthUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return baseUnitValue/1e2; + case ReciprocalLengthUnit.InverseFoot: return baseUnitValue*0.3048; + case ReciprocalLengthUnit.InverseInch: return baseUnitValue*2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return baseUnitValue; + case ReciprocalLengthUnit.InverseMicroinch: return baseUnitValue*2.54e-8; + case ReciprocalLengthUnit.InverseMil: return baseUnitValue*2.54e-5; + case ReciprocalLengthUnit.InverseMile: return baseUnitValue*1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return baseUnitValue/1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return baseUnitValue*1200/3937; + case ReciprocalLengthUnit.InverseYard: return baseUnitValue*0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/ReciprocalLength.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/ReciprocalLength.nfproj new file mode 100644 index 0000000000..5b98c3eebe --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/ReciprocalLength.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {83d6c79a-c71a-d467-284c-28edbbd059d2} + Library + Properties + 512 + UnitsNet + UnitsNet.ReciprocalLength + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.10.5-preview.18\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/UnitsNet.NanoFramework.ReciprocalLength.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/UnitsNet.NanoFramework.ReciprocalLength.nuspec new file mode 100644 index 0000000000..c17743381e --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/UnitsNet.NanoFramework.ReciprocalLength.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ReciprocalLength + 4.97.1 + Units.NET ReciprocalLength - nanoFramework + Andreas Gullberg Larsen,nanoFramework project contributors + UnitsNet + MIT + https://github.com/angularsen/UnitsNet + false + Adds ReciprocalLength units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. + https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png + + + Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). + en-US + nanoframework unit units measurement si metric imperial abbreviation abbreviations convert conversion parse c# .net immutable uwp uap winrt win10 windows runtime component reciprocallength + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/packages.config new file mode 100644 index 0000000000..dc595a08dd --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ReciprocalLength/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ReciprocalLengthUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ReciprocalLengthUnit.g.cs new file mode 100644 index 0000000000..166f08af87 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ReciprocalLengthUnit.g.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum ReciprocalLengthUnit + { + Undefined = 0, + InverseCentimeter, + InverseFoot, + InverseInch, + InverseMeter, + InverseMicroinch, + InverseMil, + InverseMile, + InverseMillimeter, + InverseUsSurveyFoot, + InverseYard, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index 99ed82fca7..dedb565eb6 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -160,6 +160,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReactiveEnergy", "ReactiveE EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReactivePower", "ReactivePower\ReactivePower.nfproj", "{6821b87e-65eb-bfdb-8fdc-8b183edf739e}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReciprocalLength", "ReciprocalLength\ReciprocalLength.nfproj", "{83d6c79a-c71a-d467-284c-28edbbd059d2}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "RelativeHumidity", "RelativeHumidity\RelativeHumidity.nfproj", "{4ac05c74-08c5-2153-f38c-976975747b5c}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "RotationalAcceleration", "RotationalAcceleration\RotationalAcceleration.nfproj", "{e2110137-6a36-f4d1-2219-26eb18fee74d}" @@ -698,6 +700,12 @@ Global {6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.ActiveCfg = Release|Any CPU {6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.Build.0 = Release|Any CPU {6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.Deploy.0 = Release|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Debug|Any CPU.Build.0 = Debug|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Release|Any CPU.ActiveCfg = Release|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Release|Any CPU.Build.0 = Release|Any CPU +{83d6c79a-c71a-d467-284c-28edbbd059d2}.Release|Any CPU.Deploy.0 = Release|Any CPU {4ac05c74-08c5-2153-f38c-976975747b5c}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4ac05c74-08c5-2153-f38c-976975747b5c}.Debug|Any CPU.Build.0 = Debug|Any CPU {4ac05c74-08c5-2153-f38c-976975747b5c}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs new file mode 100644 index 0000000000..3cd1fd9f91 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using UnitsNet.NumberExtensions.NumberToReciprocalLength; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToReciprocalLengthExtensionsTests + { + [Fact] + public void NumberToInverseCentimeterTest() => + Assert.Equal(ReciprocalLength.FromInverseCentimeter(2), 2.InverseCentimeter()); + + [Fact] + public void NumberToInverseFootTest() => + Assert.Equal(ReciprocalLength.FromInverseFoot(2), 2.InverseFoot()); + + [Fact] + public void NumberToInverseInchTest() => + Assert.Equal(ReciprocalLength.FromInverseInch(2), 2.InverseInch()); + + [Fact] + public void NumberToInverseMeterTest() => + Assert.Equal(ReciprocalLength.FromInverseMeter(2), 2.InverseMeter()); + + [Fact] + public void NumberToInverseMicroinchTest() => + Assert.Equal(ReciprocalLength.FromInverseMicroinch(2), 2.InverseMicroinch()); + + [Fact] + public void NumberToInverseMilTest() => + Assert.Equal(ReciprocalLength.FromInverseMil(2), 2.InverseMil()); + + [Fact] + public void NumberToInverseMileTest() => + Assert.Equal(ReciprocalLength.FromInverseMile(2), 2.InverseMile()); + + [Fact] + public void NumberToInverseMillimeterTest() => + Assert.Equal(ReciprocalLength.FromInverseMillimeter(2), 2.InverseMillimeter()); + + [Fact] + public void NumberToInverseUsSurveyFeetTest() => + Assert.Equal(ReciprocalLength.FromInverseUsSurveyFeet(2), 2.InverseUsSurveyFeet()); + + [Fact] + public void NumberToInverseYardTest() => + Assert.Equal(ReciprocalLength.FromInverseYard(2), 2.InverseYard()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs new file mode 100644 index 0000000000..59b7571ccc --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using System; + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToReciprocalLength +{ + /// + /// A number to ReciprocalLength Extensions + /// + public static class NumberToReciprocalLengthExtensions + { + /// + public static ReciprocalLength InverseCentimeter(this T value) => + ReciprocalLength.FromInverseCentimeter(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseFoot(this T value) => + ReciprocalLength.FromInverseFoot(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseInch(this T value) => + ReciprocalLength.FromInverseInch(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseMeter(this T value) => + ReciprocalLength.FromInverseMeter(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseMicroinch(this T value) => + ReciprocalLength.FromInverseMicroinch(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseMil(this T value) => + ReciprocalLength.FromInverseMil(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseMile(this T value) => + ReciprocalLength.FromInverseMile(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseMillimeter(this T value) => + ReciprocalLength.FromInverseMillimeter(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseUsSurveyFeet(this T value) => + ReciprocalLength.FromInverseUsSurveyFeet(Convert.ToDouble(value)); + + /// + public static ReciprocalLength InverseYard(this T value) => + ReciprocalLength.FromInverseYard(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs new file mode 100644 index 0000000000..53642ef85c --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using UnitsNet.Units; +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class ReciprocalLengthTests : ReciprocalLengthTestsBase + { + protected override bool SupportsSIUnitSystem => false; + + protected override double InverseMeterInOneInverseMeter => 1; + protected override double InverseCentimeterInOneInverseMeter => 1E-2; + protected override double InverseMillimeterInOneInverseMeter => 1E-3; + + protected override double InverseMileInOneInverseMeter => 1 / 0.000621371; + protected override double InverseYardInOneInverseMeter => 1 / 1.09361; + protected override double InverseFootInOneInverseMeter => 1 / 3.28084; + + protected override double InverseUsSurveyFeetInOneInverseMeter => 1 / 3.280833333333333; + + protected override double InverseInchInOneInverseMeter => 1 / 39.37007874; + protected override double InverseMilInOneInverseMeter => 1 / 39370.07874015; + protected override double InverseMicroinchInOneInverseMeter => 1 / 39370078.74015748; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 3714af6e50..26134289f8 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -113,6 +113,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, RatioChangeRateUnit.PercentPerSecond, Quantity.From(3, RatioChangeRateUnit.PercentPerSecond)); Assertion(3, ReactiveEnergyUnit.VoltampereReactiveHour, Quantity.From(3, ReactiveEnergyUnit.VoltampereReactiveHour)); Assertion(3, ReactivePowerUnit.VoltampereReactive, Quantity.From(3, ReactivePowerUnit.VoltampereReactive)); + Assertion(3, ReciprocalLengthUnit.InverseYard, Quantity.From(3, ReciprocalLengthUnit.InverseYard)); Assertion(3, RelativeHumidityUnit.Percent, Quantity.From(3, RelativeHumidityUnit.Percent)); Assertion(3, RotationalAccelerationUnit.RevolutionPerSecondSquared, Quantity.From(3, RotationalAccelerationUnit.RevolutionPerSecondSquared)); Assertion(3, RotationalSpeedUnit.RevolutionPerSecond, Quantity.From(3, RotationalSpeedUnit.RevolutionPerSecond)); @@ -228,6 +229,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(RatioChangeRate.Info, RatioChangeRate.Zero); Assertion(ReactiveEnergy.Info, ReactiveEnergy.Zero); Assertion(ReactivePower.Info, ReactivePower.Zero); + Assertion(ReciprocalLength.Info, ReciprocalLength.Zero); Assertion(RelativeHumidity.Info, RelativeHumidity.Zero); Assertion(RotationalAcceleration.Info, RotationalAcceleration.Zero); Assertion(RotationalSpeed.Info, RotationalSpeed.Zero); @@ -343,6 +345,7 @@ public void Type_EqualsStaticQuantityTypeProperty() Assertion(RatioChangeRate.QuantityType, RatioChangeRate.Zero); Assertion(ReactiveEnergy.QuantityType, ReactiveEnergy.Zero); Assertion(ReactivePower.QuantityType, ReactivePower.Zero); + Assertion(ReciprocalLength.QuantityType, ReciprocalLength.Zero); Assertion(RelativeHumidity.QuantityType, RelativeHumidity.Zero); Assertion(RotationalAcceleration.QuantityType, RotationalAcceleration.Zero); Assertion(RotationalSpeed.QuantityType, RotationalSpeed.Zero); @@ -458,6 +461,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(RatioChangeRate.BaseDimensions, RatioChangeRate.Zero); Assertion(ReactiveEnergy.BaseDimensions, ReactiveEnergy.Zero); Assertion(ReactivePower.BaseDimensions, ReactivePower.Zero); + Assertion(ReciprocalLength.BaseDimensions, ReciprocalLength.Zero); Assertion(RelativeHumidity.BaseDimensions, RelativeHumidity.Zero); Assertion(RotationalAcceleration.BaseDimensions, RotationalAcceleration.Zero); Assertion(RotationalSpeed.BaseDimensions, RotationalSpeed.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs new file mode 100644 index 0000000000..20587cd0bb --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -0,0 +1,713 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using System; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ReciprocalLength. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ReciprocalLengthTestsBase : QuantityTestsBase + { + protected abstract double InverseCentimeterInOneInverseMeter { get; } + protected abstract double InverseFootInOneInverseMeter { get; } + protected abstract double InverseInchInOneInverseMeter { get; } + protected abstract double InverseMeterInOneInverseMeter { get; } + protected abstract double InverseMicroinchInOneInverseMeter { get; } + protected abstract double InverseMilInOneInverseMeter { get; } + protected abstract double InverseMileInOneInverseMeter { get; } + protected abstract double InverseMillimeterInOneInverseMeter { get; } + protected abstract double InverseUsSurveyFeetInOneInverseMeter { get; } + protected abstract double InverseYardInOneInverseMeter { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double InverseCentimeterTolerance { get { return 1e-5; } } + protected virtual double InverseFootTolerance { get { return 1e-5; } } + protected virtual double InverseInchTolerance { get { return 1e-5; } } + protected virtual double InverseMeterTolerance { get { return 1e-5; } } + protected virtual double InverseMicroinchTolerance { get { return 1e-5; } } + protected virtual double InverseMilTolerance { get { return 1e-5; } } + protected virtual double InverseMileTolerance { get { return 1e-5; } } + protected virtual double InverseMillimeterTolerance { get { return 1e-5; } } + protected virtual double InverseUsSurveyFeetTolerance { get { return 1e-5; } } + protected virtual double InverseYardTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void Ctor_WithUndefinedUnit_ThrowsArgumentException() + { + Assert.Throws(() => new ReciprocalLength((double)0.0, ReciprocalLengthUnit.Undefined)); + } + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ReciprocalLength(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ReciprocalLengthUnit.InverseMeter, quantity.Unit); + } + + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new ReciprocalLength(double.PositiveInfinity, ReciprocalLengthUnit.InverseMeter)); + Assert.Throws(() => new ReciprocalLength(double.NegativeInfinity, ReciprocalLengthUnit.InverseMeter)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new ReciprocalLength(double.NaN, ReciprocalLengthUnit.InverseMeter)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ReciprocalLength(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ReciprocalLength(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ReciprocalLength) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ReciprocalLength_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ReciprocalLength(1, ReciprocalLengthUnit.InverseMeter); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ReciprocalLength.Zero, quantityInfo.Zero); + Assert.Equal("ReciprocalLength", quantityInfo.Name); + Assert.Equal(QuantityType.ReciprocalLength, quantityInfo.QuantityType); + + var units = EnumUtils.GetEnumValues().Except(new[] {ReciprocalLengthUnit.Undefined}).ToArray(); + var unitNames = units.Select(x => x.ToString()); + + // Obsolete members + Assert.Equal(units, quantityInfo.Units); + Assert.Equal(unitNames, quantityInfo.UnitNames); + } + + [Fact] + public void InverseMeterToReciprocalLengthUnits() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, inversemeter.InverseCentimeter, InverseCentimeterTolerance); + AssertEx.EqualTolerance(InverseFootInOneInverseMeter, inversemeter.InverseFoot, InverseFootTolerance); + AssertEx.EqualTolerance(InverseInchInOneInverseMeter, inversemeter.InverseInch, InverseInchTolerance); + AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, inversemeter.InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, inversemeter.InverseMicroinch, InverseMicroinchTolerance); + AssertEx.EqualTolerance(InverseMilInOneInverseMeter, inversemeter.InverseMil, InverseMilTolerance); + AssertEx.EqualTolerance(InverseMileInOneInverseMeter, inversemeter.InverseMile, InverseMileTolerance); + AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, inversemeter.InverseMillimeter, InverseMillimeterTolerance); + AssertEx.EqualTolerance(InverseUsSurveyFeetInOneInverseMeter, inversemeter.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); + AssertEx.EqualTolerance(InverseYardInOneInverseMeter, inversemeter.InverseYard, InverseYardTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseCentimeter); + AssertEx.EqualTolerance(1, quantity00.InverseCentimeter, InverseCentimeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, quantity00.Unit); + + var quantity01 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseFoot); + AssertEx.EqualTolerance(1, quantity01.InverseFoot, InverseFootTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseFoot, quantity01.Unit); + + var quantity02 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseInch); + AssertEx.EqualTolerance(1, quantity02.InverseInch, InverseInchTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseInch, quantity02.Unit); + + var quantity03 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMeter); + AssertEx.EqualTolerance(1, quantity03.InverseMeter, InverseMeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMeter, quantity03.Unit); + + var quantity04 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMicroinch); + AssertEx.EqualTolerance(1, quantity04.InverseMicroinch, InverseMicroinchTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, quantity04.Unit); + + var quantity05 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMil); + AssertEx.EqualTolerance(1, quantity05.InverseMil, InverseMilTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMil, quantity05.Unit); + + var quantity06 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMile); + AssertEx.EqualTolerance(1, quantity06.InverseMile, InverseMileTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMile, quantity06.Unit); + + var quantity07 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMillimeter); + AssertEx.EqualTolerance(1, quantity07.InverseMillimeter, InverseMillimeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, quantity07.Unit); + + var quantity08 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseUsSurveyFoot); + AssertEx.EqualTolerance(1, quantity08.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, quantity08.Unit); + + var quantity09 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseYard); + AssertEx.EqualTolerance(1, quantity09.InverseYard, InverseYardTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseYard, quantity09.Unit); + + } + + [Fact] + public void FromInverseMeter_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.PositiveInfinity)); + Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.NegativeInfinity)); + } + + [Fact] + public void FromInverseMeter_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.NaN)); + } + + [Fact] + public void As() + { + var inversemeter = ReciprocalLength.FromInverseMeter(1); + AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseCentimeter), InverseCentimeterTolerance); + AssertEx.EqualTolerance(InverseFootInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseFoot), InverseFootTolerance); + AssertEx.EqualTolerance(InverseInchInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseInch), InverseInchTolerance); + AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMeter), InverseMeterTolerance); + AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMicroinch), InverseMicroinchTolerance); + AssertEx.EqualTolerance(InverseMilInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMil), InverseMilTolerance); + AssertEx.EqualTolerance(InverseMileInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMile), InverseMileTolerance); + AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMillimeter), InverseMillimeterTolerance); + AssertEx.EqualTolerance(InverseUsSurveyFeetInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseUsSurveyFoot), InverseUsSurveyFeetTolerance); + AssertEx.EqualTolerance(InverseYardInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseYard), InverseYardTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + + [Fact] + public void ToUnit() + { + var inversemeter = ReciprocalLength.FromInverseMeter(1); + + var inversecentimeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseCentimeter); + AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, (double)inversecentimeterQuantity.Value, InverseCentimeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, inversecentimeterQuantity.Unit); + + var inversefootQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseFoot); + AssertEx.EqualTolerance(InverseFootInOneInverseMeter, (double)inversefootQuantity.Value, InverseFootTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseFoot, inversefootQuantity.Unit); + + var inverseinchQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseInch); + AssertEx.EqualTolerance(InverseInchInOneInverseMeter, (double)inverseinchQuantity.Value, InverseInchTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseInch, inverseinchQuantity.Unit); + + var inversemeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMeter); + AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, (double)inversemeterQuantity.Value, InverseMeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMeter, inversemeterQuantity.Unit); + + var inversemicroinchQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMicroinch); + AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, (double)inversemicroinchQuantity.Value, InverseMicroinchTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, inversemicroinchQuantity.Unit); + + var inversemilQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMil); + AssertEx.EqualTolerance(InverseMilInOneInverseMeter, (double)inversemilQuantity.Value, InverseMilTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMil, inversemilQuantity.Unit); + + var inversemileQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMile); + AssertEx.EqualTolerance(InverseMileInOneInverseMeter, (double)inversemileQuantity.Value, InverseMileTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMile, inversemileQuantity.Unit); + + var inversemillimeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMillimeter); + AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, (double)inversemillimeterQuantity.Value, InverseMillimeterTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, inversemillimeterQuantity.Unit); + + var inverseussurveyfootQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseUsSurveyFoot); + AssertEx.EqualTolerance(InverseUsSurveyFeetInOneInverseMeter, (double)inverseussurveyfootQuantity.Value, InverseUsSurveyFeetTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, inverseussurveyfootQuantity.Unit); + + var inverseyardQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseYard); + AssertEx.EqualTolerance(InverseYardInOneInverseMeter, (double)inverseyardQuantity.Value, InverseYardTolerance); + Assert.Equal(ReciprocalLengthUnit.InverseYard, inverseyardQuantity.Unit); + } + + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ReciprocalLength.FromInverseMeter(1).ToBaseUnit(); + Assert.Equal(ReciprocalLength.BaseUnit, quantityInBaseUnit.Unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseCentimeter(inversemeter.InverseCentimeter).InverseMeter, InverseCentimeterTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseFoot(inversemeter.InverseFoot).InverseMeter, InverseFootTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseInch(inversemeter.InverseInch).InverseMeter, InverseInchTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMeter(inversemeter.InverseMeter).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMicroinch(inversemeter.InverseMicroinch).InverseMeter, InverseMicroinchTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMil(inversemeter.InverseMil).InverseMeter, InverseMilTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMile(inversemeter.InverseMile).InverseMeter, InverseMileTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMillimeter(inversemeter.InverseMillimeter).InverseMeter, InverseMillimeterTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseUsSurveyFeet(inversemeter.InverseUsSurveyFeet).InverseMeter, InverseUsSurveyFeetTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseYard(inversemeter.InverseYard).InverseMeter, InverseYardTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ReciprocalLength v = ReciprocalLength.FromInverseMeter(1); + AssertEx.EqualTolerance(-1, -v.InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeter(3)-v).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(2, (v + v).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(10, (v*10).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(10, (10*v).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeter(10)/5).InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(2, ReciprocalLength.FromInverseMeter(10)/ReciprocalLength.FromInverseMeter(5), InverseMeterTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ReciprocalLength oneInverseMeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength twoInverseMeter = ReciprocalLength.FromInverseMeter(2); + + Assert.True(oneInverseMeter < twoInverseMeter); + Assert.True(oneInverseMeter <= twoInverseMeter); + Assert.True(twoInverseMeter > oneInverseMeter); + Assert.True(twoInverseMeter >= oneInverseMeter); + + Assert.False(oneInverseMeter > twoInverseMeter); + Assert.False(oneInverseMeter >= twoInverseMeter); + Assert.False(twoInverseMeter < oneInverseMeter); + Assert.False(twoInverseMeter <= oneInverseMeter); + } + + [Fact] + public void CompareToIsImplemented() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + Assert.Equal(0, inversemeter.CompareTo(inversemeter)); + Assert.True(inversemeter.CompareTo(ReciprocalLength.Zero) > 0); + Assert.True(ReciprocalLength.Zero.CompareTo(inversemeter) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + Assert.Throws(() => inversemeter.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + Assert.Throws(() => inversemeter.CompareTo(null)); + } + + [Fact] + public void EqualityOperators() + { + var a = ReciprocalLength.FromInverseMeter(1); + var b = ReciprocalLength.FromInverseMeter(2); + +#pragma warning disable CS8073 +// ReSharper disable EqualExpressionComparison + + Assert.True(a == a); + Assert.False(a != a); + + Assert.True(a != b); + Assert.False(a == b); + + Assert.False(a == null); + Assert.False(null == a); + +// ReSharper restore EqualExpressionComparison +#pragma warning restore CS8073 + } + + [Fact] + public void Equals_SameType_IsImplemented() + { + var a = ReciprocalLength.FromInverseMeter(1); + var b = ReciprocalLength.FromInverseMeter(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + } + + [Fact] + public void Equals_QuantityAsObject_IsImplemented() + { + object a = ReciprocalLength.FromInverseMeter(1); + object b = ReciprocalLength.FromInverseMeter(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + Assert.False(a.Equals((object)null)); + } + + [Fact] + public void Equals_RelativeTolerance_IsImplemented() + { + var v = ReciprocalLength.FromInverseMeter(1); + Assert.True(v.Equals(ReciprocalLength.FromInverseMeter(1), InverseMeterTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ReciprocalLength.Zero, InverseMeterTolerance, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ReciprocalLength.FromInverseMeter(1); + Assert.Throws(() => v.Equals(ReciprocalLength.FromInverseMeter(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + Assert.False(inversemeter.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + Assert.False(inversemeter.Equals(null)); + } + + [Fact] + public void UnitsDoesNotContainUndefined() + { + Assert.DoesNotContain(ReciprocalLengthUnit.Undefined, ReciprocalLength.Units); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ReciprocalLengthUnit)).Cast(); + foreach(var unit in units) + { + if(unit == ReciprocalLengthUnit.Undefined) + continue; + + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ReciprocalLength.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentUICulture; + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 cm⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseCentimeter).ToString()); + Assert.Equal("1 ft⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseFoot).ToString()); + Assert.Equal("1 in⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseInch).ToString()); + Assert.Equal("1 m⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMeter).ToString()); + Assert.Equal("1 µin⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMicroinch).ToString()); + Assert.Equal("1 mil⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMil).ToString()); + Assert.Equal("1 mi⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMile).ToString()); + Assert.Equal("1 mm⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMillimeter).ToString()); + Assert.Equal("1 ftUS⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseUsSurveyFoot).ToString()); + Assert.Equal("1 yd⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseYard).ToString()); + } + finally + { + Thread.CurrentThread.CurrentUICulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 cm⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseCentimeter).ToString(swedishCulture)); + Assert.Equal("1 ft⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseFoot).ToString(swedishCulture)); + Assert.Equal("1 in⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseInch).ToString(swedishCulture)); + Assert.Equal("1 m⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMeter).ToString(swedishCulture)); + Assert.Equal("1 µin⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMicroinch).ToString(swedishCulture)); + Assert.Equal("1 mil⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMil).ToString(swedishCulture)); + Assert.Equal("1 mi⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMile).ToString(swedishCulture)); + Assert.Equal("1 mm⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseMillimeter).ToString(swedishCulture)); + Assert.Equal("1 ftUS⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseUsSurveyFoot).ToString(swedishCulture)); + Assert.Equal("1 yd⁻¹", new ReciprocalLength(1, ReciprocalLengthUnit.InverseYard).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentUICulture; + try + { + CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s1")); + Assert.Equal("0.12 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s2")); + Assert.Equal("0.123 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s3")); + Assert.Equal("0.1235 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s4")); + } + finally + { + CultureInfo.CurrentUICulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s1", culture)); + Assert.Equal("0.12 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s2", culture)); + Assert.Equal("0.123 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s3", culture)); + Assert.Equal("0.1235 m⁻¹", new ReciprocalLength(0.123456, ReciprocalLengthUnit.InverseMeter).ToString("s4", culture)); + } + + + [Fact] + public void ToString_NullFormat_ThrowsArgumentNullException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => quantity.ToString(null, null, null)); + } + + [Fact] + public void ToString_NullArgs_ThrowsArgumentNullException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => quantity.ToString(null, "g", null)); + } + + [Fact] + public void ToString_NullProvider_EqualsCurrentUICulture() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); + } + + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ReciprocalLength))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ReciprocalLengthUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityType_EqualsQuantityType() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(QuantityType.ReciprocalLength, Convert.ChangeType(quantity, typeof(QuantityType))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(ReciprocalLength.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(ReciprocalLength.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ReciprocalLength.FromInverseMeter(1.0); + Assert.Equal(new {ReciprocalLength.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); + } + + [Theory] + [InlineData(1.0)] + [InlineData(-1.0)] + public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) + { + var quantity = ReciprocalLength.FromInverseMeter(value); + Assert.Equal(ReciprocalLength.FromInverseMeter(-value), -quantity); + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs new file mode 100644 index 0000000000..47f1670f66 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -0,0 +1,736 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// Reciprocal (Inverse) Length is used in various fields of science and mathematics. It is defined as the inverse value of a length unit. + /// + /// + /// https://en.wikipedia.org/wiki/Reciprocal_length + /// + // 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. + public sealed partial class ReciprocalLength : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ReciprocalLengthUnit? _unit; + + static ReciprocalLength() + { + BaseDimensions = new BaseDimensions(-1, 0, 0, 0, 0, 0, 0); + Info = new QuantityInfo(QuantityType.ReciprocalLength, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit InverseMeter. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public ReciprocalLength() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private ReciprocalLength(double value, ReciprocalLengthUnit unit) + { + if(unit == ReciprocalLengthUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of ReciprocalLength, which is InverseMeter. All conversions go via this value. + /// + public static ReciprocalLengthUnit BaseUnit { get; } = ReciprocalLengthUnit.InverseMeter; + + /// + /// Represents the largest possible value of ReciprocalLength + /// + public static ReciprocalLength MaxValue { get; } = new ReciprocalLength(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ReciprocalLength + /// + public static ReciprocalLength MinValue { get; } = new ReciprocalLength(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.ReciprocalLength; + + /// + /// All units of measurement for the ReciprocalLength quantity. + /// + public static ReciprocalLengthUnit[] Units { get; } = Enum.GetValues(typeof(ReciprocalLengthUnit)).Cast().Except(new ReciprocalLengthUnit[]{ ReciprocalLengthUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit InverseMeter. + /// + public static ReciprocalLength Zero { get; } = new ReciprocalLength(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public ReciprocalLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => ReciprocalLength.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ReciprocalLength.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get ReciprocalLength in InverseCentimeter. + /// + public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + + /// + /// Get ReciprocalLength in InverseFoot. + /// + public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + + /// + /// Get ReciprocalLength in InverseInch. + /// + public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + + /// + /// Get ReciprocalLength in InverseMeter. + /// + public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + + /// + /// Get ReciprocalLength in InverseMicroinch. + /// + public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + + /// + /// Get ReciprocalLength in InverseMil. + /// + public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + + /// + /// Get ReciprocalLength in InverseMile. + /// + public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + + /// + /// Get ReciprocalLength in InverseMillimeter. + /// + public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + + /// + /// Get ReciprocalLength in InverseUsSurveyFeet. + /// + public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); + + /// + /// Get ReciprocalLength in InverseYard. + /// + public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ReciprocalLengthUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(ReciprocalLengthUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get ReciprocalLength from InverseCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseCentimeter(double inversecentimeter) + { + double value = (double) inversecentimeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseCentimeter); + } + /// + /// Get ReciprocalLength from InverseFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseFoot(double inversefoot) + { + double value = (double) inversefoot; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseFoot); + } + /// + /// Get ReciprocalLength from InverseInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseInch(double inverseinch) + { + double value = (double) inverseinch; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseInch); + } + /// + /// Get ReciprocalLength from InverseMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseMeter(double inversemeter) + { + double value = (double) inversemeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); + } + /// + /// Get ReciprocalLength from InverseMicroinch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseMicroinch(double inversemicroinch) + { + double value = (double) inversemicroinch; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMicroinch); + } + /// + /// Get ReciprocalLength from InverseMil. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseMil(double inversemil) + { + double value = (double) inversemil; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMil); + } + /// + /// Get ReciprocalLength from InverseMile. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseMile(double inversemile) + { + double value = (double) inversemile; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMile); + } + /// + /// Get ReciprocalLength from InverseMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseMillimeter(double inversemillimeter) + { + double value = (double) inversemillimeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMillimeter); + } + /// + /// Get ReciprocalLength from InverseUsSurveyFeet. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseUsSurveyFeet(double inverseussurveyfeet) + { + double value = (double) inverseussurveyfeet; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseUsSurveyFoot); + } + /// + /// Get ReciprocalLength from InverseYard. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ReciprocalLength FromInverseYard(double inverseyard) + { + double value = (double) inverseyard; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseYard); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ReciprocalLength unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ReciprocalLength From(double value, ReciprocalLengthUnit fromUnit) + { + return new ReciprocalLength((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static ReciprocalLength Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static ReciprocalLength Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out ReciprocalLength result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ReciprocalLength result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ReciprocalLengthUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static ReciprocalLengthUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out ReciprocalLengthUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ReciprocalLengthUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is ReciprocalLength objReciprocalLength)) throw new ArgumentException("Expected type ReciprocalLength.", nameof(obj)); + + return CompareTo(objReciprocalLength); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(ReciprocalLength other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is ReciprocalLength objReciprocalLength)) + return false; + + return Equals(objReciprocalLength); + } + + public bool Equals(ReciprocalLength other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another ReciprocalLength within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(ReciprocalLength other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current ReciprocalLength. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((ReciprocalLengthUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ReciprocalLengthUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this ReciprocalLength to another ReciprocalLength with the unit representation . + /// + /// A ReciprocalLength with the specified unit. + public ReciprocalLength ToUnit(ReciprocalLengthUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new ReciprocalLength(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return _value*1e2; + case ReciprocalLengthUnit.InverseFoot: return _value/0.3048; + case ReciprocalLengthUnit.InverseInch: return _value/2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return _value; + case ReciprocalLengthUnit.InverseMicroinch: return _value/2.54e-8; + case ReciprocalLengthUnit.InverseMil: return _value/2.54e-5; + case ReciprocalLengthUnit.InverseMile: return _value/1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return _value*1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return _value*3937/1200; + case ReciprocalLengthUnit.InverseYard: return _value/0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(ReciprocalLengthUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return baseUnitValue/1e2; + case ReciprocalLengthUnit.InverseFoot: return baseUnitValue*0.3048; + case ReciprocalLengthUnit.InverseInch: return baseUnitValue*2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return baseUnitValue; + case ReciprocalLengthUnit.InverseMicroinch: return baseUnitValue*2.54e-8; + case ReciprocalLengthUnit.InverseMil: return baseUnitValue*2.54e-5; + case ReciprocalLengthUnit.InverseMile: return baseUnitValue*1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return baseUnitValue/1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return baseUnitValue*1200/3937; + case ReciprocalLengthUnit.InverseYard: return baseUnitValue*0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs index ab3efa0904..e73842df63 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -278,6 +278,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case ReactivePowerUnit reactivePowerUnit: quantity = ReactivePower.From(value, reactivePowerUnit); return true; + case ReciprocalLengthUnit reciprocalLengthUnit: + quantity = ReciprocalLength.From(value, reciprocalLengthUnit); + return true; case RelativeHumidityUnit relativeHumidityUnit: quantity = RelativeHumidity.From(value, relativeHumidityUnit); return true; @@ -652,6 +655,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(ReactivePower)) return parser.TryParse(quantityString, formatProvider, ReactivePower.From, out quantity); + if (quantityType == typeof(ReciprocalLength)) + return parser.TryParse(quantityString, formatProvider, ReciprocalLength.From, out quantity); + if (quantityType == typeof(RelativeHumidity)) return parser.TryParse(quantityString, formatProvider, RelativeHumidity.From, out quantity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index 74594c38ac..a728042709 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -108,6 +108,7 @@ public enum QuantityType RatioChangeRate, ReactiveEnergy, ReactivePower, + ReciprocalLength, RelativeHumidity, RotationalAcceleration, RotationalSpeed, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index 2da8980d4a..0e36ff20b0 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -1198,6 +1198,16 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.KilovoltampereReactive, new string[]{"kvar"}), ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.MegavoltampereReactive, new string[]{"Mvar"}), ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.VoltampereReactive, new string[]{"var"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseCentimeter, new string[]{"cm⁻¹", "1/cm"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseFoot, new string[]{"ft⁻¹", "1/ft"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseInch, new string[]{"in⁻¹", "1/in"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMeter, new string[]{"m⁻¹", "1/m"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMicroinch, new string[]{"µin⁻¹", "1/µin"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMil, new string[]{"mil⁻¹", "1/mil"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMile, new string[]{"mi⁻¹", "1/mi"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMillimeter, new string[]{"mm⁻¹", "1/mm"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseUsSurveyFoot, new string[]{"ftUS⁻¹", "1/ftUS"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseYard, new string[]{"yd⁻¹", "1/yd"}), ("en-US", typeof(RelativeHumidityUnit), (int)RelativeHumidityUnit.Percent, new string[]{"%RH"}), ("en-US", typeof(RotationalAccelerationUnit), (int)RotationalAccelerationUnit.DegreePerSecondSquared, new string[]{"°/s²", "deg/s²"}), ("en-US", typeof(RotationalAccelerationUnit), (int)RotationalAccelerationUnit.RadianPerSecondSquared, new string[]{"rad/s²"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ReciprocalLengthUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ReciprocalLengthUnit.g.cs new file mode 100644 index 0000000000..166f08af87 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ReciprocalLengthUnit.g.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum ReciprocalLengthUnit + { + Undefined = 0, + InverseCentimeter, + InverseFoot, + InverseInch, + InverseMeter, + InverseMicroinch, + InverseMil, + InverseMile, + InverseMillimeter, + InverseUsSurveyFoot, + InverseYard, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs new file mode 100644 index 0000000000..7793378b29 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -0,0 +1,1013 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// Reciprocal (Inverse) Length is used in various fields of science and mathematics. It is defined as the inverse value of a length unit. + /// + /// + /// https://en.wikipedia.org/wiki/Reciprocal_length + /// + public partial struct ReciprocalLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ReciprocalLengthUnit? _unit; + + static ReciprocalLength() + { + BaseDimensions = new BaseDimensions(-1, 0, 0, 0, 0, 0, 0); + + Info = new QuantityInfo("ReciprocalLength", + new UnitInfo[] { + new UnitInfo(ReciprocalLengthUnit.InverseCentimeter, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseFoot, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseInch, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseMeter, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseMicroinch, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseMil, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseMile, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseMillimeter, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseUsSurveyFoot, BaseUnits.Undefined), + new UnitInfo(ReciprocalLengthUnit.InverseYard, BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions, QuantityType.ReciprocalLength); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public ReciprocalLength(double value, ReciprocalLengthUnit unit) + { + if(unit == ReciprocalLengthUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to construct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public ReciprocalLength(double value, UnitSystem unitSystem) + { + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of ReciprocalLength, which is InverseMeter. All conversions go via this value. + /// + public static ReciprocalLengthUnit BaseUnit { get; } = ReciprocalLengthUnit.InverseMeter; + + /// + /// Represents the largest possible value of ReciprocalLength + /// + [Obsolete("MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848.")] + public static ReciprocalLength MaxValue { get; } = new ReciprocalLength(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ReciprocalLength + /// + [Obsolete("MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848.")] + public static ReciprocalLength MinValue { get; } = new ReciprocalLength(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + [Obsolete("QuantityType will be removed in the future. Use Info property instead.")] + public static QuantityType QuantityType { get; } = QuantityType.ReciprocalLength; + + /// + /// All units of measurement for the ReciprocalLength quantity. + /// + public static ReciprocalLengthUnit[] Units { get; } = Enum.GetValues(typeof(ReciprocalLengthUnit)).Cast().Except(new ReciprocalLengthUnit[]{ ReciprocalLengthUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit InverseMeter. + /// + public static ReciprocalLength Zero { get; } = new ReciprocalLength(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public ReciprocalLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => ReciprocalLength.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ReciprocalLength.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get ReciprocalLength in InverseCentimeter. + /// + public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + + /// + /// Get ReciprocalLength in InverseFoot. + /// + public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + + /// + /// Get ReciprocalLength in InverseInch. + /// + public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + + /// + /// Get ReciprocalLength in InverseMeter. + /// + public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + + /// + /// Get ReciprocalLength in InverseMicroinch. + /// + public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + + /// + /// Get ReciprocalLength in InverseMil. + /// + public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + + /// + /// Get ReciprocalLength in InverseMile. + /// + public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + + /// + /// Get ReciprocalLength in InverseMillimeter. + /// + public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + + /// + /// Get ReciprocalLength in InverseUsSurveyFeet. + /// + public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); + + /// + /// Get ReciprocalLength in InverseYard. + /// + public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ReciprocalLengthUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(ReciprocalLengthUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get ReciprocalLength from InverseCentimeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseCentimeter(QuantityValue inversecentimeter) + { + double value = (double) inversecentimeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseCentimeter); + } + /// + /// Get ReciprocalLength from InverseFoot. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseFoot(QuantityValue inversefoot) + { + double value = (double) inversefoot; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseFoot); + } + /// + /// Get ReciprocalLength from InverseInch. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseInch(QuantityValue inverseinch) + { + double value = (double) inverseinch; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseInch); + } + /// + /// Get ReciprocalLength from InverseMeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMeter(QuantityValue inversemeter) + { + double value = (double) inversemeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); + } + /// + /// Get ReciprocalLength from InverseMicroinch. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMicroinch(QuantityValue inversemicroinch) + { + double value = (double) inversemicroinch; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMicroinch); + } + /// + /// Get ReciprocalLength from InverseMil. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMil(QuantityValue inversemil) + { + double value = (double) inversemil; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMil); + } + /// + /// Get ReciprocalLength from InverseMile. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMile(QuantityValue inversemile) + { + double value = (double) inversemile; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMile); + } + /// + /// Get ReciprocalLength from InverseMillimeter. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseMillimeter(QuantityValue inversemillimeter) + { + double value = (double) inversemillimeter; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMillimeter); + } + /// + /// Get ReciprocalLength from InverseUsSurveyFeet. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseUsSurveyFeet(QuantityValue inverseussurveyfeet) + { + double value = (double) inverseussurveyfeet; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseUsSurveyFoot); + } + /// + /// Get ReciprocalLength from InverseYard. + /// + /// If value is NaN or Infinity. + public static ReciprocalLength FromInverseYard(QuantityValue inverseyard) + { + double value = (double) inverseyard; + return new ReciprocalLength(value, ReciprocalLengthUnit.InverseYard); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ReciprocalLength unit value. + public static ReciprocalLength From(QuantityValue value, ReciprocalLengthUnit fromUnit) + { + return new ReciprocalLength((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static ReciprocalLength Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static ReciprocalLength Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse(string? str, out ReciprocalLength result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse(string? str, IFormatProvider? provider, out ReciprocalLength result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ReciprocalLengthUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// Format to use when parsing number and unit. Defaults to if null. + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ReciprocalLengthUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out ReciprocalLengthUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider? provider, out ReciprocalLengthUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ReciprocalLength operator -(ReciprocalLength right) + { + return new ReciprocalLength(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ReciprocalLength operator +(ReciprocalLength left, ReciprocalLength right) + { + return new ReciprocalLength(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static ReciprocalLength operator -(ReciprocalLength left, ReciprocalLength right) + { + return new ReciprocalLength(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static ReciprocalLength operator *(double left, ReciprocalLength right) + { + return new ReciprocalLength(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ReciprocalLength operator *(ReciprocalLength left, double right) + { + return new ReciprocalLength(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ReciprocalLength operator /(ReciprocalLength left, double right) + { + return new ReciprocalLength(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ReciprocalLength left, ReciprocalLength right) + { + return left.InverseMeter / right.InverseMeter; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ReciprocalLength left, ReciprocalLength right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ReciprocalLength left, ReciprocalLength right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(ReciprocalLength left, ReciprocalLength right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(ReciprocalLength left, ReciprocalLength right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(ReciprocalLength left, ReciprocalLength right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(ReciprocalLength left, ReciprocalLength right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is ReciprocalLength objReciprocalLength)) throw new ArgumentException("Expected type ReciprocalLength.", nameof(obj)); + + return CompareTo(objReciprocalLength); + } + + /// + public int CompareTo(ReciprocalLength other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is ReciprocalLength objReciprocalLength)) + return false; + + return Equals(objReciprocalLength); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(ReciprocalLength other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another ReciprocalLength within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(ReciprocalLength other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current ReciprocalLength. + public override int GetHashCode() + { + return new { Info.Name, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ReciprocalLengthUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ReciprocalLengthUnit unitAsReciprocalLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); + + return As(unitAsReciprocalLengthUnit); + } + + /// + /// Converts this ReciprocalLength to another ReciprocalLength with the unit representation . + /// + /// A ReciprocalLength with the specified unit. + public ReciprocalLength ToUnit(ReciprocalLengthUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ReciprocalLength(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ReciprocalLengthUnit unitAsReciprocalLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsReciprocalLengthUnit); + } + + /// + public ReciprocalLength ToUnit(UnitSystem unitSystem) + { + if(unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(ReciprocalLengthUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return _value*1e2; + case ReciprocalLengthUnit.InverseFoot: return _value/0.3048; + case ReciprocalLengthUnit.InverseInch: return _value/2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return _value; + case ReciprocalLengthUnit.InverseMicroinch: return _value/2.54e-8; + case ReciprocalLengthUnit.InverseMil: return _value/2.54e-5; + case ReciprocalLengthUnit.InverseMile: return _value/1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return _value*1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return _value*3937/1200; + case ReciprocalLengthUnit.InverseYard: return _value/0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + internal ReciprocalLength ToBaseUnit() + { + var baseUnitValue = GetValueInBaseUnit(); + return new ReciprocalLength(baseUnitValue, BaseUnit); + } + + private double GetValueAs(ReciprocalLengthUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case ReciprocalLengthUnit.InverseCentimeter: return baseUnitValue/1e2; + case ReciprocalLengthUnit.InverseFoot: return baseUnitValue*0.3048; + case ReciprocalLengthUnit.InverseInch: return baseUnitValue*2.54e-2; + case ReciprocalLengthUnit.InverseMeter: return baseUnitValue; + case ReciprocalLengthUnit.InverseMicroinch: return baseUnitValue*2.54e-8; + case ReciprocalLengthUnit.InverseMil: return baseUnitValue*2.54e-5; + case ReciprocalLengthUnit.InverseMile: return baseUnitValue*1609.34; + case ReciprocalLengthUnit.InverseMillimeter: return baseUnitValue/1e3; + case ReciprocalLengthUnit.InverseUsSurveyFoot: return baseUnitValue*1200/3937; + case ReciprocalLengthUnit.InverseYard: return baseUnitValue*0.9144; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString(IFormatProvider? provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider? provider) + { + return QuantityFormatter.Format(this, format, provider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ReciprocalLength)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ReciprocalLength)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ReciprocalLength)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(ReciprocalLength)) + return this; + else if(conversionType == typeof(ReciprocalLengthUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return ReciprocalLength.QuantityType; + else if(conversionType == typeof(QuantityInfo)) + return ReciprocalLength.Info; + else if(conversionType == typeof(BaseDimensions)) + return ReciprocalLength.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ReciprocalLength)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 379d90ba31..17e8e4aa1a 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -117,6 +117,7 @@ public static partial class Quantity { "RatioChangeRate", RatioChangeRate.Info }, { "ReactiveEnergy", ReactiveEnergy.Info }, { "ReactivePower", ReactivePower.Info }, + { "ReciprocalLength", ReciprocalLength.Info }, { "RelativeHumidity", RelativeHumidity.Info }, { "RotationalAcceleration", RotationalAcceleration.Info }, { "RotationalSpeed", RotationalSpeed.Info }, @@ -231,6 +232,7 @@ public static partial class Quantity { "RatioChangeRate", QuantityType.RatioChangeRate }, { "ReactiveEnergy", QuantityType.ReactiveEnergy }, { "ReactivePower", QuantityType.ReactivePower }, + { "ReciprocalLength", QuantityType.ReciprocalLength }, { "RelativeHumidity", QuantityType.RelativeHumidity }, { "RotationalAcceleration", QuantityType.RotationalAcceleration }, { "RotationalSpeed", QuantityType.RotationalSpeed }, @@ -431,6 +433,8 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return ReactiveEnergy.From(value, ReactiveEnergy.BaseUnit); case QuantityType.ReactivePower: return ReactivePower.From(value, ReactivePower.BaseUnit); + case QuantityType.ReciprocalLength: + return ReciprocalLength.From(value, ReciprocalLength.BaseUnit); case QuantityType.RelativeHumidity: return RelativeHumidity.From(value, RelativeHumidity.BaseUnit); case QuantityType.RotationalAcceleration: @@ -662,6 +666,8 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu return ReactiveEnergy.From(value, ReactiveEnergy.BaseUnit); case "ReactivePower": return ReactivePower.From(value, ReactivePower.BaseUnit); + case "ReciprocalLength": + return ReciprocalLength.From(value, ReciprocalLength.BaseUnit); case "RelativeHumidity": return RelativeHumidity.From(value, RelativeHumidity.BaseUnit); case "RotationalAcceleration": @@ -973,6 +979,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity? quanti case ReactivePowerUnit reactivePowerUnit: quantity = ReactivePower.From(value, reactivePowerUnit); return true; + case ReciprocalLengthUnit reciprocalLengthUnit: + quantity = ReciprocalLength.From(value, reciprocalLengthUnit); + return true; case RelativeHumidityUnit relativeHumidityUnit: quantity = RelativeHumidity.From(value, relativeHumidityUnit); return true; @@ -1245,6 +1254,8 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, return parser.TryParse(quantityString, formatProvider, ReactiveEnergy.From, out quantity); case Type _ when quantityType == typeof(ReactivePower): return parser.TryParse(quantityString, formatProvider, ReactivePower.From, out quantity); + case Type _ when quantityType == typeof(ReciprocalLength): + return parser.TryParse(quantityString, formatProvider, ReciprocalLength.From, out quantity); case Type _ when quantityType == typeof(RelativeHumidity): return parser.TryParse(quantityString, formatProvider, RelativeHumidity.From, out quantity); case Type _ when quantityType == typeof(RotationalAcceleration): diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 487624b259..4e4aa97330 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -110,6 +110,7 @@ public enum QuantityType RatioChangeRate, ReactiveEnergy, ReactivePower, + ReciprocalLength, RelativeHumidity, RotationalAcceleration, RotationalSpeed, diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index ca8e554c6e..ee5df60b78 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -1198,6 +1198,16 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.KilovoltampereReactive, new string[]{"kvar"}), ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.MegavoltampereReactive, new string[]{"Mvar"}), ("en-US", typeof(ReactivePowerUnit), (int)ReactivePowerUnit.VoltampereReactive, new string[]{"var"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseCentimeter, new string[]{"cm⁻¹", "1/cm"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseFoot, new string[]{"ft⁻¹", "1/ft"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseInch, new string[]{"in⁻¹", "1/in"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMeter, new string[]{"m⁻¹", "1/m"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMicroinch, new string[]{"µin⁻¹", "1/µin"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMil, new string[]{"mil⁻¹", "1/mil"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMile, new string[]{"mi⁻¹", "1/mi"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseMillimeter, new string[]{"mm⁻¹", "1/mm"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseUsSurveyFoot, new string[]{"ftUS⁻¹", "1/ftUS"}), + ("en-US", typeof(ReciprocalLengthUnit), (int)ReciprocalLengthUnit.InverseYard, new string[]{"yd⁻¹", "1/yd"}), ("en-US", typeof(RelativeHumidityUnit), (int)RelativeHumidityUnit.Percent, new string[]{"%RH"}), ("en-US", typeof(RotationalAccelerationUnit), (int)RotationalAccelerationUnit.DegreePerSecondSquared, new string[]{"°/s²", "deg/s²"}), ("en-US", typeof(RotationalAccelerationUnit), (int)RotationalAccelerationUnit.RadianPerSecondSquared, new string[]{"rad/s²"}), diff --git a/UnitsNet/GeneratedCode/UnitConverter.g.cs b/UnitsNet/GeneratedCode/UnitConverter.g.cs index 50992a2ee7..50c99c36ee 100644 --- a/UnitsNet/GeneratedCode/UnitConverter.g.cs +++ b/UnitsNet/GeneratedCode/UnitConverter.g.cs @@ -1783,6 +1783,25 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(ReactivePower.BaseUnit, ReactivePowerUnit.MegavoltampereReactive, q => q.ToUnit(ReactivePowerUnit.MegavoltampereReactive)); unitConverter.SetConversionFunction(ReactivePowerUnit.MegavoltampereReactive, ReactivePower.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(ReactivePower.BaseUnit, ReactivePower.BaseUnit, q => q); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseCentimeter, q => q.ToUnit(ReciprocalLengthUnit.InverseCentimeter)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseCentimeter, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseFoot, q => q.ToUnit(ReciprocalLengthUnit.InverseFoot)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseFoot, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseInch, q => q.ToUnit(ReciprocalLengthUnit.InverseInch)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseInch, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLength.BaseUnit, q => q); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseMicroinch, q => q.ToUnit(ReciprocalLengthUnit.InverseMicroinch)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseMicroinch, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseMil, q => q.ToUnit(ReciprocalLengthUnit.InverseMil)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseMil, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseMile, q => q.ToUnit(ReciprocalLengthUnit.InverseMile)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseMile, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseMillimeter, q => q.ToUnit(ReciprocalLengthUnit.InverseMillimeter)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseMillimeter, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseUsSurveyFoot, q => q.ToUnit(ReciprocalLengthUnit.InverseUsSurveyFoot)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseUsSurveyFoot, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ReciprocalLength.BaseUnit, ReciprocalLengthUnit.InverseYard, q => q.ToUnit(ReciprocalLengthUnit.InverseYard)); + unitConverter.SetConversionFunction(ReciprocalLengthUnit.InverseYard, ReciprocalLength.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(RelativeHumidity.BaseUnit, RelativeHumidity.BaseUnit, q => q); unitConverter.SetConversionFunction(RotationalAcceleration.BaseUnit, RotationalAccelerationUnit.DegreePerSecondSquared, q => q.ToUnit(RotationalAccelerationUnit.DegreePerSecondSquared)); unitConverter.SetConversionFunction(RotationalAccelerationUnit.DegreePerSecondSquared, RotationalAcceleration.BaseUnit, q => q.ToBaseUnit()); diff --git a/UnitsNet/GeneratedCode/Units/ReciprocalLengthUnit.g.cs b/UnitsNet/GeneratedCode/Units/ReciprocalLengthUnit.g.cs new file mode 100644 index 0000000000..166f08af87 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ReciprocalLengthUnit.g.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// 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. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum ReciprocalLengthUnit + { + Undefined = 0, + InverseCentimeter, + InverseFoot, + InverseInch, + InverseMeter, + InverseMicroinch, + InverseMil, + InverseMile, + InverseMillimeter, + InverseUsSurveyFoot, + InverseYard, + } + + #pragma warning restore 1591 +} From ba9381b9375feb1562b185697b0ed3026e72d2d3 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 14:27:59 -0400 Subject: [PATCH 03/15] Implement inverse method for ReciprocalLength quantity. --- .../CustomCode/ReciprocalLengthTests.cs | 14 ++++++++++++ .../Quantities/ReciprocalLength.extra.cs | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 53642ef85c..0e6f2f2a75 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -39,5 +39,19 @@ public class ReciprocalLengthTests : ReciprocalLengthTestsBase protected override double InverseInchInOneInverseMeter => 1 / 39.37007874; protected override double InverseMilInOneInverseMeter => 1 / 39370.07874015; protected override double InverseMicroinchInOneInverseMeter => 1 / 39370078.74015748; + + [Theory] + [InlineData(-1.0, -1.0)] + [InlineData(-2.0, -0.5)] + [InlineData(0.0, 0.0)] + [InlineData(1.0, 1.0)] + [InlineData(2.0, 0.5)] + public static void InverseTest(double value, double expected) + { + var inverseLength = new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); + var length = inverseLength.Inverse(); + + AssertEx.Equals(expected, length.Meters); + } } } diff --git a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs new file mode 100644 index 0000000000..809f9402d3 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs @@ -0,0 +1,22 @@ +// 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. + +using UnitsNet.Units; + +namespace UnitsNet +{ + public partial struct ReciprocalLength + { + /// + /// Calculates the inverse or of this unit. + /// + /// The inverse or of this unit. + public Length Inverse() + { + if (InverseMeter == 0.0) + return new Length(0.0, LengthUnit.Meter); + + return new Length(1 / InverseMeter, LengthUnit.Meter); + } + } +} From 183b80c2c4e1d9fcd348010f72d3b5d3015a70f3 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 14:52:05 -0400 Subject: [PATCH 04/15] Add convenience operator overloads for ForcePerLength quantity to interact with ReciprocalLength quantity. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 14 ++++++++++++++ .../CustomCode/Quantities/ForcePerLength.extra.cs | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 0e6f2f2a75..3a6dce86be 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -53,5 +53,19 @@ public static void InverseTest(double value, double expected) AssertEx.Equals(expected, length.Meters); } + + [Fact] + public static void ForcePerLengthTimesReciprocalLengthEqualsPressure() + { + Pressure pressure = ForcePerLength.FromNewtonsPerMeter(10) * ReciprocalLength.FromInverseMeter(5); + Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50)); + } + + [Fact] + public static void ForcePerLengthDividedByReciprocalLengthEqualsForce() + { + Force force = ForcePerLength.FromNewtonsPerMeter(10) / ReciprocalLength.FromInverseMeter(5); + Assert.Equal(force, Force.FromNewtons(2)); + } } } diff --git a/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs b/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs index 7cb334b147..5b9db46d56 100644 --- a/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs +++ b/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs @@ -28,5 +28,17 @@ public partial struct ForcePerLength { return Torque.FromNewtonMeters(forcePerLength.NewtonsPerMeter * area.SquareMeters); } + + /// Get from multiplied by . + public static Pressure operator *(ForcePerLength forcePerLength, ReciprocalLength reciprocalLength) + { + return Pressure.FromNewtonsPerSquareMeter(forcePerLength.NewtonsPerMeter * reciprocalLength.InverseMeter); + } + + /// Get from divided by . + public static Force operator /(ForcePerLength forcePerLength, ReciprocalLength reciprocalLength) + { + return Force.FromNewtons(forcePerLength.NewtonsPerMeter / reciprocalLength.InverseMeter); + } } } From 5cda1220d04c12dee5054e986b4c4c764bf137b1 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 15:11:04 -0400 Subject: [PATCH 05/15] Add convenience operator overloads for Force quantity to interact with ReciprocalLength quantity. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 7 +++++++ UnitsNet/CustomCode/Quantities/Force.extra.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 3a6dce86be..37fcd1ab65 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -67,5 +67,12 @@ public static void ForcePerLengthDividedByReciprocalLengthEqualsForce() Force force = ForcePerLength.FromNewtonsPerMeter(10) / ReciprocalLength.FromInverseMeter(5); Assert.Equal(force, Force.FromNewtons(2)); } + + [Fact] + public static void ForceTimesReciprocalLengthEqualsForcePerLength() + { + ForcePerLength forcePerLength = Force.FromNewtons(10) * ReciprocalLength.FromInverseMeter(5); + Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(50)); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Force.extra.cs b/UnitsNet/CustomCode/Quantities/Force.extra.cs index 1d9881edff..faa85b9523 100644 --- a/UnitsNet/CustomCode/Quantities/Force.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Force.extra.cs @@ -32,6 +32,12 @@ public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration) return Power.FromWatts(force.Newtons * speed.MetersPerSecond); } + /// Get from times . + public static ForcePerLength operator *(Force force, ReciprocalLength reciprocalLength) + { + return ForcePerLength.FromNewtonsPerMeter(force.Newtons * reciprocalLength.InverseMeter); + } + /// Get from divided by . public static Acceleration operator /(Force force, Mass mass) { From dde3e908caebbbdeff183ad916062d5ae853a550 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 15:22:48 -0400 Subject: [PATCH 06/15] Add convenience operator overloads for Pressure quantity to interact with ReciprocalLength quantity. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 7 +++++++ UnitsNet/CustomCode/Quantities/Pressure.extra.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 37fcd1ab65..9546a1002e 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -74,5 +74,12 @@ public static void ForceTimesReciprocalLengthEqualsForcePerLength() ForcePerLength forcePerLength = Force.FromNewtons(10) * ReciprocalLength.FromInverseMeter(5); Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(50)); } + + [Fact] + public static void PressureDividedByReciprocalLengthEqualsForcePerLength() + { + ForcePerLength forcePerLength = Pressure.FromPascals(50) / ReciprocalLength.FromInverseMeter(5); + Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(10)); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Pressure.extra.cs b/UnitsNet/CustomCode/Quantities/Pressure.extra.cs index ecaf977ed6..e938c4f84c 100644 --- a/UnitsNet/CustomCode/Quantities/Pressure.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Pressure.extra.cs @@ -28,5 +28,11 @@ public partial struct Pressure { return new SpecificWeight(pressure.Pascals / length.Meters, UnitsNet.Units.SpecificWeightUnit.NewtonPerCubicMeter); } + + /// Get from divided by . + public static ForcePerLength operator /(Pressure pressure, ReciprocalLength reciprocalLength) + { + return new ForcePerLength(pressure.Pascals / reciprocalLength.InverseMeter, UnitsNet.Units.ForcePerLengthUnit.NewtonPerMeter); + } } } From f8a5401fe24646ce886e9729783dd6c461f721f6 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 15:42:20 -0400 Subject: [PATCH 07/15] Implement Inverse method for Length quantity to get ReciprocalLength quantity. --- UnitsNet.Tests/CustomCode/LevelTests.cs | 14 ++++++++++++++ UnitsNet/CustomCode/Quantities/Length.extra.cs | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/LevelTests.cs b/UnitsNet.Tests/CustomCode/LevelTests.cs index a3af30a00e..ec575ec765 100644 --- a/UnitsNet.Tests/CustomCode/LevelTests.cs +++ b/UnitsNet.Tests/CustomCode/LevelTests.cs @@ -42,5 +42,19 @@ public void InvalidReference_ExpectArgumentOutOfRangeException(double quantity, // reference can't be zero or less than zero if quantity is postive. Assert.Throws(() => new Level(quantity, reference)); } + + [Theory] + [InlineData(-1.0, -1.0)] + [InlineData(-2.0, -0.5)] + [InlineData(0.0, 0.0)] + [InlineData(1.0, 1.0)] + [InlineData(2.0, 0.5)] + public static void InverseTest(double value, double expected) + { + var length = new Length(value, Units.LengthUnit.Meter); + var inverseLength = length.Inverse(); + + AssertEx.Equals(expected, inverseLength.InverseMeter); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Length.extra.cs b/UnitsNet/CustomCode/Quantities/Length.extra.cs index c69d65fabf..1d7c8922c0 100644 --- a/UnitsNet/CustomCode/Quantities/Length.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Length.extra.cs @@ -14,6 +14,18 @@ public partial struct Length { private const double InchesInOneFoot = 12; + /// + /// Calculates the inverse of this unit. + /// + /// The inverse of this unit as . + public ReciprocalLength Inverse() + { + if (Meters == 0.0) + return new ReciprocalLength(0.0, ReciprocalLengthUnit.InverseMeter); + + return new ReciprocalLength(1 / Meters, ReciprocalLengthUnit.InverseMeter); + } + /// /// Converts the length to a customary feet/inches combination. /// From 15490a1cd20a49129e23425f1a9d7af6bd34fbd4 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Fri, 16 Jul 2021 18:30:16 -0400 Subject: [PATCH 08/15] Add commutative implementations of recently implemented arithmetic operator overloads for Force and ForcePerLength quantities to interact with ReciprocalLength quantity. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 14 ++++++++++++++ .../Quantities/ReciprocalLength.extra.cs | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 9546a1002e..befe56a8a5 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -81,5 +81,19 @@ public static void PressureDividedByReciprocalLengthEqualsForcePerLength() ForcePerLength forcePerLength = Pressure.FromPascals(50) / ReciprocalLength.FromInverseMeter(5); Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(10)); } + + [Fact] + public static void ReciprocalLengthTimesForcePerLengthEqualsPressure() + { + Pressure pressure = ReciprocalLength.FromInverseMeter(5) *ForcePerLength.FromNewtonsPerMeter(10); + Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50)); + } + + [Fact] + public static void ReciprocalLengthTimesForceEqualsForcePerLength() + { + ForcePerLength forcePerLength = ReciprocalLength.FromInverseMeter(5) * Force.FromNewtons(10); + Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(50)); + } } } diff --git a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs index 809f9402d3..4833f17fbf 100644 --- a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs +++ b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs @@ -18,5 +18,17 @@ public Length Inverse() return new Length(1 / InverseMeter, LengthUnit.Meter); } + + /// Get from multiplied by . + public static Pressure operator *(ReciprocalLength reciprocalLength, ForcePerLength forcePerLength) + { + return Pressure.FromNewtonsPerSquareMeter(reciprocalLength.InverseMeter * forcePerLength.NewtonsPerMeter); + } + + /// Get from times . + public static ForcePerLength operator *(ReciprocalLength reciprocalLength, Force force) + { + return ForcePerLength.FromNewtonsPerMeter(reciprocalLength.InverseMeter * force.Newtons); + } } } From b0e53cf78799789c6ab963360402e6b88bf202dd Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 09:48:08 -0400 Subject: [PATCH 09/15] Fix plural naming for the units. --- Common/UnitDefinitions/ReciprocalLength.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Common/UnitDefinitions/ReciprocalLength.json b/Common/UnitDefinitions/ReciprocalLength.json index a31980b9f5..175cbfd729 100644 --- a/Common/UnitDefinitions/ReciprocalLength.json +++ b/Common/UnitDefinitions/ReciprocalLength.json @@ -9,7 +9,7 @@ "Units": [ { "SingularName": "InverseMeter", - "PluralName": "InverseMeter", + "PluralName": "InverseMeters", "FromUnitToBaseFunc": "x", "FromBaseToUnitFunc": "x", "Localization": [ @@ -21,7 +21,7 @@ }, { "SingularName": "InverseCentimeter", - "PluralName": "InverseCentimeter", + "PluralName": "InverseCentimeters", "FromUnitToBaseFunc": "x*1e2", "FromBaseToUnitFunc": "x/1e2", "Localization": [ @@ -33,7 +33,7 @@ }, { "SingularName": "InverseMillimeter", - "PluralName": "InverseMillimeter", + "PluralName": "InverseMillimeters", "FromUnitToBaseFunc": "x*1e3", "FromBaseToUnitFunc": "x/1e3", "Localization": [ @@ -45,7 +45,7 @@ }, { "SingularName": "InverseMile", - "PluralName": "InverseMile", + "PluralName": "InverseMiles", "FromUnitToBaseFunc": "x/1609.34", "FromBaseToUnitFunc": "x*1609.34", "Localization": [ @@ -57,7 +57,7 @@ }, { "SingularName": "InverseYard", - "PluralName": "InverseYard", + "PluralName": "InverseYards", "FromUnitToBaseFunc": "x/0.9144", "FromBaseToUnitFunc": "x*0.9144", "Localization": [ @@ -69,7 +69,7 @@ }, { "SingularName": "InverseFoot", - "PluralName": "InverseFoot", + "PluralName": "InverseFeet", "FromUnitToBaseFunc": "x/0.3048", "FromBaseToUnitFunc": "x*0.3048", "Localization": [ @@ -93,7 +93,7 @@ }, { "SingularName": "InverseInch", - "PluralName": "InverseInch", + "PluralName": "InverseInches", "FromUnitToBaseFunc": "x/2.54e-2", "FromBaseToUnitFunc": "x*2.54e-2", "Localization": [ @@ -105,7 +105,7 @@ }, { "SingularName": "InverseMil", - "PluralName": "InverseMil", + "PluralName": "InverseMils", "FromUnitToBaseFunc": "x/2.54e-5", "FromBaseToUnitFunc": "x*2.54e-5", "Localization": [ @@ -117,7 +117,7 @@ }, { "SingularName": "InverseMicroinch", - "PluralName": "InverseMicroinch", + "PluralName": "InverseMicroinches", "FromUnitToBaseFunc": "x/2.54e-8", "FromBaseToUnitFunc": "x*2.54e-8", "Localization": [ From f2b5ed900d388afb022418ee5b16656e97ef8238 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 09:57:10 -0400 Subject: [PATCH 10/15] Add generated code for updated plural names --- .../Quantities/ReciprocalLength.g.cs | 72 ++--- ...umberToReciprocalLengthExtensionsTest.g.cs | 36 +-- .../NumberToReciprocalLengthExtensions.g.cs | 54 ++-- .../TestsBase/ReciprocalLengthTestsBase.g.cs | 270 +++++++++--------- .../Quantities/ReciprocalLength.g.cs | 90 +++--- .../Quantities/ReciprocalLength.g.cs | 92 +++--- 6 files changed, 307 insertions(+), 307 deletions(-) diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs index ca9773d06b..273c2e6e9f 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -81,44 +81,44 @@ public ReciprocalLength(double value, ReciprocalLengthUnit unit) #region Conversion Properties /// - /// Get ReciprocalLength in InverseCentimeter. + /// Get ReciprocalLength in InverseCentimeters. /// - public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + public double InverseCentimeters => As(ReciprocalLengthUnit.InverseCentimeter); /// - /// Get ReciprocalLength in InverseFoot. + /// Get ReciprocalLength in InverseFeet. /// - public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + public double InverseFeet => As(ReciprocalLengthUnit.InverseFoot); /// - /// Get ReciprocalLength in InverseInch. + /// Get ReciprocalLength in InverseInches. /// - public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + public double InverseInches => As(ReciprocalLengthUnit.InverseInch); /// - /// Get ReciprocalLength in InverseMeter. + /// Get ReciprocalLength in InverseMeters. /// - public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + public double InverseMeters => As(ReciprocalLengthUnit.InverseMeter); /// - /// Get ReciprocalLength in InverseMicroinch. + /// Get ReciprocalLength in InverseMicroinches. /// - public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + public double InverseMicroinches => As(ReciprocalLengthUnit.InverseMicroinch); /// - /// Get ReciprocalLength in InverseMil. + /// Get ReciprocalLength in InverseMils. /// - public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + public double InverseMils => As(ReciprocalLengthUnit.InverseMil); /// - /// Get ReciprocalLength in InverseMile. + /// Get ReciprocalLength in InverseMiles. /// - public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + public double InverseMiles => As(ReciprocalLengthUnit.InverseMile); /// - /// Get ReciprocalLength in InverseMillimeter. + /// Get ReciprocalLength in InverseMillimeters. /// - public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + public double InverseMillimeters => As(ReciprocalLengthUnit.InverseMillimeter); /// /// Get ReciprocalLength in InverseUsSurveyFeet. @@ -126,61 +126,61 @@ public ReciprocalLength(double value, ReciprocalLengthUnit unit) public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); /// - /// Get ReciprocalLength in InverseYard. + /// Get ReciprocalLength in InverseYards. /// - public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + public double InverseYards => As(ReciprocalLengthUnit.InverseYard); #endregion #region Static Factory Methods /// - /// Get ReciprocalLength from InverseCentimeter. + /// Get ReciprocalLength from InverseCentimeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseCentimeter(double inversecentimeter) => new ReciprocalLength(inversecentimeter, ReciprocalLengthUnit.InverseCentimeter); + public static ReciprocalLength FromInverseCentimeters(double inversecentimeters) => new ReciprocalLength(inversecentimeters, ReciprocalLengthUnit.InverseCentimeter); /// - /// Get ReciprocalLength from InverseFoot. + /// Get ReciprocalLength from InverseFeet. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseFoot(double inversefoot) => new ReciprocalLength(inversefoot, ReciprocalLengthUnit.InverseFoot); + public static ReciprocalLength FromInverseFeet(double inversefeet) => new ReciprocalLength(inversefeet, ReciprocalLengthUnit.InverseFoot); /// - /// Get ReciprocalLength from InverseInch. + /// Get ReciprocalLength from InverseInches. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseInch(double inverseinch) => new ReciprocalLength(inverseinch, ReciprocalLengthUnit.InverseInch); + public static ReciprocalLength FromInverseInches(double inverseinches) => new ReciprocalLength(inverseinches, ReciprocalLengthUnit.InverseInch); /// - /// Get ReciprocalLength from InverseMeter. + /// Get ReciprocalLength from InverseMeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMeter(double inversemeter) => new ReciprocalLength(inversemeter, ReciprocalLengthUnit.InverseMeter); + public static ReciprocalLength FromInverseMeters(double inversemeters) => new ReciprocalLength(inversemeters, ReciprocalLengthUnit.InverseMeter); /// - /// Get ReciprocalLength from InverseMicroinch. + /// Get ReciprocalLength from InverseMicroinches. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMicroinch(double inversemicroinch) => new ReciprocalLength(inversemicroinch, ReciprocalLengthUnit.InverseMicroinch); + public static ReciprocalLength FromInverseMicroinches(double inversemicroinches) => new ReciprocalLength(inversemicroinches, ReciprocalLengthUnit.InverseMicroinch); /// - /// Get ReciprocalLength from InverseMil. + /// Get ReciprocalLength from InverseMils. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMil(double inversemil) => new ReciprocalLength(inversemil, ReciprocalLengthUnit.InverseMil); + public static ReciprocalLength FromInverseMils(double inversemils) => new ReciprocalLength(inversemils, ReciprocalLengthUnit.InverseMil); /// - /// Get ReciprocalLength from InverseMile. + /// Get ReciprocalLength from InverseMiles. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMile(double inversemile) => new ReciprocalLength(inversemile, ReciprocalLengthUnit.InverseMile); + public static ReciprocalLength FromInverseMiles(double inversemiles) => new ReciprocalLength(inversemiles, ReciprocalLengthUnit.InverseMile); /// - /// Get ReciprocalLength from InverseMillimeter. + /// Get ReciprocalLength from InverseMillimeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMillimeter(double inversemillimeter) => new ReciprocalLength(inversemillimeter, ReciprocalLengthUnit.InverseMillimeter); + public static ReciprocalLength FromInverseMillimeters(double inversemillimeters) => new ReciprocalLength(inversemillimeters, ReciprocalLengthUnit.InverseMillimeter); /// /// Get ReciprocalLength from InverseUsSurveyFeet. @@ -189,10 +189,10 @@ public ReciprocalLength(double value, ReciprocalLengthUnit unit) public static ReciprocalLength FromInverseUsSurveyFeet(double inverseussurveyfeet) => new ReciprocalLength(inverseussurveyfeet, ReciprocalLengthUnit.InverseUsSurveyFoot); /// - /// Get ReciprocalLength from InverseYard. + /// Get ReciprocalLength from InverseYards. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseYard(double inverseyard) => new ReciprocalLength(inverseyard, ReciprocalLengthUnit.InverseYard); + public static ReciprocalLength FromInverseYards(double inverseyards) => new ReciprocalLength(inverseyards, ReciprocalLengthUnit.InverseYard); /// diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs index 3cd1fd9f91..6136b0a71d 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReciprocalLengthExtensionsTest.g.cs @@ -25,44 +25,44 @@ namespace UnitsNet.Tests public class NumberToReciprocalLengthExtensionsTests { [Fact] - public void NumberToInverseCentimeterTest() => - Assert.Equal(ReciprocalLength.FromInverseCentimeter(2), 2.InverseCentimeter()); + public void NumberToInverseCentimetersTest() => + Assert.Equal(ReciprocalLength.FromInverseCentimeters(2), 2.InverseCentimeters()); [Fact] - public void NumberToInverseFootTest() => - Assert.Equal(ReciprocalLength.FromInverseFoot(2), 2.InverseFoot()); + public void NumberToInverseFeetTest() => + Assert.Equal(ReciprocalLength.FromInverseFeet(2), 2.InverseFeet()); [Fact] - public void NumberToInverseInchTest() => - Assert.Equal(ReciprocalLength.FromInverseInch(2), 2.InverseInch()); + public void NumberToInverseInchesTest() => + Assert.Equal(ReciprocalLength.FromInverseInches(2), 2.InverseInches()); [Fact] - public void NumberToInverseMeterTest() => - Assert.Equal(ReciprocalLength.FromInverseMeter(2), 2.InverseMeter()); + public void NumberToInverseMetersTest() => + Assert.Equal(ReciprocalLength.FromInverseMeters(2), 2.InverseMeters()); [Fact] - public void NumberToInverseMicroinchTest() => - Assert.Equal(ReciprocalLength.FromInverseMicroinch(2), 2.InverseMicroinch()); + public void NumberToInverseMicroinchesTest() => + Assert.Equal(ReciprocalLength.FromInverseMicroinches(2), 2.InverseMicroinches()); [Fact] - public void NumberToInverseMilTest() => - Assert.Equal(ReciprocalLength.FromInverseMil(2), 2.InverseMil()); + public void NumberToInverseMilsTest() => + Assert.Equal(ReciprocalLength.FromInverseMils(2), 2.InverseMils()); [Fact] - public void NumberToInverseMileTest() => - Assert.Equal(ReciprocalLength.FromInverseMile(2), 2.InverseMile()); + public void NumberToInverseMilesTest() => + Assert.Equal(ReciprocalLength.FromInverseMiles(2), 2.InverseMiles()); [Fact] - public void NumberToInverseMillimeterTest() => - Assert.Equal(ReciprocalLength.FromInverseMillimeter(2), 2.InverseMillimeter()); + public void NumberToInverseMillimetersTest() => + Assert.Equal(ReciprocalLength.FromInverseMillimeters(2), 2.InverseMillimeters()); [Fact] public void NumberToInverseUsSurveyFeetTest() => Assert.Equal(ReciprocalLength.FromInverseUsSurveyFeet(2), 2.InverseUsSurveyFeet()); [Fact] - public void NumberToInverseYardTest() => - Assert.Equal(ReciprocalLength.FromInverseYard(2), 2.InverseYard()); + public void NumberToInverseYardsTest() => + Assert.Equal(ReciprocalLength.FromInverseYards(2), 2.InverseYards()); } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs index 59b7571ccc..309a5ce336 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReciprocalLengthExtensions.g.cs @@ -28,45 +28,45 @@ namespace UnitsNet.NumberExtensions.NumberToReciprocalLength /// public static class NumberToReciprocalLengthExtensions { - /// - public static ReciprocalLength InverseCentimeter(this T value) => - ReciprocalLength.FromInverseCentimeter(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseCentimeters(this T value) => + ReciprocalLength.FromInverseCentimeters(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseFoot(this T value) => - ReciprocalLength.FromInverseFoot(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseFeet(this T value) => + ReciprocalLength.FromInverseFeet(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseInch(this T value) => - ReciprocalLength.FromInverseInch(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseInches(this T value) => + ReciprocalLength.FromInverseInches(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseMeter(this T value) => - ReciprocalLength.FromInverseMeter(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseMeters(this T value) => + ReciprocalLength.FromInverseMeters(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseMicroinch(this T value) => - ReciprocalLength.FromInverseMicroinch(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseMicroinches(this T value) => + ReciprocalLength.FromInverseMicroinches(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseMil(this T value) => - ReciprocalLength.FromInverseMil(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseMils(this T value) => + ReciprocalLength.FromInverseMils(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseMile(this T value) => - ReciprocalLength.FromInverseMile(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseMiles(this T value) => + ReciprocalLength.FromInverseMiles(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseMillimeter(this T value) => - ReciprocalLength.FromInverseMillimeter(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseMillimeters(this T value) => + ReciprocalLength.FromInverseMillimeters(Convert.ToDouble(value)); /// public static ReciprocalLength InverseUsSurveyFeet(this T value) => ReciprocalLength.FromInverseUsSurveyFeet(Convert.ToDouble(value)); - /// - public static ReciprocalLength InverseYard(this T value) => - ReciprocalLength.FromInverseYard(Convert.ToDouble(value)); + /// + public static ReciprocalLength InverseYards(this T value) => + ReciprocalLength.FromInverseYards(Convert.ToDouble(value)); } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 20587cd0bb..682963c9ff 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -37,28 +37,28 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class ReciprocalLengthTestsBase : QuantityTestsBase { - protected abstract double InverseCentimeterInOneInverseMeter { get; } - protected abstract double InverseFootInOneInverseMeter { get; } - protected abstract double InverseInchInOneInverseMeter { get; } - protected abstract double InverseMeterInOneInverseMeter { get; } - protected abstract double InverseMicroinchInOneInverseMeter { get; } - protected abstract double InverseMilInOneInverseMeter { get; } - protected abstract double InverseMileInOneInverseMeter { get; } - protected abstract double InverseMillimeterInOneInverseMeter { get; } + protected abstract double InverseCentimetersInOneInverseMeter { get; } + protected abstract double InverseFeetInOneInverseMeter { get; } + protected abstract double InverseInchesInOneInverseMeter { get; } + protected abstract double InverseMetersInOneInverseMeter { get; } + protected abstract double InverseMicroinchesInOneInverseMeter { get; } + protected abstract double InverseMilsInOneInverseMeter { get; } + protected abstract double InverseMilesInOneInverseMeter { get; } + protected abstract double InverseMillimetersInOneInverseMeter { get; } protected abstract double InverseUsSurveyFeetInOneInverseMeter { get; } - protected abstract double InverseYardInOneInverseMeter { get; } + protected abstract double InverseYardsInOneInverseMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double InverseCentimeterTolerance { get { return 1e-5; } } - protected virtual double InverseFootTolerance { get { return 1e-5; } } - protected virtual double InverseInchTolerance { get { return 1e-5; } } - protected virtual double InverseMeterTolerance { get { return 1e-5; } } - protected virtual double InverseMicroinchTolerance { get { return 1e-5; } } - protected virtual double InverseMilTolerance { get { return 1e-5; } } - protected virtual double InverseMileTolerance { get { return 1e-5; } } - protected virtual double InverseMillimeterTolerance { get { return 1e-5; } } + protected virtual double InverseCentimetersTolerance { get { return 1e-5; } } + protected virtual double InverseFeetTolerance { get { return 1e-5; } } + protected virtual double InverseInchesTolerance { get { return 1e-5; } } + protected virtual double InverseMetersTolerance { get { return 1e-5; } } + protected virtual double InverseMicroinchesTolerance { get { return 1e-5; } } + protected virtual double InverseMilsTolerance { get { return 1e-5; } } + protected virtual double InverseMilesTolerance { get { return 1e-5; } } + protected virtual double InverseMillimetersTolerance { get { return 1e-5; } } protected virtual double InverseUsSurveyFeetTolerance { get { return 1e-5; } } - protected virtual double InverseYardTolerance { get { return 1e-5; } } + protected virtual double InverseYardsTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global [Fact] @@ -132,52 +132,52 @@ public void ReciprocalLength_QuantityInfo_ReturnsQuantityInfoDescribingQuantity( [Fact] public void InverseMeterToReciprocalLengthUnits() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); - AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, inversemeter.InverseCentimeter, InverseCentimeterTolerance); - AssertEx.EqualTolerance(InverseFootInOneInverseMeter, inversemeter.InverseFoot, InverseFootTolerance); - AssertEx.EqualTolerance(InverseInchInOneInverseMeter, inversemeter.InverseInch, InverseInchTolerance); - AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, inversemeter.InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, inversemeter.InverseMicroinch, InverseMicroinchTolerance); - AssertEx.EqualTolerance(InverseMilInOneInverseMeter, inversemeter.InverseMil, InverseMilTolerance); - AssertEx.EqualTolerance(InverseMileInOneInverseMeter, inversemeter.InverseMile, InverseMileTolerance); - AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, inversemeter.InverseMillimeter, InverseMillimeterTolerance); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); + AssertEx.EqualTolerance(InverseCentimetersInOneInverseMeter, inversemeter.InverseCentimeters, InverseCentimetersTolerance); + AssertEx.EqualTolerance(InverseFeetInOneInverseMeter, inversemeter.InverseFeet, InverseFeetTolerance); + AssertEx.EqualTolerance(InverseInchesInOneInverseMeter, inversemeter.InverseInches, InverseInchesTolerance); + AssertEx.EqualTolerance(InverseMetersInOneInverseMeter, inversemeter.InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(InverseMicroinchesInOneInverseMeter, inversemeter.InverseMicroinches, InverseMicroinchesTolerance); + AssertEx.EqualTolerance(InverseMilsInOneInverseMeter, inversemeter.InverseMils, InverseMilsTolerance); + AssertEx.EqualTolerance(InverseMilesInOneInverseMeter, inversemeter.InverseMiles, InverseMilesTolerance); + AssertEx.EqualTolerance(InverseMillimetersInOneInverseMeter, inversemeter.InverseMillimeters, InverseMillimetersTolerance); AssertEx.EqualTolerance(InverseUsSurveyFeetInOneInverseMeter, inversemeter.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); - AssertEx.EqualTolerance(InverseYardInOneInverseMeter, inversemeter.InverseYard, InverseYardTolerance); + AssertEx.EqualTolerance(InverseYardsInOneInverseMeter, inversemeter.InverseYards, InverseYardsTolerance); } [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { var quantity00 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseCentimeter); - AssertEx.EqualTolerance(1, quantity00.InverseCentimeter, InverseCentimeterTolerance); + AssertEx.EqualTolerance(1, quantity00.InverseCentimeters, InverseCentimetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, quantity00.Unit); var quantity01 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseFoot); - AssertEx.EqualTolerance(1, quantity01.InverseFoot, InverseFootTolerance); + AssertEx.EqualTolerance(1, quantity01.InverseFeet, InverseFeetTolerance); Assert.Equal(ReciprocalLengthUnit.InverseFoot, quantity01.Unit); var quantity02 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseInch); - AssertEx.EqualTolerance(1, quantity02.InverseInch, InverseInchTolerance); + AssertEx.EqualTolerance(1, quantity02.InverseInches, InverseInchesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseInch, quantity02.Unit); var quantity03 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMeter); - AssertEx.EqualTolerance(1, quantity03.InverseMeter, InverseMeterTolerance); + AssertEx.EqualTolerance(1, quantity03.InverseMeters, InverseMetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMeter, quantity03.Unit); var quantity04 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMicroinch); - AssertEx.EqualTolerance(1, quantity04.InverseMicroinch, InverseMicroinchTolerance); + AssertEx.EqualTolerance(1, quantity04.InverseMicroinches, InverseMicroinchesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, quantity04.Unit); var quantity05 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMil); - AssertEx.EqualTolerance(1, quantity05.InverseMil, InverseMilTolerance); + AssertEx.EqualTolerance(1, quantity05.InverseMils, InverseMilsTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMil, quantity05.Unit); var quantity06 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMile); - AssertEx.EqualTolerance(1, quantity06.InverseMile, InverseMileTolerance); + AssertEx.EqualTolerance(1, quantity06.InverseMiles, InverseMilesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMile, quantity06.Unit); var quantity07 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseMillimeter); - AssertEx.EqualTolerance(1, quantity07.InverseMillimeter, InverseMillimeterTolerance); + AssertEx.EqualTolerance(1, quantity07.InverseMillimeters, InverseMillimetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, quantity07.Unit); var quantity08 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseUsSurveyFoot); @@ -185,38 +185,38 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, quantity08.Unit); var quantity09 = ReciprocalLength.From(1, ReciprocalLengthUnit.InverseYard); - AssertEx.EqualTolerance(1, quantity09.InverseYard, InverseYardTolerance); + AssertEx.EqualTolerance(1, quantity09.InverseYards, InverseYardsTolerance); Assert.Equal(ReciprocalLengthUnit.InverseYard, quantity09.Unit); } [Fact] - public void FromInverseMeter_WithInfinityValue_ThrowsArgumentException() + public void FromInverseMeters_WithInfinityValue_ThrowsArgumentException() { - Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.PositiveInfinity)); - Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.NegativeInfinity)); + Assert.Throws(() => ReciprocalLength.FromInverseMeters(double.PositiveInfinity)); + Assert.Throws(() => ReciprocalLength.FromInverseMeters(double.NegativeInfinity)); } [Fact] - public void FromInverseMeter_WithNanValue_ThrowsArgumentException() + public void FromInverseMeters_WithNanValue_ThrowsArgumentException() { - Assert.Throws(() => ReciprocalLength.FromInverseMeter(double.NaN)); + Assert.Throws(() => ReciprocalLength.FromInverseMeters(double.NaN)); } [Fact] public void As() { - var inversemeter = ReciprocalLength.FromInverseMeter(1); - AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseCentimeter), InverseCentimeterTolerance); - AssertEx.EqualTolerance(InverseFootInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseFoot), InverseFootTolerance); - AssertEx.EqualTolerance(InverseInchInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseInch), InverseInchTolerance); - AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMeter), InverseMeterTolerance); - AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMicroinch), InverseMicroinchTolerance); - AssertEx.EqualTolerance(InverseMilInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMil), InverseMilTolerance); - AssertEx.EqualTolerance(InverseMileInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMile), InverseMileTolerance); - AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMillimeter), InverseMillimeterTolerance); + var inversemeter = ReciprocalLength.FromInverseMeters(1); + AssertEx.EqualTolerance(InverseCentimetersInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseCentimeter), InverseCentimetersTolerance); + AssertEx.EqualTolerance(InverseFeetInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseFoot), InverseFeetTolerance); + AssertEx.EqualTolerance(InverseInchesInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseInch), InverseInchesTolerance); + AssertEx.EqualTolerance(InverseMetersInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMeter), InverseMetersTolerance); + AssertEx.EqualTolerance(InverseMicroinchesInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMicroinch), InverseMicroinchesTolerance); + AssertEx.EqualTolerance(InverseMilsInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMil), InverseMilsTolerance); + AssertEx.EqualTolerance(InverseMilesInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMile), InverseMilesTolerance); + AssertEx.EqualTolerance(InverseMillimetersInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseMillimeter), InverseMillimetersTolerance); AssertEx.EqualTolerance(InverseUsSurveyFeetInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseUsSurveyFoot), InverseUsSurveyFeetTolerance); - AssertEx.EqualTolerance(InverseYardInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseYard), InverseYardTolerance); + AssertEx.EqualTolerance(InverseYardsInOneInverseMeter, inversemeter.As(ReciprocalLengthUnit.InverseYard), InverseYardsTolerance); } [Fact] @@ -239,38 +239,38 @@ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void ToUnit() { - var inversemeter = ReciprocalLength.FromInverseMeter(1); + var inversemeter = ReciprocalLength.FromInverseMeters(1); var inversecentimeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseCentimeter); - AssertEx.EqualTolerance(InverseCentimeterInOneInverseMeter, (double)inversecentimeterQuantity.Value, InverseCentimeterTolerance); + AssertEx.EqualTolerance(InverseCentimetersInOneInverseMeter, (double)inversecentimeterQuantity.Value, InverseCentimetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, inversecentimeterQuantity.Unit); var inversefootQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseFoot); - AssertEx.EqualTolerance(InverseFootInOneInverseMeter, (double)inversefootQuantity.Value, InverseFootTolerance); + AssertEx.EqualTolerance(InverseFeetInOneInverseMeter, (double)inversefootQuantity.Value, InverseFeetTolerance); Assert.Equal(ReciprocalLengthUnit.InverseFoot, inversefootQuantity.Unit); var inverseinchQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseInch); - AssertEx.EqualTolerance(InverseInchInOneInverseMeter, (double)inverseinchQuantity.Value, InverseInchTolerance); + AssertEx.EqualTolerance(InverseInchesInOneInverseMeter, (double)inverseinchQuantity.Value, InverseInchesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseInch, inverseinchQuantity.Unit); var inversemeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMeter); - AssertEx.EqualTolerance(InverseMeterInOneInverseMeter, (double)inversemeterQuantity.Value, InverseMeterTolerance); + AssertEx.EqualTolerance(InverseMetersInOneInverseMeter, (double)inversemeterQuantity.Value, InverseMetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMeter, inversemeterQuantity.Unit); var inversemicroinchQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMicroinch); - AssertEx.EqualTolerance(InverseMicroinchInOneInverseMeter, (double)inversemicroinchQuantity.Value, InverseMicroinchTolerance); + AssertEx.EqualTolerance(InverseMicroinchesInOneInverseMeter, (double)inversemicroinchQuantity.Value, InverseMicroinchesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, inversemicroinchQuantity.Unit); var inversemilQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMil); - AssertEx.EqualTolerance(InverseMilInOneInverseMeter, (double)inversemilQuantity.Value, InverseMilTolerance); + AssertEx.EqualTolerance(InverseMilsInOneInverseMeter, (double)inversemilQuantity.Value, InverseMilsTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMil, inversemilQuantity.Unit); var inversemileQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMile); - AssertEx.EqualTolerance(InverseMileInOneInverseMeter, (double)inversemileQuantity.Value, InverseMileTolerance); + AssertEx.EqualTolerance(InverseMilesInOneInverseMeter, (double)inversemileQuantity.Value, InverseMilesTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMile, inversemileQuantity.Unit); var inversemillimeterQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseMillimeter); - AssertEx.EqualTolerance(InverseMillimeterInOneInverseMeter, (double)inversemillimeterQuantity.Value, InverseMillimeterTolerance); + AssertEx.EqualTolerance(InverseMillimetersInOneInverseMeter, (double)inversemillimeterQuantity.Value, InverseMillimetersTolerance); Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, inversemillimeterQuantity.Unit); var inverseussurveyfootQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseUsSurveyFoot); @@ -278,67 +278,67 @@ public void ToUnit() Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, inverseussurveyfootQuantity.Unit); var inverseyardQuantity = inversemeter.ToUnit(ReciprocalLengthUnit.InverseYard); - AssertEx.EqualTolerance(InverseYardInOneInverseMeter, (double)inverseyardQuantity.Value, InverseYardTolerance); + AssertEx.EqualTolerance(InverseYardsInOneInverseMeter, (double)inverseyardQuantity.Value, InverseYardsTolerance); Assert.Equal(ReciprocalLengthUnit.InverseYard, inverseyardQuantity.Unit); } [Fact] public void ToBaseUnit_ReturnsQuantityWithBaseUnit() { - var quantityInBaseUnit = ReciprocalLength.FromInverseMeter(1).ToBaseUnit(); + var quantityInBaseUnit = ReciprocalLength.FromInverseMeters(1).ToBaseUnit(); Assert.Equal(ReciprocalLength.BaseUnit, quantityInBaseUnit.Unit); } [Fact] public void ConversionRoundTrip() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseCentimeter(inversemeter.InverseCentimeter).InverseMeter, InverseCentimeterTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseFoot(inversemeter.InverseFoot).InverseMeter, InverseFootTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseInch(inversemeter.InverseInch).InverseMeter, InverseInchTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMeter(inversemeter.InverseMeter).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMicroinch(inversemeter.InverseMicroinch).InverseMeter, InverseMicroinchTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMil(inversemeter.InverseMil).InverseMeter, InverseMilTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMile(inversemeter.InverseMile).InverseMeter, InverseMileTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMillimeter(inversemeter.InverseMillimeter).InverseMeter, InverseMillimeterTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseUsSurveyFeet(inversemeter.InverseUsSurveyFeet).InverseMeter, InverseUsSurveyFeetTolerance); - AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseYard(inversemeter.InverseYard).InverseMeter, InverseYardTolerance); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseCentimeters(inversemeter.InverseCentimeters).InverseMeters, InverseCentimetersTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseFeet(inversemeter.InverseFeet).InverseMeters, InverseFeetTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseInches(inversemeter.InverseInches).InverseMeters, InverseInchesTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMeters(inversemeter.InverseMeters).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMicroinches(inversemeter.InverseMicroinches).InverseMeters, InverseMicroinchesTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMils(inversemeter.InverseMils).InverseMeters, InverseMilsTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMiles(inversemeter.InverseMiles).InverseMeters, InverseMilesTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseMillimeters(inversemeter.InverseMillimeters).InverseMeters, InverseMillimetersTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseUsSurveyFeet(inversemeter.InverseUsSurveyFeet).InverseMeters, InverseUsSurveyFeetTolerance); + AssertEx.EqualTolerance(1, ReciprocalLength.FromInverseYards(inversemeter.InverseYards).InverseMeters, InverseYardsTolerance); } [Fact] public void ArithmeticOperators() { - ReciprocalLength v = ReciprocalLength.FromInverseMeter(1); - AssertEx.EqualTolerance(-1, -v.InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeter(3)-v).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeter(10)/5).InverseMeter, InverseMeterTolerance); - AssertEx.EqualTolerance(2, ReciprocalLength.FromInverseMeter(10)/ReciprocalLength.FromInverseMeter(5), InverseMeterTolerance); + ReciprocalLength v = ReciprocalLength.FromInverseMeters(1); + AssertEx.EqualTolerance(-1, -v.InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeters(3)-v).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(2, (v + v).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(10, (v*10).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(10, (10*v).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(2, (ReciprocalLength.FromInverseMeters(10)/5).InverseMeters, InverseMetersTolerance); + AssertEx.EqualTolerance(2, ReciprocalLength.FromInverseMeters(10)/ReciprocalLength.FromInverseMeters(5), InverseMetersTolerance); } [Fact] public void ComparisonOperators() { - ReciprocalLength oneInverseMeter = ReciprocalLength.FromInverseMeter(1); - ReciprocalLength twoInverseMeter = ReciprocalLength.FromInverseMeter(2); + ReciprocalLength oneInverseMeter = ReciprocalLength.FromInverseMeters(1); + ReciprocalLength twoInverseMeters = ReciprocalLength.FromInverseMeters(2); - Assert.True(oneInverseMeter < twoInverseMeter); - Assert.True(oneInverseMeter <= twoInverseMeter); - Assert.True(twoInverseMeter > oneInverseMeter); - Assert.True(twoInverseMeter >= oneInverseMeter); + Assert.True(oneInverseMeter < twoInverseMeters); + Assert.True(oneInverseMeter <= twoInverseMeters); + Assert.True(twoInverseMeters > oneInverseMeter); + Assert.True(twoInverseMeters >= oneInverseMeter); - Assert.False(oneInverseMeter > twoInverseMeter); - Assert.False(oneInverseMeter >= twoInverseMeter); - Assert.False(twoInverseMeter < oneInverseMeter); - Assert.False(twoInverseMeter <= oneInverseMeter); + Assert.False(oneInverseMeter > twoInverseMeters); + Assert.False(oneInverseMeter >= twoInverseMeters); + Assert.False(twoInverseMeters < oneInverseMeter); + Assert.False(twoInverseMeters <= oneInverseMeter); } [Fact] public void CompareToIsImplemented() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); Assert.Equal(0, inversemeter.CompareTo(inversemeter)); Assert.True(inversemeter.CompareTo(ReciprocalLength.Zero) > 0); Assert.True(ReciprocalLength.Zero.CompareTo(inversemeter) < 0); @@ -347,22 +347,22 @@ public void CompareToIsImplemented() [Fact] public void CompareToThrowsOnTypeMismatch() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); Assert.Throws(() => inversemeter.CompareTo(new object())); } [Fact] public void CompareToThrowsOnNull() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); Assert.Throws(() => inversemeter.CompareTo(null)); } [Fact] public void EqualityOperators() { - var a = ReciprocalLength.FromInverseMeter(1); - var b = ReciprocalLength.FromInverseMeter(2); + var a = ReciprocalLength.FromInverseMeters(1); + var b = ReciprocalLength.FromInverseMeters(2); #pragma warning disable CS8073 // ReSharper disable EqualExpressionComparison @@ -383,8 +383,8 @@ public void EqualityOperators() [Fact] public void Equals_SameType_IsImplemented() { - var a = ReciprocalLength.FromInverseMeter(1); - var b = ReciprocalLength.FromInverseMeter(2); + var a = ReciprocalLength.FromInverseMeters(1); + var b = ReciprocalLength.FromInverseMeters(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); @@ -393,8 +393,8 @@ public void Equals_SameType_IsImplemented() [Fact] public void Equals_QuantityAsObject_IsImplemented() { - object a = ReciprocalLength.FromInverseMeter(1); - object b = ReciprocalLength.FromInverseMeter(2); + object a = ReciprocalLength.FromInverseMeters(1); + object b = ReciprocalLength.FromInverseMeters(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); @@ -404,29 +404,29 @@ public void Equals_QuantityAsObject_IsImplemented() [Fact] public void Equals_RelativeTolerance_IsImplemented() { - var v = ReciprocalLength.FromInverseMeter(1); - Assert.True(v.Equals(ReciprocalLength.FromInverseMeter(1), InverseMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ReciprocalLength.Zero, InverseMeterTolerance, ComparisonType.Relative)); + var v = ReciprocalLength.FromInverseMeters(1); + Assert.True(v.Equals(ReciprocalLength.FromInverseMeters(1), InverseMetersTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ReciprocalLength.Zero, InverseMetersTolerance, ComparisonType.Relative)); } [Fact] public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() { - var v = ReciprocalLength.FromInverseMeter(1); - Assert.Throws(() => v.Equals(ReciprocalLength.FromInverseMeter(1), -1, ComparisonType.Relative)); + var v = ReciprocalLength.FromInverseMeters(1); + Assert.Throws(() => v.Equals(ReciprocalLength.FromInverseMeters(1), -1, ComparisonType.Relative)); } [Fact] public void EqualsReturnsFalseOnTypeMismatch() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); Assert.False(inversemeter.Equals(new object())); } [Fact] public void EqualsReturnsFalseOnNull() { - ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeter(1); + ReciprocalLength inversemeter = ReciprocalLength.FromInverseMeters(1); Assert.False(inversemeter.Equals(null)); } @@ -528,21 +528,21 @@ public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixFor [Fact] public void ToString_NullFormat_ThrowsArgumentNullException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => quantity.ToString(null, null, null)); } [Fact] public void ToString_NullArgs_ThrowsArgumentNullException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => quantity.ToString(null, "g", null)); } [Fact] public void ToString_NullProvider_EqualsCurrentUICulture() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); } @@ -550,154 +550,154 @@ public void ToString_NullProvider_EqualsCurrentUICulture() [Fact] public void Convert_ToBool_ThrowsInvalidCastException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => Convert.ToBoolean(quantity)); } [Fact] public void Convert_ToByte_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); } [Fact] public void Convert_ToChar_ThrowsInvalidCastException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => Convert.ToChar(quantity)); } [Fact] public void Convert_ToDateTime_ThrowsInvalidCastException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => Convert.ToDateTime(quantity)); } [Fact] public void Convert_ToDecimal_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); } [Fact] public void Convert_ToDouble_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); } [Fact] public void Convert_ToInt16_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); } [Fact] public void Convert_ToInt32_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); } [Fact] public void Convert_ToInt64_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); } [Fact] public void Convert_ToSByte_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); } [Fact] public void Convert_ToSingle_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); } [Fact] public void Convert_ToString_EqualsToString() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); } [Fact] public void Convert_ToUInt16_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); } [Fact] public void Convert_ToUInt32_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); } [Fact] public void Convert_ToUInt64_EqualsValueAsSameType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); } [Fact] public void Convert_ChangeType_SelfType_EqualsSelf() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ReciprocalLength))); } [Fact] public void Convert_ChangeType_UnitType_EqualsUnit() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ReciprocalLengthUnit))); } [Fact] public void Convert_ChangeType_QuantityType_EqualsQuantityType() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(QuantityType.ReciprocalLength, Convert.ChangeType(quantity, typeof(QuantityType))); } [Fact] public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(ReciprocalLength.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); } [Fact] public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(ReciprocalLength.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); } [Fact] public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } [Fact] public void GetHashCode_Equals() { - var quantity = ReciprocalLength.FromInverseMeter(1.0); + var quantity = ReciprocalLength.FromInverseMeters(1.0); Assert.Equal(new {ReciprocalLength.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); } @@ -706,8 +706,8 @@ public void GetHashCode_Equals() [InlineData(-1.0)] public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { - var quantity = ReciprocalLength.FromInverseMeter(value); - Assert.Equal(ReciprocalLength.FromInverseMeter(-value), -quantity); + var quantity = ReciprocalLength.FromInverseMeters(value); + Assert.Equal(ReciprocalLength.FromInverseMeters(-value), -quantity); } } } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs index 47f1670f66..8a0d4d8d1d 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -159,44 +159,44 @@ private ReciprocalLength(double value, ReciprocalLengthUnit unit) #region Conversion Properties /// - /// Get ReciprocalLength in InverseCentimeter. + /// Get ReciprocalLength in InverseCentimeters. /// - public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + public double InverseCentimeters => As(ReciprocalLengthUnit.InverseCentimeter); /// - /// Get ReciprocalLength in InverseFoot. + /// Get ReciprocalLength in InverseFeet. /// - public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + public double InverseFeet => As(ReciprocalLengthUnit.InverseFoot); /// - /// Get ReciprocalLength in InverseInch. + /// Get ReciprocalLength in InverseInches. /// - public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + public double InverseInches => As(ReciprocalLengthUnit.InverseInch); /// - /// Get ReciprocalLength in InverseMeter. + /// Get ReciprocalLength in InverseMeters. /// - public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + public double InverseMeters => As(ReciprocalLengthUnit.InverseMeter); /// - /// Get ReciprocalLength in InverseMicroinch. + /// Get ReciprocalLength in InverseMicroinches. /// - public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + public double InverseMicroinches => As(ReciprocalLengthUnit.InverseMicroinch); /// - /// Get ReciprocalLength in InverseMil. + /// Get ReciprocalLength in InverseMils. /// - public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + public double InverseMils => As(ReciprocalLengthUnit.InverseMil); /// - /// Get ReciprocalLength in InverseMile. + /// Get ReciprocalLength in InverseMiles. /// - public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + public double InverseMiles => As(ReciprocalLengthUnit.InverseMile); /// - /// Get ReciprocalLength in InverseMillimeter. + /// Get ReciprocalLength in InverseMillimeters. /// - public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + public double InverseMillimeters => As(ReciprocalLengthUnit.InverseMillimeter); /// /// Get ReciprocalLength in InverseUsSurveyFeet. @@ -204,9 +204,9 @@ private ReciprocalLength(double value, ReciprocalLengthUnit unit) public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); /// - /// Get ReciprocalLength in InverseYard. + /// Get ReciprocalLength in InverseYards. /// - public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + public double InverseYards => As(ReciprocalLengthUnit.InverseYard); #endregion @@ -239,83 +239,83 @@ public static string GetAbbreviation(ReciprocalLengthUnit unit, [CanBeNull] stri #region Static Factory Methods /// - /// Get ReciprocalLength from InverseCentimeter. + /// Get ReciprocalLength from InverseCentimeters. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseCentimeter(double inversecentimeter) + public static ReciprocalLength FromInverseCentimeters(double inversecentimeters) { - double value = (double) inversecentimeter; + double value = (double) inversecentimeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseCentimeter); } /// - /// Get ReciprocalLength from InverseFoot. + /// Get ReciprocalLength from InverseFeet. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseFoot(double inversefoot) + public static ReciprocalLength FromInverseFeet(double inversefeet) { - double value = (double) inversefoot; + double value = (double) inversefeet; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseFoot); } /// - /// Get ReciprocalLength from InverseInch. + /// Get ReciprocalLength from InverseInches. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseInch(double inverseinch) + public static ReciprocalLength FromInverseInches(double inverseinches) { - double value = (double) inverseinch; + double value = (double) inverseinches; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseInch); } /// - /// Get ReciprocalLength from InverseMeter. + /// Get ReciprocalLength from InverseMeters. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseMeter(double inversemeter) + public static ReciprocalLength FromInverseMeters(double inversemeters) { - double value = (double) inversemeter; + double value = (double) inversemeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); } /// - /// Get ReciprocalLength from InverseMicroinch. + /// Get ReciprocalLength from InverseMicroinches. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseMicroinch(double inversemicroinch) + public static ReciprocalLength FromInverseMicroinches(double inversemicroinches) { - double value = (double) inversemicroinch; + double value = (double) inversemicroinches; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMicroinch); } /// - /// Get ReciprocalLength from InverseMil. + /// Get ReciprocalLength from InverseMils. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseMil(double inversemil) + public static ReciprocalLength FromInverseMils(double inversemils) { - double value = (double) inversemil; + double value = (double) inversemils; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMil); } /// - /// Get ReciprocalLength from InverseMile. + /// Get ReciprocalLength from InverseMiles. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseMile(double inversemile) + public static ReciprocalLength FromInverseMiles(double inversemiles) { - double value = (double) inversemile; + double value = (double) inversemiles; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMile); } /// - /// Get ReciprocalLength from InverseMillimeter. + /// Get ReciprocalLength from InverseMillimeters. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseMillimeter(double inversemillimeter) + public static ReciprocalLength FromInverseMillimeters(double inversemillimeters) { - double value = (double) inversemillimeter; + double value = (double) inversemillimeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMillimeter); } /// @@ -329,13 +329,13 @@ public static ReciprocalLength FromInverseUsSurveyFeet(double inverseussurveyfee return new ReciprocalLength(value, ReciprocalLengthUnit.InverseUsSurveyFoot); } /// - /// Get ReciprocalLength from InverseYard. + /// Get ReciprocalLength from InverseYards. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static ReciprocalLength FromInverseYard(double inverseyard) + public static ReciprocalLength FromInverseYards(double inverseyards) { - double value = (double) inverseyard; + double value = (double) inverseyards; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseYard); } diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 7793378b29..124d5ce4a5 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -181,44 +181,44 @@ public ReciprocalLength(double value, UnitSystem unitSystem) #region Conversion Properties /// - /// Get ReciprocalLength in InverseCentimeter. + /// Get ReciprocalLength in InverseCentimeters. /// - public double InverseCentimeter => As(ReciprocalLengthUnit.InverseCentimeter); + public double InverseCentimeters => As(ReciprocalLengthUnit.InverseCentimeter); /// - /// Get ReciprocalLength in InverseFoot. + /// Get ReciprocalLength in InverseFeet. /// - public double InverseFoot => As(ReciprocalLengthUnit.InverseFoot); + public double InverseFeet => As(ReciprocalLengthUnit.InverseFoot); /// - /// Get ReciprocalLength in InverseInch. + /// Get ReciprocalLength in InverseInches. /// - public double InverseInch => As(ReciprocalLengthUnit.InverseInch); + public double InverseInches => As(ReciprocalLengthUnit.InverseInch); /// - /// Get ReciprocalLength in InverseMeter. + /// Get ReciprocalLength in InverseMeters. /// - public double InverseMeter => As(ReciprocalLengthUnit.InverseMeter); + public double InverseMeters => As(ReciprocalLengthUnit.InverseMeter); /// - /// Get ReciprocalLength in InverseMicroinch. + /// Get ReciprocalLength in InverseMicroinches. /// - public double InverseMicroinch => As(ReciprocalLengthUnit.InverseMicroinch); + public double InverseMicroinches => As(ReciprocalLengthUnit.InverseMicroinch); /// - /// Get ReciprocalLength in InverseMil. + /// Get ReciprocalLength in InverseMils. /// - public double InverseMil => As(ReciprocalLengthUnit.InverseMil); + public double InverseMils => As(ReciprocalLengthUnit.InverseMil); /// - /// Get ReciprocalLength in InverseMile. + /// Get ReciprocalLength in InverseMiles. /// - public double InverseMile => As(ReciprocalLengthUnit.InverseMile); + public double InverseMiles => As(ReciprocalLengthUnit.InverseMile); /// - /// Get ReciprocalLength in InverseMillimeter. + /// Get ReciprocalLength in InverseMillimeters. /// - public double InverseMillimeter => As(ReciprocalLengthUnit.InverseMillimeter); + public double InverseMillimeters => As(ReciprocalLengthUnit.InverseMillimeter); /// /// Get ReciprocalLength in InverseUsSurveyFeet. @@ -226,9 +226,9 @@ public ReciprocalLength(double value, UnitSystem unitSystem) public double InverseUsSurveyFeet => As(ReciprocalLengthUnit.InverseUsSurveyFoot); /// - /// Get ReciprocalLength in InverseYard. + /// Get ReciprocalLength in InverseYards. /// - public double InverseYard => As(ReciprocalLengthUnit.InverseYard); + public double InverseYards => As(ReciprocalLengthUnit.InverseYard); #endregion @@ -260,75 +260,75 @@ public static string GetAbbreviation(ReciprocalLengthUnit unit, IFormatProvider? #region Static Factory Methods /// - /// Get ReciprocalLength from InverseCentimeter. + /// Get ReciprocalLength from InverseCentimeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseCentimeter(QuantityValue inversecentimeter) + public static ReciprocalLength FromInverseCentimeters(QuantityValue inversecentimeters) { - double value = (double) inversecentimeter; + double value = (double) inversecentimeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseCentimeter); } /// - /// Get ReciprocalLength from InverseFoot. + /// Get ReciprocalLength from InverseFeet. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseFoot(QuantityValue inversefoot) + public static ReciprocalLength FromInverseFeet(QuantityValue inversefeet) { - double value = (double) inversefoot; + double value = (double) inversefeet; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseFoot); } /// - /// Get ReciprocalLength from InverseInch. + /// Get ReciprocalLength from InverseInches. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseInch(QuantityValue inverseinch) + public static ReciprocalLength FromInverseInches(QuantityValue inverseinches) { - double value = (double) inverseinch; + double value = (double) inverseinches; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseInch); } /// - /// Get ReciprocalLength from InverseMeter. + /// Get ReciprocalLength from InverseMeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMeter(QuantityValue inversemeter) + public static ReciprocalLength FromInverseMeters(QuantityValue inversemeters) { - double value = (double) inversemeter; + double value = (double) inversemeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); } /// - /// Get ReciprocalLength from InverseMicroinch. + /// Get ReciprocalLength from InverseMicroinches. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMicroinch(QuantityValue inversemicroinch) + public static ReciprocalLength FromInverseMicroinches(QuantityValue inversemicroinches) { - double value = (double) inversemicroinch; + double value = (double) inversemicroinches; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMicroinch); } /// - /// Get ReciprocalLength from InverseMil. + /// Get ReciprocalLength from InverseMils. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMil(QuantityValue inversemil) + public static ReciprocalLength FromInverseMils(QuantityValue inversemils) { - double value = (double) inversemil; + double value = (double) inversemils; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMil); } /// - /// Get ReciprocalLength from InverseMile. + /// Get ReciprocalLength from InverseMiles. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMile(QuantityValue inversemile) + public static ReciprocalLength FromInverseMiles(QuantityValue inversemiles) { - double value = (double) inversemile; + double value = (double) inversemiles; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMile); } /// - /// Get ReciprocalLength from InverseMillimeter. + /// Get ReciprocalLength from InverseMillimeters. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseMillimeter(QuantityValue inversemillimeter) + public static ReciprocalLength FromInverseMillimeters(QuantityValue inversemillimeters) { - double value = (double) inversemillimeter; + double value = (double) inversemillimeters; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseMillimeter); } /// @@ -341,12 +341,12 @@ public static ReciprocalLength FromInverseUsSurveyFeet(QuantityValue inverseussu return new ReciprocalLength(value, ReciprocalLengthUnit.InverseUsSurveyFoot); } /// - /// Get ReciprocalLength from InverseYard. + /// Get ReciprocalLength from InverseYards. /// /// If value is NaN or Infinity. - public static ReciprocalLength FromInverseYard(QuantityValue inverseyard) + public static ReciprocalLength FromInverseYards(QuantityValue inverseyards) { - double value = (double) inverseyard; + double value = (double) inverseyards; return new ReciprocalLength(value, ReciprocalLengthUnit.InverseYard); } @@ -548,7 +548,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip /// Get ratio value from dividing by . public static double operator /(ReciprocalLength left, ReciprocalLength right) { - return left.InverseMeter / right.InverseMeter; + return left.InverseMeters / right.InverseMeters; } #endregion From 9e9289a09b15a6accb760d044c4fb6ba33fe5bd7 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 10:14:22 -0400 Subject: [PATCH 11/15] Fix for updated plural names. --- UnitsNet.Tests/CustomCode/LevelTests.cs | 2 +- .../CustomCode/ReciprocalLengthTests.cs | 30 +++++++++---------- UnitsNet/CustomCode/Quantities/Force.extra.cs | 2 +- .../Quantities/ForcePerLength.extra.cs | 4 +-- .../CustomCode/Quantities/Pressure.extra.cs | 2 +- .../Quantities/ReciprocalLength.extra.cs | 8 ++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/LevelTests.cs b/UnitsNet.Tests/CustomCode/LevelTests.cs index ec575ec765..bf1752787b 100644 --- a/UnitsNet.Tests/CustomCode/LevelTests.cs +++ b/UnitsNet.Tests/CustomCode/LevelTests.cs @@ -54,7 +54,7 @@ public static void InverseTest(double value, double expected) var length = new Length(value, Units.LengthUnit.Meter); var inverseLength = length.Inverse(); - AssertEx.Equals(expected, inverseLength.InverseMeter); + AssertEx.Equals(expected, inverseLength.InverseMeters); } } } diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index befe56a8a5..bd8f267d5c 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -26,19 +26,19 @@ public class ReciprocalLengthTests : ReciprocalLengthTestsBase { protected override bool SupportsSIUnitSystem => false; - protected override double InverseMeterInOneInverseMeter => 1; - protected override double InverseCentimeterInOneInverseMeter => 1E-2; - protected override double InverseMillimeterInOneInverseMeter => 1E-3; + protected override double InverseMetersInOneInverseMeter => 1; + protected override double InverseCentimetersInOneInverseMeter => 1E-2; + protected override double InverseMillimetersInOneInverseMeter => 1E-3; - protected override double InverseMileInOneInverseMeter => 1 / 0.000621371; - protected override double InverseYardInOneInverseMeter => 1 / 1.09361; - protected override double InverseFootInOneInverseMeter => 1 / 3.28084; + protected override double InverseMilesInOneInverseMeter => 1 / 0.000621371; + protected override double InverseYardsInOneInverseMeter => 1 / 1.09361; + protected override double InverseFeetInOneInverseMeter => 1 / 3.28084; protected override double InverseUsSurveyFeetInOneInverseMeter => 1 / 3.280833333333333; - protected override double InverseInchInOneInverseMeter => 1 / 39.37007874; - protected override double InverseMilInOneInverseMeter => 1 / 39370.07874015; - protected override double InverseMicroinchInOneInverseMeter => 1 / 39370078.74015748; + protected override double InverseInchesInOneInverseMeter => 1 / 39.37007874; + protected override double InverseMilsInOneInverseMeter => 1 / 39370.07874015; + protected override double InverseMicroinchesInOneInverseMeter => 1 / 39370078.74015748; [Theory] [InlineData(-1.0, -1.0)] @@ -57,42 +57,42 @@ public static void InverseTest(double value, double expected) [Fact] public static void ForcePerLengthTimesReciprocalLengthEqualsPressure() { - Pressure pressure = ForcePerLength.FromNewtonsPerMeter(10) * ReciprocalLength.FromInverseMeter(5); + Pressure pressure = ForcePerLength.FromNewtonsPerMeter(10) * ReciprocalLength.FromInverseMeters(5); Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50)); } [Fact] public static void ForcePerLengthDividedByReciprocalLengthEqualsForce() { - Force force = ForcePerLength.FromNewtonsPerMeter(10) / ReciprocalLength.FromInverseMeter(5); + Force force = ForcePerLength.FromNewtonsPerMeter(10) / ReciprocalLength.FromInverseMeters(5); Assert.Equal(force, Force.FromNewtons(2)); } [Fact] public static void ForceTimesReciprocalLengthEqualsForcePerLength() { - ForcePerLength forcePerLength = Force.FromNewtons(10) * ReciprocalLength.FromInverseMeter(5); + ForcePerLength forcePerLength = Force.FromNewtons(10) * ReciprocalLength.FromInverseMeters(5); Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(50)); } [Fact] public static void PressureDividedByReciprocalLengthEqualsForcePerLength() { - ForcePerLength forcePerLength = Pressure.FromPascals(50) / ReciprocalLength.FromInverseMeter(5); + ForcePerLength forcePerLength = Pressure.FromPascals(50) / ReciprocalLength.FromInverseMeters(5); Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(10)); } [Fact] public static void ReciprocalLengthTimesForcePerLengthEqualsPressure() { - Pressure pressure = ReciprocalLength.FromInverseMeter(5) *ForcePerLength.FromNewtonsPerMeter(10); + Pressure pressure = ReciprocalLength.FromInverseMeters(5) *ForcePerLength.FromNewtonsPerMeter(10); Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50)); } [Fact] public static void ReciprocalLengthTimesForceEqualsForcePerLength() { - ForcePerLength forcePerLength = ReciprocalLength.FromInverseMeter(5) * Force.FromNewtons(10); + ForcePerLength forcePerLength = ReciprocalLength.FromInverseMeters(5) * Force.FromNewtons(10); Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(50)); } } diff --git a/UnitsNet/CustomCode/Quantities/Force.extra.cs b/UnitsNet/CustomCode/Quantities/Force.extra.cs index faa85b9523..4019b245df 100644 --- a/UnitsNet/CustomCode/Quantities/Force.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Force.extra.cs @@ -35,7 +35,7 @@ public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration) /// Get from times . public static ForcePerLength operator *(Force force, ReciprocalLength reciprocalLength) { - return ForcePerLength.FromNewtonsPerMeter(force.Newtons * reciprocalLength.InverseMeter); + return ForcePerLength.FromNewtonsPerMeter(force.Newtons * reciprocalLength.InverseMeters); } /// Get from divided by . diff --git a/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs b/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs index 5b9db46d56..5c37361248 100644 --- a/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs +++ b/UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs @@ -32,13 +32,13 @@ public partial struct ForcePerLength /// Get from multiplied by . public static Pressure operator *(ForcePerLength forcePerLength, ReciprocalLength reciprocalLength) { - return Pressure.FromNewtonsPerSquareMeter(forcePerLength.NewtonsPerMeter * reciprocalLength.InverseMeter); + return Pressure.FromNewtonsPerSquareMeter(forcePerLength.NewtonsPerMeter * reciprocalLength.InverseMeters); } /// Get from divided by . public static Force operator /(ForcePerLength forcePerLength, ReciprocalLength reciprocalLength) { - return Force.FromNewtons(forcePerLength.NewtonsPerMeter / reciprocalLength.InverseMeter); + return Force.FromNewtons(forcePerLength.NewtonsPerMeter / reciprocalLength.InverseMeters); } } } diff --git a/UnitsNet/CustomCode/Quantities/Pressure.extra.cs b/UnitsNet/CustomCode/Quantities/Pressure.extra.cs index e938c4f84c..75ccdcb3f1 100644 --- a/UnitsNet/CustomCode/Quantities/Pressure.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Pressure.extra.cs @@ -32,7 +32,7 @@ public partial struct Pressure /// Get from divided by . public static ForcePerLength operator /(Pressure pressure, ReciprocalLength reciprocalLength) { - return new ForcePerLength(pressure.Pascals / reciprocalLength.InverseMeter, UnitsNet.Units.ForcePerLengthUnit.NewtonPerMeter); + return new ForcePerLength(pressure.Pascals / reciprocalLength.InverseMeters, UnitsNet.Units.ForcePerLengthUnit.NewtonPerMeter); } } } diff --git a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs index 4833f17fbf..9c966719a4 100644 --- a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs +++ b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs @@ -13,22 +13,22 @@ public partial struct ReciprocalLength /// The inverse or of this unit. public Length Inverse() { - if (InverseMeter == 0.0) + if (InverseMeters == 0.0) return new Length(0.0, LengthUnit.Meter); - return new Length(1 / InverseMeter, LengthUnit.Meter); + return new Length(1 / InverseMeters, LengthUnit.Meter); } /// Get from multiplied by . public static Pressure operator *(ReciprocalLength reciprocalLength, ForcePerLength forcePerLength) { - return Pressure.FromNewtonsPerSquareMeter(reciprocalLength.InverseMeter * forcePerLength.NewtonsPerMeter); + return Pressure.FromNewtonsPerSquareMeter(reciprocalLength.InverseMeters * forcePerLength.NewtonsPerMeter); } /// Get from times . public static ForcePerLength operator *(ReciprocalLength reciprocalLength, Force force) { - return ForcePerLength.FromNewtonsPerMeter(reciprocalLength.InverseMeter * force.Newtons); + return ForcePerLength.FromNewtonsPerMeter(reciprocalLength.InverseMeters * force.Newtons); } } } From 2c7325d6c216c78f941f19e5eb2783802dab290f Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 10:21:37 -0400 Subject: [PATCH 12/15] Better naming for the inverse test of the ReciprocalLength. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index bd8f267d5c..31492327b1 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -46,7 +46,7 @@ public class ReciprocalLengthTests : ReciprocalLengthTestsBase [InlineData(0.0, 0.0)] [InlineData(1.0, 1.0)] [InlineData(2.0, 0.5)] - public static void InverseTest(double value, double expected) + public static void InverseReturnsLength(double value, double expected) { var inverseLength = new ReciprocalLength(value, ReciprocalLengthUnit.InverseMeter); var length = inverseLength.Inverse(); From 9627483a193dfb6211d90ce3bbb0d511759b7849 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 10:24:21 -0400 Subject: [PATCH 13/15] Move Length's inverse method to its own place with better naming. --- UnitsNet.Tests/CustomCode/LengthTests.cs | 14 ++++++++++++++ UnitsNet.Tests/CustomCode/LevelTests.cs | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index 0f8e85ac88..b665632d03 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -213,5 +213,19 @@ public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity() Assert.Equal(0.0508, inSI.Value); Assert.Equal(LengthUnit.Meter, inSI.Unit); } + + [Theory] + [InlineData(-1.0, -1.0)] + [InlineData(-2.0, -0.5)] + [InlineData(0.0, 0.0)] + [InlineData(1.0, 1.0)] + [InlineData(2.0, 0.5)] + public static void InverseReturnsReciprocalLength(double value, double expected) + { + var length = new Length(value, Units.LengthUnit.Meter); + var inverseLength = length.Inverse(); + + AssertEx.Equals(expected, inverseLength.InverseMeters); + } } } diff --git a/UnitsNet.Tests/CustomCode/LevelTests.cs b/UnitsNet.Tests/CustomCode/LevelTests.cs index bf1752787b..a3af30a00e 100644 --- a/UnitsNet.Tests/CustomCode/LevelTests.cs +++ b/UnitsNet.Tests/CustomCode/LevelTests.cs @@ -42,19 +42,5 @@ public void InvalidReference_ExpectArgumentOutOfRangeException(double quantity, // reference can't be zero or less than zero if quantity is postive. Assert.Throws(() => new Level(quantity, reference)); } - - [Theory] - [InlineData(-1.0, -1.0)] - [InlineData(-2.0, -0.5)] - [InlineData(0.0, 0.0)] - [InlineData(1.0, 1.0)] - [InlineData(2.0, 0.5)] - public static void InverseTest(double value, double expected) - { - var length = new Length(value, Units.LengthUnit.Meter); - var inverseLength = length.Inverse(); - - AssertEx.Equals(expected, inverseLength.InverseMeters); - } } } From 13be62e4d954533dbf17dc225409638e24e9891b Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 10:35:04 -0400 Subject: [PATCH 14/15] Better doc for the inverse method for ReciprocalLength. --- UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs index 9c966719a4..ce72f9b423 100644 --- a/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs +++ b/UnitsNet/CustomCode/Quantities/ReciprocalLength.extra.cs @@ -8,9 +8,9 @@ namespace UnitsNet public partial struct ReciprocalLength { /// - /// Calculates the inverse or of this unit. + /// Calculates the inverse of this quantity. /// - /// The inverse or of this unit. + /// The corresponding inverse quantity, . public Length Inverse() { if (InverseMeters == 0.0) From 182cf5af623d66fe8ddfd5b6320985546cdd3100 Mon Sep 17 00:00:00 2001 From: Burak Can Date: Mon, 19 Jul 2021 10:48:02 -0400 Subject: [PATCH 15/15] Use constant values rather than fractions. --- UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs index 31492327b1..03ac14b0a8 100644 --- a/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs @@ -30,15 +30,15 @@ public class ReciprocalLengthTests : ReciprocalLengthTestsBase protected override double InverseCentimetersInOneInverseMeter => 1E-2; protected override double InverseMillimetersInOneInverseMeter => 1E-3; - protected override double InverseMilesInOneInverseMeter => 1 / 0.000621371; - protected override double InverseYardsInOneInverseMeter => 1 / 1.09361; - protected override double InverseFeetInOneInverseMeter => 1 / 3.28084; + protected override double InverseMilesInOneInverseMeter => 1609.344; + protected override double InverseYardsInOneInverseMeter => 0.914402; + protected override double InverseFeetInOneInverseMeter => 0.3048; - protected override double InverseUsSurveyFeetInOneInverseMeter => 1 / 3.280833333333333; + protected override double InverseUsSurveyFeetInOneInverseMeter => 0.3048; - protected override double InverseInchesInOneInverseMeter => 1 / 39.37007874; - protected override double InverseMilsInOneInverseMeter => 1 / 39370.07874015; - protected override double InverseMicroinchesInOneInverseMeter => 1 / 39370078.74015748; + protected override double InverseInchesInOneInverseMeter => 2.54E-2; + protected override double InverseMilsInOneInverseMeter => 2.54E-5; + protected override double InverseMicroinchesInOneInverseMeter => 2.54E-8; [Theory] [InlineData(-1.0, -1.0)]