From abf4766ed640fbf5cb81dea2402cfa44aae51ef3 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Wed, 8 Feb 2023 18:46:20 -0500 Subject: [PATCH 1/8] Added support for molar flow units --- Common/UnitDefinitions/MolarFlow.json | 107 ++ Common/UnitDefinitions/MolarMass.json | 12 + Common/UnitDefinitions/Molarity.json | 18 +- Common/UnitEnumValues.g.json | 20 +- .../GeneratedCode/MolarFlow/MolarFlow.nfproj | 42 + .../UnitsNet.NanoFramework.MolarFlow.nuspec | 26 + .../GeneratedCode/MolarFlow/packages.config | 4 + .../GeneratedCode/Quantities/MolarFlow.g.cs | 224 ++++ .../GeneratedCode/Quantities/MolarMass.g.cs | 13 + .../GeneratedCode/Quantities/Molarity.g.cs | 26 + .../GeneratedCode/Units/MolarFlowUnit.g.cs | 37 + .../GeneratedCode/Units/MolarMassUnit.g.cs | 1 + .../GeneratedCode/Units/MolarityUnit.g.cs | 2 + .../GeneratedCode/UnitsNet.nanoFramework.sln | 8 + .../NumberToMolarFlowExtensionsTest.g.cs | 52 + .../NumberToMolarMassExtensionsTest.g.cs | 4 + .../NumberToMolarityExtensionsTest.g.cs | 8 + .../NumberToMolarFlowExtensions.g.cs | 56 + .../NumberToMolarMassExtensions.g.cs | 4 + .../NumberToMolarityExtensions.g.cs | 8 + UnitsNet.Tests/CustomCode/MolarFlowTests.cs | 65 ++ UnitsNet.Tests/CustomCode/MolarMassTests.cs | 2 +- UnitsNet.Tests/CustomCode/MolarityTests.cs | 2 + .../GeneratedCode/IQuantityTests.g.cs | 5 +- .../TestsBase/MolarFlowTestsBase.g.cs | 816 ++++++++++++++ .../TestsBase/MolarMassTestsBase.g.cs | 79 +- .../TestsBase/MolarityTestsBase.g.cs | 110 +- .../CustomCode/Quantities/MolarFlow.extra.cs | 26 + .../GeneratedCode/Quantities/MolarFlow.g.cs | 995 ++++++++++++++++++ .../GeneratedCode/Quantities/MolarMass.g.cs | 21 + .../GeneratedCode/Quantities/Molarity.g.cs | 42 + UnitsNet/GeneratedCode/Quantity.g.cs | 7 + .../GeneratedCode/Units/MolarFlowUnit.g.cs | 37 + .../GeneratedCode/Units/MolarMassUnit.g.cs | 1 + .../GeneratedCode/Units/MolarityUnit.g.cs | 2 + 35 files changed, 2838 insertions(+), 44 deletions(-) create mode 100644 Common/UnitDefinitions/MolarFlow.json create mode 100644 UnitsNet.NanoFramework/GeneratedCode/MolarFlow/MolarFlow.nfproj create mode 100644 UnitsNet.NanoFramework/GeneratedCode/MolarFlow/UnitsNet.NanoFramework.MolarFlow.nuspec create mode 100644 UnitsNet.NanoFramework/GeneratedCode/MolarFlow/packages.config create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/MolarFlowTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs create mode 100644 UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs diff --git a/Common/UnitDefinitions/MolarFlow.json b/Common/UnitDefinitions/MolarFlow.json new file mode 100644 index 0000000000..c56d2b2bf5 --- /dev/null +++ b/Common/UnitDefinitions/MolarFlow.json @@ -0,0 +1,107 @@ +{ + "Name": "MolarFlow", + "BaseUnit": "KilomolePerSecond", + "XmlDocSummary": "Molar flow is the ratio of the amount of substance change to the time during which the change occurred (value of amount of substance changes per unit time).", + "BaseDimensions": { + "N": 1, + "T": -1 + }, + "Units": [ + { + "SingularName": "KilomolePerSecond", + "PluralName": "KilomolesPerSecond", + "BaseUnits": { + "N": "Kilomole", + "T": "Second" + }, + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kmol/s" ] + } + ] + }, + { + "SingularName": "KilomolePerMinute", + "PluralName": "KilomolesPerMinute", + "BaseUnits": { + "N": "Kilomole", + "T": "Minute" + }, + "FromUnitToBaseFunc": "{x} / 5.999988e1", + "FromBaseToUnitFunc": "{x} * 5.999988e1", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kmol/min" ] + } + ] + }, + { + "SingularName": "KilomolePerHour", + "PluralName": "KilomolesPerHour", + "BaseUnits": { + "N": "Kilomole", + "T": "Hour" + }, + "FromUnitToBaseFunc": "{x} / 3.599997e3", + "FromBaseToUnitFunc": "{x} * 3.599997e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kmol/h" ] + } + ] + }, + { + "SingularName": "PoundMolePerSecond", + "PluralName": "PoundsMolePerSecond", + "BaseUnits": { + "N": "PoundMole", + "T": "Second" + }, + "FromUnitToBaseFunc": "{x} / 2.2046244201838", + "FromBaseToUnitFunc": "{x} * 2.2046244201838", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lbmol/s" ] + } + ] + }, + { + "SingularName": "PoundMolePerMinute", + "PluralName": "PoundsMolePerMinute", + "BaseUnits": { + "N": "PoundMole", + "T": "Minute" + }, + "FromUnitToBaseFunc": "{x} / 1.32277406886626e2", + "FromBaseToUnitFunc": "{x} * 1.32277406886626e2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lbmol/min" ] + } + ] + }, + { + "SingularName": "PoundMolePerHour", + "PluralName": "PoundsMolePerHour", + "BaseUnits": { + "N": "PoundMole", + "T": "Hour" + }, + "FromUnitToBaseFunc": "{x} / 7.93663391482404e3", + "FromBaseToUnitFunc": "{x} * 7.93663391482404e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lbmol/h" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/MolarMass.json b/Common/UnitDefinitions/MolarMass.json index 49c31aae60..36401297c6 100644 --- a/Common/UnitDefinitions/MolarMass.json +++ b/Common/UnitDefinitions/MolarMass.json @@ -24,6 +24,18 @@ } ] }, + { + "SingularName": "KilogramPerKilomole", + "PluralName": "KilogramsPerKilomole", + "FromUnitToBaseFunc": "{x} / 1e3", + "FromBaseToUnitFunc": "{x} * 1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kg/kmol" ] + } + ] + }, { "SingularName": "PoundPerMole", "PluralName": "PoundsPerMole", diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index a35ca9c2b6..806734424c 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -17,7 +17,7 @@ }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [], + "Prefixes": [ "Kilo" ], "Localization": [ { "Culture": "en-US", @@ -41,6 +41,22 @@ "Abbreviations": [ "mol/L", "M" ] } ] + }, + { + "SingularName": "PoundMolePerCubicFoot", + "PluralName": "PoundMolesPerCubicFoot", + "BaseUnits": { + "L": "Foot", + "N": "PoundMole" + }, + "FromUnitToBaseFunc": "{x} / 6.242796e-5", + "FromBaseToUnitFunc": "{x} * 6.242796e-5", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lbmol/ft³" ] + } + ] } ] } diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index d0a4cd5db3..071cda7cfa 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -956,7 +956,10 @@ "NanomolePerLiter": 14, "NanomolesPerLiter": 15, "PicomolePerLiter": 16, - "PicomolesPerLiter": 17 + "PicomolesPerLiter": 17, + "KilomolePerCubicMeter": 25, + "KilopoundMolePerCubicFoot": 23, + "PoundMolePerCubicFoot": 18 }, "MolarMass": { "CentigramPerMole": 1, @@ -970,7 +973,9 @@ "MicrogramPerMole": 9, "MilligramPerMole": 10, "NanogramPerMole": 11, - "PoundPerMole": 12 + "PoundPerMole": 12, + "KiloGramPerKiloMole": 20, + "KilogramPerKilomole": 15 }, "Permeability": { "HenryPerMeter": 1 @@ -1690,5 +1695,16 @@ "PoundFootPerSecond": 16, "SlugFootPerSecond": 11, "PoundForceSecond": 18 + }, + "MolarFlow": { + "KiloMolePerHour": 10, + "KiloMolePerMinute": 1, + "KiloMolePerSecond": 5, + "PoundMolePerHour": 6, + "PoundMolePerMinute": 7, + "PoundMolePerSecond": 4, + "KilomolePerHour": 2, + "KilomolePerMinute": 15, + "KilomolePerSecond": 12 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/MolarFlow.nfproj b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/MolarFlow.nfproj new file mode 100644 index 0000000000..cac2107cd5 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/MolarFlow.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {49cc942b-d836-a48b-0429-25bf95247759} + Library + Properties + 512 + UnitsNet + UnitsNet.MolarFlow + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/UnitsNet.NanoFramework.MolarFlow.nuspec b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/UnitsNet.NanoFramework.MolarFlow.nuspec new file mode 100644 index 0000000000..8be55b4230 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/UnitsNet.NanoFramework.MolarFlow.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.MolarFlow + 5.1.0 + Units.NET MolarFlow - nanoFramework + Andreas Gullberg Larsen,nanoFramework project contributors + UnitsNet + MIT + https://github.com/angularsen/UnitsNet + false + Adds MolarFlow 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 molarflow unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/packages.config b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/packages.config new file mode 100644 index 0000000000..faccd72a98 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/MolarFlow/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs new file mode 100644 index 0000000000..9eac852d38 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs @@ -0,0 +1,224 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// Molar flow is the ratio of the amount of substance change to the time during which the change occurred (value of amount of substance changes per unit time). + /// + public struct MolarFlow + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly MolarFlowUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public MolarFlowUnit 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 MolarFlow(double value, MolarFlowUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of Duration, which is Second. All conversions go via this value. + /// + public static MolarFlowUnit BaseUnit { get; } = MolarFlowUnit.KilomolePerSecond; + + /// + /// Represents the largest possible value of Duration + /// + public static MolarFlow MaxValue { get; } = new MolarFlow(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Duration + /// + public static MolarFlow MinValue { get; } = new MolarFlow(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static MolarFlow Zero { get; } = new MolarFlow(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerHour => As(MolarFlowUnit.KilomolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerMinute => As(MolarFlowUnit.KilomolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerSecond => As(MolarFlowUnit.KilomolePerSecond); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerHour => As(MolarFlowUnit.PoundMolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerMinute => As(MolarFlowUnit.PoundMolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerSecond => As(MolarFlowUnit.PoundMolePerSecond); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerHour(double kilomolesperhour) => new MolarFlow(kilomolesperhour, MolarFlowUnit.KilomolePerHour); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerMinute(double kilomolesperminute) => new MolarFlow(kilomolesperminute, MolarFlowUnit.KilomolePerMinute); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerSecond(double kilomolespersecond) => new MolarFlow(kilomolespersecond, MolarFlowUnit.KilomolePerSecond); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerHour(double poundsmoleperhour) => new MolarFlow(poundsmoleperhour, MolarFlowUnit.PoundMolePerHour); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerMinute(double poundsmoleperminute) => new MolarFlow(poundsmoleperminute, MolarFlowUnit.PoundMolePerMinute); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerSecond(double poundsmolepersecond) => new MolarFlow(poundsmolepersecond, MolarFlowUnit.PoundMolePerSecond); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MolarFlow unit value. + public static MolarFlow From(double value, MolarFlowUnit fromUnit) + { + return new MolarFlow(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(MolarFlowUnit unit) => GetValueAs(unit); + + /// + /// Converts this Duration to another Duration with the unit representation . + /// + /// A Duration with the specified unit. + public MolarFlow ToUnit(MolarFlowUnit unit) + { + var convertedValue = GetValueAs(unit); + return new MolarFlow(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() + { + return Unit switch + { + MolarFlowUnit.KilomolePerHour => _value / 3.599997e3, + MolarFlowUnit.KilomolePerMinute => _value / 5.999988e1, + MolarFlowUnit.KilomolePerSecond => _value, + MolarFlowUnit.PoundMolePerHour => _value / 7.93663391482404e3, + MolarFlowUnit.PoundMolePerMinute => _value / 1.32277406886626e2, + MolarFlowUnit.PoundMolePerSecond => _value / 2.2046244201838, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(MolarFlowUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + MolarFlowUnit.KilomolePerHour => baseUnitValue * 3.599997e3, + MolarFlowUnit.KilomolePerMinute => baseUnitValue * 5.999988e1, + MolarFlowUnit.KilomolePerSecond => baseUnitValue, + MolarFlowUnit.PoundMolePerHour => baseUnitValue * 7.93663391482404e3, + MolarFlowUnit.PoundMolePerMinute => baseUnitValue * 1.32277406886626e2, + MolarFlowUnit.PoundMolePerSecond => baseUnitValue * 2.2046244201838, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarMass.g.cs index 8134422826..95cdd25de5 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarMass.g.cs @@ -104,6 +104,11 @@ public MolarMass(double value, MolarMassUnit unit) /// public double HectogramsPerMole => As(MolarMassUnit.HectogramPerMole); + /// + /// Gets a value of this quantity converted into + /// + public double KilogramsPerKilomole => As(MolarMassUnit.KilogramPerKilomole); + /// /// Gets a value of this quantity converted into /// @@ -173,6 +178,12 @@ public MolarMass(double value, MolarMassUnit unit) /// If value is NaN or Infinity. public static MolarMass FromHectogramsPerMole(double hectogramspermole) => new MolarMass(hectogramspermole, MolarMassUnit.HectogramPerMole); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarMass FromKilogramsPerKilomole(double kilogramsperkilomole) => new MolarMass(kilogramsperkilomole, MolarMassUnit.KilogramPerKilomole); + /// /// Creates a from . /// @@ -260,6 +271,7 @@ private double GetValueInBaseUnit() MolarMassUnit.DecigramPerMole => (_value / 1e3) * 1e-1d, MolarMassUnit.GramPerMole => _value / 1e3, MolarMassUnit.HectogramPerMole => (_value / 1e3) * 1e2d, + MolarMassUnit.KilogramPerKilomole => _value / 1e3, MolarMassUnit.KilogramPerMole => (_value / 1e3) * 1e3d, MolarMassUnit.KilopoundPerMole => (_value * 0.45359237) * 1e3d, MolarMassUnit.MegapoundPerMole => (_value * 0.45359237) * 1e6d, @@ -285,6 +297,7 @@ private double GetValueAs(MolarMassUnit unit) MolarMassUnit.DecigramPerMole => (baseUnitValue * 1e3) / 1e-1d, MolarMassUnit.GramPerMole => baseUnitValue * 1e3, MolarMassUnit.HectogramPerMole => (baseUnitValue * 1e3) / 1e2d, + MolarMassUnit.KilogramPerKilomole => baseUnitValue * 1e3, MolarMassUnit.KilogramPerMole => (baseUnitValue * 1e3) / 1e3d, MolarMassUnit.KilopoundPerMole => (baseUnitValue / 0.45359237) / 1e3d, MolarMassUnit.MegapoundPerMole => (baseUnitValue / 0.45359237) / 1e6d, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs index d9263501fd..533d58a67d 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs @@ -97,6 +97,11 @@ public Molarity(double value, MolarityUnit unit) /// public double FemtomolesPerLiter => As(MolarityUnit.FemtomolePerLiter); + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerCubicMeter => As(MolarityUnit.KilomolePerCubicMeter); + /// /// Gets a value of this quantity converted into /// @@ -127,6 +132,11 @@ public Molarity(double value, MolarityUnit unit) /// public double PicomolesPerLiter => As(MolarityUnit.PicomolePerLiter); + /// + /// Gets a value of this quantity converted into + /// + public double PoundMolesPerCubicFoot => As(MolarityUnit.PoundMolePerCubicFoot); + #endregion #region Static Factory Methods @@ -149,6 +159,12 @@ public Molarity(double value, MolarityUnit unit) /// If value is NaN or Infinity. public static Molarity FromFemtomolesPerLiter(double femtomolesperliter) => new Molarity(femtomolesperliter, MolarityUnit.FemtomolePerLiter); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Molarity FromKilomolesPerCubicMeter(double kilomolespercubicmeter) => new Molarity(kilomolespercubicmeter, MolarityUnit.KilomolePerCubicMeter); + /// /// Creates a from . /// @@ -185,6 +201,12 @@ public Molarity(double value, MolarityUnit unit) /// If value is NaN or Infinity. public static Molarity FromPicomolesPerLiter(double picomolesperliter) => new Molarity(picomolesperliter, MolarityUnit.PicomolePerLiter); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Molarity FromPoundMolesPerCubicFoot(double poundmolespercubicfoot) => new Molarity(poundmolespercubicfoot, MolarityUnit.PoundMolePerCubicFoot); + /// /// Dynamically convert from value and unit enum to . /// @@ -228,12 +250,14 @@ private double GetValueInBaseUnit() MolarityUnit.CentimolePerLiter => (_value / 1e-3) * 1e-2d, MolarityUnit.DecimolePerLiter => (_value / 1e-3) * 1e-1d, MolarityUnit.FemtomolePerLiter => (_value / 1e-3) * 1e-15d, + MolarityUnit.KilomolePerCubicMeter => (_value) * 1e3d, MolarityUnit.MicromolePerLiter => (_value / 1e-3) * 1e-6d, MolarityUnit.MillimolePerLiter => (_value / 1e-3) * 1e-3d, MolarityUnit.MolePerCubicMeter => _value, MolarityUnit.MolePerLiter => _value / 1e-3, MolarityUnit.NanomolePerLiter => (_value / 1e-3) * 1e-9d, MolarityUnit.PicomolePerLiter => (_value / 1e-3) * 1e-12d, + MolarityUnit.PoundMolePerCubicFoot => _value / 6.242796e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -250,12 +274,14 @@ private double GetValueAs(MolarityUnit unit) MolarityUnit.CentimolePerLiter => (baseUnitValue * 1e-3) / 1e-2d, MolarityUnit.DecimolePerLiter => (baseUnitValue * 1e-3) / 1e-1d, MolarityUnit.FemtomolePerLiter => (baseUnitValue * 1e-3) / 1e-15d, + MolarityUnit.KilomolePerCubicMeter => (baseUnitValue) / 1e3d, MolarityUnit.MicromolePerLiter => (baseUnitValue * 1e-3) / 1e-6d, MolarityUnit.MillimolePerLiter => (baseUnitValue * 1e-3) / 1e-3d, MolarityUnit.MolePerCubicMeter => baseUnitValue, MolarityUnit.MolePerLiter => baseUnitValue * 1e-3, MolarityUnit.NanomolePerLiter => (baseUnitValue * 1e-3) / 1e-9d, MolarityUnit.PicomolePerLiter => (baseUnitValue * 1e-3) / 1e-12d, + MolarityUnit.PoundMolePerCubicFoot => baseUnitValue * 6.242796e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs new file mode 100644 index 0000000000..c58c44ea9e --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 MolarFlowUnit + { + KilomolePerHour = 2, + KilomolePerMinute = 15, + KilomolePerSecond = 12, + PoundMolePerHour = 6, + PoundMolePerMinute = 7, + PoundMolePerSecond = 4, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarMassUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarMassUnit.g.cs index 417075c855..4be43903ef 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarMassUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarMassUnit.g.cs @@ -30,6 +30,7 @@ public enum MolarMassUnit DecigramPerMole = 3, GramPerMole = 4, HectogramPerMole = 5, + KilogramPerKilomole = 15, KilogramPerMole = 6, KilopoundPerMole = 7, MegapoundPerMole = 8, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarityUnit.g.cs index 3119352a47..d9c7972422 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,12 +28,14 @@ public enum MolarityUnit CentimolePerLiter = 1, DecimolePerLiter = 3, FemtomolePerLiter = 5, + KilomolePerCubicMeter = 25, MicromolePerLiter = 6, MillimolePerLiter = 8, MolePerCubicMeter = 10, MolePerLiter = 11, NanomolePerLiter = 14, PicomolePerLiter = 16, + PoundMolePerCubicFoot = 18, } #pragma warning restore 1591 diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index c4180bc92b..e1eafd5bbc 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -142,6 +142,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "MolarEnergy", "MolarEnergy\ EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "MolarEntropy", "MolarEntropy\MolarEntropy.nfproj", "{2053731b-90f5-5141-d15e-8d7be8c2662f}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "MolarFlow", "MolarFlow\MolarFlow.nfproj", "{49cc942b-d836-a48b-0429-25bf95247759}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Molarity", "Molarity\Molarity.nfproj", "{0d21f127-8c25-9b3a-9612-ce2eea6e7ac1}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "MolarMass", "MolarMass\MolarMass.nfproj", "{fe51bbda-2039-23fd-f29a-39c14adcb1f6}" @@ -662,6 +664,12 @@ Global {2053731b-90f5-5141-d15e-8d7be8c2662f}.Release|Any CPU.ActiveCfg = Release|Any CPU {2053731b-90f5-5141-d15e-8d7be8c2662f}.Release|Any CPU.Build.0 = Release|Any CPU {2053731b-90f5-5141-d15e-8d7be8c2662f}.Release|Any CPU.Deploy.0 = Release|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Debug|Any CPU.Build.0 = Debug|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Release|Any CPU.ActiveCfg = Release|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Release|Any CPU.Build.0 = Release|Any CPU +{49cc942b-d836-a48b-0429-25bf95247759}.Release|Any CPU.Deploy.0 = Release|Any CPU {0d21f127-8c25-9b3a-9612-ce2eea6e7ac1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0d21f127-8c25-9b3a-9612-ce2eea6e7ac1}.Debug|Any CPU.Build.0 = Debug|Any CPU {0d21f127-8c25-9b3a-9612-ce2eea6e7ac1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs new file mode 100644 index 0000000000..29e576da4c --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToMolarFlow; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToMolarFlowExtensionsTests + { + [Fact] + public void NumberToKilomolesPerHourTest() => + Assert.Equal(MolarFlow.FromKilomolesPerHour(2), 2.KilomolesPerHour()); + + [Fact] + public void NumberToKilomolesPerMinuteTest() => + Assert.Equal(MolarFlow.FromKilomolesPerMinute(2), 2.KilomolesPerMinute()); + + [Fact] + public void NumberToKilomolesPerSecondTest() => + Assert.Equal(MolarFlow.FromKilomolesPerSecond(2), 2.KilomolesPerSecond()); + + [Fact] + public void NumberToPoundsMolePerHourTest() => + Assert.Equal(MolarFlow.FromPoundsMolePerHour(2), 2.PoundsMolePerHour()); + + [Fact] + public void NumberToPoundsMolePerMinuteTest() => + Assert.Equal(MolarFlow.FromPoundsMolePerMinute(2), 2.PoundsMolePerMinute()); + + [Fact] + public void NumberToPoundsMolePerSecondTest() => + Assert.Equal(MolarFlow.FromPoundsMolePerSecond(2), 2.PoundsMolePerSecond()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarMassExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarMassExtensionsTest.g.cs index 72161eee76..cc48f3cbf5 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarMassExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarMassExtensionsTest.g.cs @@ -44,6 +44,10 @@ public void NumberToGramsPerMoleTest() => public void NumberToHectogramsPerMoleTest() => Assert.Equal(MolarMass.FromHectogramsPerMole(2), 2.HectogramsPerMole()); + [Fact] + public void NumberToKilogramsPerKilomoleTest() => + Assert.Equal(MolarMass.FromKilogramsPerKilomole(2), 2.KilogramsPerKilomole()); + [Fact] public void NumberToKilogramsPerMoleTest() => Assert.Equal(MolarMass.FromKilogramsPerMole(2), 2.KilogramsPerMole()); diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarityExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarityExtensionsTest.g.cs index 688089b86b..4e870a80bf 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarityExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarityExtensionsTest.g.cs @@ -36,6 +36,10 @@ public void NumberToDecimolesPerLiterTest() => public void NumberToFemtomolesPerLiterTest() => Assert.Equal(Molarity.FromFemtomolesPerLiter(2), 2.FemtomolesPerLiter()); + [Fact] + public void NumberToKilomolesPerCubicMeterTest() => + Assert.Equal(Molarity.FromKilomolesPerCubicMeter(2), 2.KilomolesPerCubicMeter()); + [Fact] public void NumberToMicromolesPerLiterTest() => Assert.Equal(Molarity.FromMicromolesPerLiter(2), 2.MicromolesPerLiter()); @@ -60,5 +64,9 @@ public void NumberToNanomolesPerLiterTest() => public void NumberToPicomolesPerLiterTest() => Assert.Equal(Molarity.FromPicomolesPerLiter(2), 2.PicomolesPerLiter()); + [Fact] + public void NumberToPoundMolesPerCubicFootTest() => + Assert.Equal(Molarity.FromPoundMolesPerCubicFoot(2), 2.PoundMolesPerCubicFoot()); + } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs new file mode 100644 index 0000000000..91227f1b49 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToMolarFlow +{ + /// + /// A number to MolarFlow Extensions + /// + public static class NumberToMolarFlowExtensions + { + /// + public static MolarFlow KilomolesPerHour(this T value) => + MolarFlow.FromKilomolesPerHour(Convert.ToDouble(value)); + + /// + public static MolarFlow KilomolesPerMinute(this T value) => + MolarFlow.FromKilomolesPerMinute(Convert.ToDouble(value)); + + /// + public static MolarFlow KilomolesPerSecond(this T value) => + MolarFlow.FromKilomolesPerSecond(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundsMolePerHour(this T value) => + MolarFlow.FromPoundsMolePerHour(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundsMolePerMinute(this T value) => + MolarFlow.FromPoundsMolePerMinute(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundsMolePerSecond(this T value) => + MolarFlow.FromPoundsMolePerSecond(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarMassExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarMassExtensions.g.cs index 35d86155a5..2c8fa6dd48 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarMassExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarMassExtensions.g.cs @@ -48,6 +48,10 @@ public static MolarMass GramsPerMole(this T value) => public static MolarMass HectogramsPerMole(this T value) => MolarMass.FromHectogramsPerMole(Convert.ToDouble(value)); + /// + public static MolarMass KilogramsPerKilomole(this T value) => + MolarMass.FromKilogramsPerKilomole(Convert.ToDouble(value)); + /// public static MolarMass KilogramsPerMole(this T value) => MolarMass.FromKilogramsPerMole(Convert.ToDouble(value)); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarityExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarityExtensions.g.cs index a4f5a24607..c7b472ee5d 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarityExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarityExtensions.g.cs @@ -40,6 +40,10 @@ public static Molarity DecimolesPerLiter(this T value) => public static Molarity FemtomolesPerLiter(this T value) => Molarity.FromFemtomolesPerLiter(Convert.ToDouble(value)); + /// + public static Molarity KilomolesPerCubicMeter(this T value) => + Molarity.FromKilomolesPerCubicMeter(Convert.ToDouble(value)); + /// public static Molarity MicromolesPerLiter(this T value) => Molarity.FromMicromolesPerLiter(Convert.ToDouble(value)); @@ -64,5 +68,9 @@ public static Molarity NanomolesPerLiter(this T value) => public static Molarity PicomolesPerLiter(this T value) => Molarity.FromPicomolesPerLiter(Convert.ToDouble(value)); + /// + public static Molarity PoundMolesPerCubicFoot(this T value) => + Molarity.FromPoundMolesPerCubicFoot(Convert.ToDouble(value)); + } } diff --git a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs new file mode 100644 index 0000000000..232d4e67a1 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// 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; +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class MolarFlowTests : MolarFlowTestsBase + { + // Override properties in base class here + protected override bool SupportsSIUnitSystem => false; + + protected override double KilomolesPerHourInOneKilomolePerSecond => 3.599997e3; + + protected override double KilomolesPerMinuteInOneKilomolePerSecond => 5.999988e1; + + protected override double KilomolesPerSecondInOneKilomolePerSecond => 1.0; + + protected override double PoundsMolePerHourInOneKilomolePerSecond => 7.93663391482404e3; + + protected override double PoundsMolePerMinuteInOneKilomolePerSecond => 1.32277406886626e2; + + protected override double PoundsMolePerSecondInOneKilomolePerSecond => 2.2046244201838; + + [Fact] + public void MolarFlowTimesTimeSpanEqualsAmountOfSubstance() + { + AmountOfSubstance amount = MolarFlow.FromKilomolesPerSecond(20) * TimeSpan.FromSeconds(2); + Assert.Equal(AmountOfSubstance.FromKilomoles(40), amount); + } + + [Fact] + public void MolarFlowTimesDurationEqualsAmountOfSubstance() + { + AmountOfSubstance amount = MolarFlow.FromKilomolesPerSecond(20) * Duration.FromSeconds(2); + Assert.Equal(AmountOfSubstance.FromKilomoles(40), amount); + } + + [Fact] + public void MolarFlowTimesMolarMassEqualsMassFlow() + { + MassFlow massFlow = MolarFlow.FromKilomolesPerSecond(2) * MolarMass.FromKilogramsPerKilomole(3); + Assert.Equal(MassFlow.FromKilogramsPerSecond(6), massFlow); + } + + } +} diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index d954425a7a..264350bee0 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -42,6 +42,6 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleTolerance => 1e-3; protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; - + protected override double KilogramsPerKilomoleInOneKilogramPerMole => 1e3; } } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 7ff13f12b3..9d409e10d1 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -41,6 +41,8 @@ public class MolarityTests : MolarityTestsBase protected override double MicromolesPerLiterInOneMolePerCubicMeter => 1e3; protected override double NanomolesPerLiterInOneMolePerCubicMeter => 1e6; protected override double PicomolesPerLiterInOneMolePerCubicMeter => 1e9; + protected override double KilomolesPerCubicMeterInOneMolePerCubicMeter => 1e-3; + protected override double PoundMolesPerCubicFootInOneMolePerCubicMeter => 6.242796e-5; #endregion diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index ab0ba68c6e..63d87ca150 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -104,7 +104,8 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, MassMomentOfInertiaUnit.TonneSquareMilimeter, Quantity.From(3, MassMomentOfInertiaUnit.TonneSquareMilimeter)); Assertion(3, MolarEnergyUnit.MegajoulePerMole, Quantity.From(3, MolarEnergyUnit.MegajoulePerMole)); Assertion(3, MolarEntropyUnit.MegajoulePerMoleKelvin, Quantity.From(3, MolarEntropyUnit.MegajoulePerMoleKelvin)); - Assertion(3, MolarityUnit.PicomolePerLiter, Quantity.From(3, MolarityUnit.PicomolePerLiter)); + Assertion(3, MolarFlowUnit.PoundMolePerSecond, Quantity.From(3, MolarFlowUnit.PoundMolePerSecond)); + Assertion(3, MolarityUnit.PoundMolePerCubicFoot, Quantity.From(3, MolarityUnit.PoundMolePerCubicFoot)); Assertion(3, MolarMassUnit.PoundPerMole, Quantity.From(3, MolarMassUnit.PoundPerMole)); Assertion(3, PermeabilityUnit.HenryPerMeter, Quantity.From(3, PermeabilityUnit.HenryPerMeter)); Assertion(3, PermittivityUnit.FaradPerMeter, Quantity.From(3, PermittivityUnit.FaradPerMeter)); @@ -228,6 +229,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(MassMomentOfInertia.Info, MassMomentOfInertia.Zero); Assertion(MolarEnergy.Info, MolarEnergy.Zero); Assertion(MolarEntropy.Info, MolarEntropy.Zero); + Assertion(MolarFlow.Info, MolarFlow.Zero); Assertion(Molarity.Info, Molarity.Zero); Assertion(MolarMass.Info, MolarMass.Zero); Assertion(Permeability.Info, Permeability.Zero); @@ -352,6 +354,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(MassMomentOfInertia.BaseDimensions, MassMomentOfInertia.Zero); Assertion(MolarEnergy.BaseDimensions, MolarEnergy.Zero); Assertion(MolarEntropy.BaseDimensions, MolarEntropy.Zero); + Assertion(MolarFlow.BaseDimensions, MolarFlow.Zero); Assertion(Molarity.BaseDimensions, Molarity.Zero); Assertion(MolarMass.BaseDimensions, MolarMass.Zero); Assertion(Permeability.BaseDimensions, Permeability.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs new file mode 100644 index 0000000000..03a6024103 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -0,0 +1,816 @@ +//------------------------------------------------------------------------------ +// +// 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.Collections.Generic; +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 MolarFlow. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class MolarFlowTestsBase : QuantityTestsBase + { + protected abstract double KilomolesPerHourInOneKilomolePerSecond { get; } + protected abstract double KilomolesPerMinuteInOneKilomolePerSecond { get; } + protected abstract double KilomolesPerSecondInOneKilomolePerSecond { get; } + protected abstract double PoundsMolePerHourInOneKilomolePerSecond { get; } + protected abstract double PoundsMolePerMinuteInOneKilomolePerSecond { get; } + protected abstract double PoundsMolePerSecondInOneKilomolePerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double KilomolesPerHourTolerance { get { return 1e-5; } } + protected virtual double KilomolesPerMinuteTolerance { get { return 1e-5; } } + protected virtual double KilomolesPerSecondTolerance { get { return 1e-5; } } + protected virtual double PoundsMolePerHourTolerance { get { return 1e-5; } } + protected virtual double PoundsMolePerMinuteTolerance { get { return 1e-5; } } + protected virtual double PoundsMolePerSecondTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(MolarFlowUnit unit) + { + return unit switch + { + MolarFlowUnit.KilomolePerHour => (KilomolesPerHourInOneKilomolePerSecond, KilomolesPerHourTolerance), + MolarFlowUnit.KilomolePerMinute => (KilomolesPerMinuteInOneKilomolePerSecond, KilomolesPerMinuteTolerance), + MolarFlowUnit.KilomolePerSecond => (KilomolesPerSecondInOneKilomolePerSecond, KilomolesPerSecondTolerance), + MolarFlowUnit.PoundMolePerHour => (PoundsMolePerHourInOneKilomolePerSecond, PoundsMolePerHourTolerance), + MolarFlowUnit.PoundMolePerMinute => (PoundsMolePerMinuteInOneKilomolePerSecond, PoundsMolePerMinuteTolerance), + MolarFlowUnit.PoundMolePerSecond => (PoundsMolePerSecondInOneKilomolePerSecond, PoundsMolePerSecondTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { MolarFlowUnit.KilomolePerHour }, + new object[] { MolarFlowUnit.KilomolePerMinute }, + new object[] { MolarFlowUnit.KilomolePerSecond }, + new object[] { MolarFlowUnit.PoundMolePerHour }, + new object[] { MolarFlowUnit.PoundMolePerMinute }, + new object[] { MolarFlowUnit.PoundMolePerSecond }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new MolarFlow(); + Assert.Equal(0, quantity.Value); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new MolarFlow(double.PositiveInfinity, MolarFlowUnit.KilomolePerSecond)); + Assert.Throws(() => new MolarFlow(double.NegativeInfinity, MolarFlowUnit.KilomolePerSecond)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new MolarFlow(double.NaN, MolarFlowUnit.KilomolePerSecond)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new MolarFlow(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MolarFlow(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MolarFlow) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void MolarFlow_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new MolarFlow(1, MolarFlowUnit.KilomolePerSecond); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(MolarFlow.Zero, quantityInfo.Zero); + Assert.Equal("MolarFlow", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void KilomolePerSecondToMolarFlowUnits() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + AssertEx.EqualTolerance(KilomolesPerHourInOneKilomolePerSecond, kilomolepersecond.KilomolesPerHour, KilomolesPerHourTolerance); + AssertEx.EqualTolerance(KilomolesPerMinuteInOneKilomolePerSecond, kilomolepersecond.KilomolesPerMinute, KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(KilomolesPerSecondInOneKilomolePerSecond, kilomolepersecond.KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(PoundsMolePerHourInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerHour, PoundsMolePerHourTolerance); + AssertEx.EqualTolerance(PoundsMolePerMinuteInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + AssertEx.EqualTolerance(PoundsMolePerSecondInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = MolarFlow.From(1, MolarFlowUnit.KilomolePerHour); + AssertEx.EqualTolerance(1, quantity00.KilomolesPerHour, KilomolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerHour, quantity00.Unit); + + var quantity01 = MolarFlow.From(1, MolarFlowUnit.KilomolePerMinute); + AssertEx.EqualTolerance(1, quantity01.KilomolesPerMinute, KilomolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerMinute, quantity01.Unit); + + var quantity02 = MolarFlow.From(1, MolarFlowUnit.KilomolePerSecond); + AssertEx.EqualTolerance(1, quantity02.KilomolesPerSecond, KilomolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, quantity02.Unit); + + var quantity03 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerHour); + AssertEx.EqualTolerance(1, quantity03.PoundsMolePerHour, PoundsMolePerHourTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, quantity03.Unit); + + var quantity04 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerMinute); + AssertEx.EqualTolerance(1, quantity04.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, quantity04.Unit); + + var quantity05 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerSecond); + AssertEx.EqualTolerance(1, quantity05.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, quantity05.Unit); + + } + + [Fact] + public void FromKilomolesPerSecond_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.PositiveInfinity)); + Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.NegativeInfinity)); + } + + [Fact] + public void FromKilomolesPerSecond_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.NaN)); + } + + [Fact] + public void As() + { + var kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + AssertEx.EqualTolerance(KilomolesPerHourInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerHour), KilomolesPerHourTolerance); + AssertEx.EqualTolerance(KilomolesPerMinuteInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerMinute), KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(KilomolesPerSecondInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerSecond), KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(PoundsMolePerHourInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerHour), PoundsMolePerHourTolerance); + AssertEx.EqualTolerance(PoundsMolePerMinuteInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerMinute), PoundsMolePerMinuteTolerance); + AssertEx.EqualTolerance(PoundsMolePerSecondInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerSecond), PoundsMolePerSecondTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + + [Fact] + public void Parse() + { + try + { + var parsed = MolarFlow.Parse("1 kmol/h", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilomolesPerHour, KilomolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 kmol/min", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilomolesPerMinute, KilomolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 kmol/s", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilomolesPerSecond, KilomolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 lbmol/h", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerHour, PoundsMolePerHourTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 lbmol/min", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 lbmol/s", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(MolarFlow.TryParse("1 kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilomolesPerHour, KilomolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerHour, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 kmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilomolesPerMinute, KilomolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 kmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilomolesPerSecond, KilomolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 lbmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerHour, PoundsMolePerHourTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 lbmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 lbmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = MolarFlow.ParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("kmol/min", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("kmol/s", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("lbmol/min", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("lbmol/s", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(MolarFlow.TryParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("kmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("kmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("lbmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("lbmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(MolarFlowUnit unit) + { + var inBaseUnits = MolarFlow.From(1.0, MolarFlow.BaseUnit); + var converted = inBaseUnits.ToUnit(unit); + + var conversionFactor = GetConversionFactor(unit); + AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); + Assert.Equal(unit, converted.Unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_WithSameUnits_AreEqual(MolarFlowUnit unit) + { + var quantity = MolarFlow.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarFlowUnit unit) + { + // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. + var fromUnit = MolarFlow.Units.First(u => u != MolarFlow.BaseUnit); + + var quantity = MolarFlow.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(MolarFlowUnit unit) + { + var quantity = default(MolarFlow); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerHour(kilomolepersecond.KilomolesPerHour).KilomolesPerSecond, KilomolesPerHourTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerMinute(kilomolepersecond.KilomolesPerMinute).KilomolesPerSecond, KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerSecond(kilomolepersecond.KilomolesPerSecond).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerHour(kilomolepersecond.PoundsMolePerHour).KilomolesPerSecond, PoundsMolePerHourTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerMinute(kilomolepersecond.PoundsMolePerMinute).KilomolesPerSecond, PoundsMolePerMinuteTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerSecond(kilomolepersecond.PoundsMolePerSecond).KilomolesPerSecond, PoundsMolePerSecondTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + MolarFlow v = MolarFlow.FromKilomolesPerSecond(1); + AssertEx.EqualTolerance(-1, -v.KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (MolarFlow.FromKilomolesPerSecond(3)-v).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (v + v).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(10, (v*10).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(10, (10*v).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (MolarFlow.FromKilomolesPerSecond(10)/5).KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(2, MolarFlow.FromKilomolesPerSecond(10)/MolarFlow.FromKilomolesPerSecond(5), KilomolesPerSecondTolerance); + } + + [Fact] + public void ComparisonOperators() + { + MolarFlow oneKilomolePerSecond = MolarFlow.FromKilomolesPerSecond(1); + MolarFlow twoKilomolesPerSecond = MolarFlow.FromKilomolesPerSecond(2); + + Assert.True(oneKilomolePerSecond < twoKilomolesPerSecond); + Assert.True(oneKilomolePerSecond <= twoKilomolesPerSecond); + Assert.True(twoKilomolesPerSecond > oneKilomolePerSecond); + Assert.True(twoKilomolesPerSecond >= oneKilomolePerSecond); + + Assert.False(oneKilomolePerSecond > twoKilomolesPerSecond); + Assert.False(oneKilomolePerSecond >= twoKilomolesPerSecond); + Assert.False(twoKilomolesPerSecond < oneKilomolePerSecond); + Assert.False(twoKilomolesPerSecond <= oneKilomolePerSecond); + } + + [Fact] + public void CompareToIsImplemented() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + Assert.Equal(0, kilomolepersecond.CompareTo(kilomolepersecond)); + Assert.True(kilomolepersecond.CompareTo(MolarFlow.Zero) > 0); + Assert.True(MolarFlow.Zero.CompareTo(kilomolepersecond) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + Assert.Throws(() => kilomolepersecond.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + Assert.Throws(() => kilomolepersecond.CompareTo(null)); + } + + [Theory] + [InlineData(1, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerSecond, true)] // Same value and unit. + [InlineData(1, MolarFlowUnit.KilomolePerSecond, 2, MolarFlowUnit.KilomolePerSecond, false)] // Different value. + [InlineData(2, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different value and unit. + [InlineData(1, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarFlowUnit unitA, double valueB, MolarFlowUnit unitB, bool expectEqual) + { + var a = new MolarFlow(valueA, unitA); + var b = new MolarFlow(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MolarFlow.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + + [Fact] + public void Equals_RelativeTolerance_IsImplemented() + { + var v = MolarFlow.FromKilomolesPerSecond(1); + Assert.True(v.Equals(MolarFlow.FromKilomolesPerSecond(1), KilomolesPerSecondTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(MolarFlow.Zero, KilomolesPerSecondTolerance, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = MolarFlow.FromKilomolesPerSecond(1); + Assert.Throws(() => v.Equals(MolarFlow.FromKilomolesPerSecond(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + Assert.False(kilomolepersecond.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); + Assert.False(kilomolepersecond.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(MolarFlowUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(MolarFlow.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 kmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString()); + Assert.Equal("1 kmol/min", new MolarFlow(1, MolarFlowUnit.KilomolePerMinute).ToString()); + Assert.Equal("1 kmol/s", new MolarFlow(1, MolarFlowUnit.KilomolePerSecond).ToString()); + Assert.Equal("1 lbmol/h", new MolarFlow(1, MolarFlowUnit.PoundMolePerHour).ToString()); + Assert.Equal("1 lbmol/min", new MolarFlow(1, MolarFlowUnit.PoundMolePerMinute).ToString()); + Assert.Equal("1 lbmol/s", new MolarFlow(1, MolarFlowUnit.PoundMolePerSecond).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = 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 kmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString(swedishCulture)); + Assert.Equal("1 kmol/min", new MolarFlow(1, MolarFlowUnit.KilomolePerMinute).ToString(swedishCulture)); + Assert.Equal("1 kmol/s", new MolarFlow(1, MolarFlowUnit.KilomolePerSecond).ToString(swedishCulture)); + Assert.Equal("1 lbmol/h", new MolarFlow(1, MolarFlowUnit.PoundMolePerHour).ToString(swedishCulture)); + Assert.Equal("1 lbmol/min", new MolarFlow(1, MolarFlowUnit.PoundMolePerMinute).ToString(swedishCulture)); + Assert.Equal("1 lbmol/s", new MolarFlow(1, MolarFlowUnit.PoundMolePerSecond).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s1")); + Assert.Equal("0.12 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s2")); + Assert.Equal("0.123 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s3")); + Assert.Equal("0.1235 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s1", culture)); + Assert.Equal("0.12 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s2", culture)); + Assert.Equal("0.123 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s3", culture)); + Assert.Equal("0.1235 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + CultureInfo formatProvider = cultureName == null + ? null + : CultureInfo.GetCultureInfo(cultureName); + + Assert.Equal(quantity.ToString("g", formatProvider), quantity.ToString(null, formatProvider)); + } + + [Theory] + [InlineData(null)] + [InlineData("g")] + public void ToString_NullProvider_EqualsCurrentCulture(string format) + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(MolarFlow))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(MolarFlowUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(MolarFlow.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(MolarFlow.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + Assert.Equal(new {MolarFlow.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 = MolarFlow.FromKilomolesPerSecond(value); + Assert.Equal(MolarFlow.FromKilomolesPerSecond(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index c68a6474c1..7953b2e18f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -43,6 +43,7 @@ public abstract partial class MolarMassTestsBase : QuantityTestsBase protected abstract double DecigramsPerMoleInOneKilogramPerMole { get; } protected abstract double GramsPerMoleInOneKilogramPerMole { get; } protected abstract double HectogramsPerMoleInOneKilogramPerMole { get; } + protected abstract double KilogramsPerKilomoleInOneKilogramPerMole { get; } protected abstract double KilogramsPerMoleInOneKilogramPerMole { get; } protected abstract double KilopoundsPerMoleInOneKilogramPerMole { get; } protected abstract double MegapoundsPerMoleInOneKilogramPerMole { get; } @@ -57,6 +58,7 @@ public abstract partial class MolarMassTestsBase : QuantityTestsBase protected virtual double DecigramsPerMoleTolerance { get { return 1e-5; } } protected virtual double GramsPerMoleTolerance { get { return 1e-5; } } protected virtual double HectogramsPerMoleTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerKilomoleTolerance { get { return 1e-5; } } protected virtual double KilogramsPerMoleTolerance { get { return 1e-5; } } protected virtual double KilopoundsPerMoleTolerance { get { return 1e-5; } } protected virtual double MegapoundsPerMoleTolerance { get { return 1e-5; } } @@ -75,6 +77,7 @@ public abstract partial class MolarMassTestsBase : QuantityTestsBase MolarMassUnit.DecigramPerMole => (DecigramsPerMoleInOneKilogramPerMole, DecigramsPerMoleTolerance), MolarMassUnit.GramPerMole => (GramsPerMoleInOneKilogramPerMole, GramsPerMoleTolerance), MolarMassUnit.HectogramPerMole => (HectogramsPerMoleInOneKilogramPerMole, HectogramsPerMoleTolerance), + MolarMassUnit.KilogramPerKilomole => (KilogramsPerKilomoleInOneKilogramPerMole, KilogramsPerKilomoleTolerance), MolarMassUnit.KilogramPerMole => (KilogramsPerMoleInOneKilogramPerMole, KilogramsPerMoleTolerance), MolarMassUnit.KilopoundPerMole => (KilopoundsPerMoleInOneKilogramPerMole, KilopoundsPerMoleTolerance), MolarMassUnit.MegapoundPerMole => (MegapoundsPerMoleInOneKilogramPerMole, MegapoundsPerMoleTolerance), @@ -93,6 +96,7 @@ public abstract partial class MolarMassTestsBase : QuantityTestsBase new object[] { MolarMassUnit.DecigramPerMole }, new object[] { MolarMassUnit.GramPerMole }, new object[] { MolarMassUnit.HectogramPerMole }, + new object[] { MolarMassUnit.KilogramPerKilomole }, new object[] { MolarMassUnit.KilogramPerMole }, new object[] { MolarMassUnit.KilopoundPerMole }, new object[] { MolarMassUnit.MegapoundPerMole }, @@ -167,6 +171,7 @@ public void KilogramPerMoleToMolarMassUnits() AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.DecigramsPerMole, DecigramsPerMoleTolerance); AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.GramsPerMole, GramsPerMoleTolerance); AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.HectogramsPerMole, HectogramsPerMoleTolerance); + AssertEx.EqualTolerance(KilogramsPerKilomoleInOneKilogramPerMole, kilogrampermole.KilogramsPerKilomole, KilogramsPerKilomoleTolerance); AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.KilogramsPerMole, KilogramsPerMoleTolerance); AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.KilopoundsPerMole, KilopoundsPerMoleTolerance); AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.MegapoundsPerMole, MegapoundsPerMoleTolerance); @@ -199,33 +204,37 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity04.HectogramsPerMole, HectogramsPerMoleTolerance); Assert.Equal(MolarMassUnit.HectogramPerMole, quantity04.Unit); - var quantity05 = MolarMass.From(1, MolarMassUnit.KilogramPerMole); - AssertEx.EqualTolerance(1, quantity05.KilogramsPerMole, KilogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilogramPerMole, quantity05.Unit); + var quantity05 = MolarMass.From(1, MolarMassUnit.KilogramPerKilomole); + AssertEx.EqualTolerance(1, quantity05.KilogramsPerKilomole, KilogramsPerKilomoleTolerance); + Assert.Equal(MolarMassUnit.KilogramPerKilomole, quantity05.Unit); - var quantity06 = MolarMass.From(1, MolarMassUnit.KilopoundPerMole); - AssertEx.EqualTolerance(1, quantity06.KilopoundsPerMole, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, quantity06.Unit); + var quantity06 = MolarMass.From(1, MolarMassUnit.KilogramPerMole); + AssertEx.EqualTolerance(1, quantity06.KilogramsPerMole, KilogramsPerMoleTolerance); + Assert.Equal(MolarMassUnit.KilogramPerMole, quantity06.Unit); - var quantity07 = MolarMass.From(1, MolarMassUnit.MegapoundPerMole); - AssertEx.EqualTolerance(1, quantity07.MegapoundsPerMole, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, quantity07.Unit); + var quantity07 = MolarMass.From(1, MolarMassUnit.KilopoundPerMole); + AssertEx.EqualTolerance(1, quantity07.KilopoundsPerMole, KilopoundsPerMoleTolerance); + Assert.Equal(MolarMassUnit.KilopoundPerMole, quantity07.Unit); - var quantity08 = MolarMass.From(1, MolarMassUnit.MicrogramPerMole); - AssertEx.EqualTolerance(1, quantity08.MicrogramsPerMole, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, quantity08.Unit); + var quantity08 = MolarMass.From(1, MolarMassUnit.MegapoundPerMole); + AssertEx.EqualTolerance(1, quantity08.MegapoundsPerMole, MegapoundsPerMoleTolerance); + Assert.Equal(MolarMassUnit.MegapoundPerMole, quantity08.Unit); - var quantity09 = MolarMass.From(1, MolarMassUnit.MilligramPerMole); - AssertEx.EqualTolerance(1, quantity09.MilligramsPerMole, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, quantity09.Unit); + var quantity09 = MolarMass.From(1, MolarMassUnit.MicrogramPerMole); + AssertEx.EqualTolerance(1, quantity09.MicrogramsPerMole, MicrogramsPerMoleTolerance); + Assert.Equal(MolarMassUnit.MicrogramPerMole, quantity09.Unit); - var quantity10 = MolarMass.From(1, MolarMassUnit.NanogramPerMole); - AssertEx.EqualTolerance(1, quantity10.NanogramsPerMole, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, quantity10.Unit); + var quantity10 = MolarMass.From(1, MolarMassUnit.MilligramPerMole); + AssertEx.EqualTolerance(1, quantity10.MilligramsPerMole, MilligramsPerMoleTolerance); + Assert.Equal(MolarMassUnit.MilligramPerMole, quantity10.Unit); - var quantity11 = MolarMass.From(1, MolarMassUnit.PoundPerMole); - AssertEx.EqualTolerance(1, quantity11.PoundsPerMole, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, quantity11.Unit); + var quantity11 = MolarMass.From(1, MolarMassUnit.NanogramPerMole); + AssertEx.EqualTolerance(1, quantity11.NanogramsPerMole, NanogramsPerMoleTolerance); + Assert.Equal(MolarMassUnit.NanogramPerMole, quantity11.Unit); + + var quantity12 = MolarMass.From(1, MolarMassUnit.PoundPerMole); + AssertEx.EqualTolerance(1, quantity12.PoundsPerMole, PoundsPerMoleTolerance); + Assert.Equal(MolarMassUnit.PoundPerMole, quantity12.Unit); } @@ -251,6 +260,7 @@ public void As() AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.DecigramPerMole), DecigramsPerMoleTolerance); AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.GramPerMole), GramsPerMoleTolerance); AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.HectogramPerMole), HectogramsPerMoleTolerance); + AssertEx.EqualTolerance(KilogramsPerKilomoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilogramPerKilomole), KilogramsPerKilomoleTolerance); AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilogramPerMole), KilogramsPerMoleTolerance); AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilopoundPerMole), KilopoundsPerMoleTolerance); AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MegapoundPerMole), MegapoundsPerMoleTolerance); @@ -350,6 +360,13 @@ public void Parse() Assert.Equal(MolarMassUnit.HectogramPerMole, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = MolarMass.Parse("1 kg/kmol", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilogramsPerKilomole, KilogramsPerKilomoleTolerance); + Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = MolarMass.Parse("1 kg/mol", CultureInfo.GetCultureInfo("en-US")); @@ -513,6 +530,12 @@ public void TryParse() Assert.Equal(MolarMassUnit.HectogramPerMole, parsed.Unit); } + { + Assert.True(MolarMass.TryParse("1 kg/kmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilogramsPerKilomole, KilogramsPerKilomoleTolerance); + Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsed.Unit); + } + { Assert.True(MolarMass.TryParse("1 kg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilogramsPerMole, KilogramsPerMoleTolerance); @@ -662,6 +685,12 @@ public void ParseUnit() Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = MolarMass.ParseUnit("kg/kmol", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = MolarMass.ParseUnit("kg/mol", CultureInfo.GetCultureInfo("en-US")); @@ -801,6 +830,11 @@ public void TryParseUnit() Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); } + { + Assert.True(MolarMass.TryParseUnit("kg/kmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsedUnit); + } + { Assert.True(MolarMass.TryParseUnit("kg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(MolarMassUnit.KilogramPerMole, parsedUnit); @@ -924,6 +958,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, MolarMass.FromDecigramsPerMole(kilogrampermole.DecigramsPerMole).KilogramsPerMole, DecigramsPerMoleTolerance); AssertEx.EqualTolerance(1, MolarMass.FromGramsPerMole(kilogrampermole.GramsPerMole).KilogramsPerMole, GramsPerMoleTolerance); AssertEx.EqualTolerance(1, MolarMass.FromHectogramsPerMole(kilogrampermole.HectogramsPerMole).KilogramsPerMole, HectogramsPerMoleTolerance); + AssertEx.EqualTolerance(1, MolarMass.FromKilogramsPerKilomole(kilogrampermole.KilogramsPerKilomole).KilogramsPerMole, KilogramsPerKilomoleTolerance); AssertEx.EqualTolerance(1, MolarMass.FromKilogramsPerMole(kilogrampermole.KilogramsPerMole).KilogramsPerMole, KilogramsPerMoleTolerance); AssertEx.EqualTolerance(1, MolarMass.FromKilopoundsPerMole(kilogrampermole.KilopoundsPerMole).KilogramsPerMole, KilopoundsPerMoleTolerance); AssertEx.EqualTolerance(1, MolarMass.FromMegapoundsPerMole(kilogrampermole.MegapoundsPerMole).KilogramsPerMole, MegapoundsPerMoleTolerance); @@ -1083,6 +1118,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 dg/mol", new MolarMass(1, MolarMassUnit.DecigramPerMole).ToString()); Assert.Equal("1 g/mol", new MolarMass(1, MolarMassUnit.GramPerMole).ToString()); Assert.Equal("1 hg/mol", new MolarMass(1, MolarMassUnit.HectogramPerMole).ToString()); + Assert.Equal("1 kg/kmol", new MolarMass(1, MolarMassUnit.KilogramPerKilomole).ToString()); Assert.Equal("1 kg/mol", new MolarMass(1, MolarMassUnit.KilogramPerMole).ToString()); Assert.Equal("1 klb/mol", new MolarMass(1, MolarMassUnit.KilopoundPerMole).ToString()); Assert.Equal("1 Mlb/mol", new MolarMass(1, MolarMassUnit.MegapoundPerMole).ToString()); @@ -1108,6 +1144,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 dg/mol", new MolarMass(1, MolarMassUnit.DecigramPerMole).ToString(swedishCulture)); Assert.Equal("1 g/mol", new MolarMass(1, MolarMassUnit.GramPerMole).ToString(swedishCulture)); Assert.Equal("1 hg/mol", new MolarMass(1, MolarMassUnit.HectogramPerMole).ToString(swedishCulture)); + Assert.Equal("1 kg/kmol", new MolarMass(1, MolarMassUnit.KilogramPerKilomole).ToString(swedishCulture)); Assert.Equal("1 kg/mol", new MolarMass(1, MolarMassUnit.KilogramPerMole).ToString(swedishCulture)); Assert.Equal("1 klb/mol", new MolarMass(1, MolarMassUnit.KilopoundPerMole).ToString(swedishCulture)); Assert.Equal("1 Mlb/mol", new MolarMass(1, MolarMassUnit.MegapoundPerMole).ToString(swedishCulture)); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index bb0c982295..1eff8e5907 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -41,23 +41,27 @@ public abstract partial class MolarityTestsBase : QuantityTestsBase protected abstract double CentimolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double DecimolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double FemtomolesPerLiterInOneMolePerCubicMeter { get; } + protected abstract double KilomolesPerCubicMeterInOneMolePerCubicMeter { get; } protected abstract double MicromolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double MillimolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double MolesPerCubicMeterInOneMolePerCubicMeter { get; } protected abstract double MolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double NanomolesPerLiterInOneMolePerCubicMeter { get; } protected abstract double PicomolesPerLiterInOneMolePerCubicMeter { get; } + protected abstract double PoundMolesPerCubicFootInOneMolePerCubicMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global protected virtual double CentimolesPerLiterTolerance { get { return 1e-5; } } protected virtual double DecimolesPerLiterTolerance { get { return 1e-5; } } protected virtual double FemtomolesPerLiterTolerance { get { return 1e-5; } } + protected virtual double KilomolesPerCubicMeterTolerance { get { return 1e-5; } } protected virtual double MicromolesPerLiterTolerance { get { return 1e-5; } } protected virtual double MillimolesPerLiterTolerance { get { return 1e-5; } } protected virtual double MolesPerCubicMeterTolerance { get { return 1e-5; } } protected virtual double MolesPerLiterTolerance { get { return 1e-5; } } protected virtual double NanomolesPerLiterTolerance { get { return 1e-5; } } protected virtual double PicomolesPerLiterTolerance { get { return 1e-5; } } + protected virtual double PoundMolesPerCubicFootTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(MolarityUnit unit) @@ -67,12 +71,14 @@ public abstract partial class MolarityTestsBase : QuantityTestsBase MolarityUnit.CentimolePerLiter => (CentimolesPerLiterInOneMolePerCubicMeter, CentimolesPerLiterTolerance), MolarityUnit.DecimolePerLiter => (DecimolesPerLiterInOneMolePerCubicMeter, DecimolesPerLiterTolerance), MolarityUnit.FemtomolePerLiter => (FemtomolesPerLiterInOneMolePerCubicMeter, FemtomolesPerLiterTolerance), + MolarityUnit.KilomolePerCubicMeter => (KilomolesPerCubicMeterInOneMolePerCubicMeter, KilomolesPerCubicMeterTolerance), MolarityUnit.MicromolePerLiter => (MicromolesPerLiterInOneMolePerCubicMeter, MicromolesPerLiterTolerance), MolarityUnit.MillimolePerLiter => (MillimolesPerLiterInOneMolePerCubicMeter, MillimolesPerLiterTolerance), MolarityUnit.MolePerCubicMeter => (MolesPerCubicMeterInOneMolePerCubicMeter, MolesPerCubicMeterTolerance), MolarityUnit.MolePerLiter => (MolesPerLiterInOneMolePerCubicMeter, MolesPerLiterTolerance), MolarityUnit.NanomolePerLiter => (NanomolesPerLiterInOneMolePerCubicMeter, NanomolesPerLiterTolerance), MolarityUnit.PicomolePerLiter => (PicomolesPerLiterInOneMolePerCubicMeter, PicomolesPerLiterTolerance), + MolarityUnit.PoundMolePerCubicFoot => (PoundMolesPerCubicFootInOneMolePerCubicMeter, PoundMolesPerCubicFootTolerance), _ => throw new NotSupportedException() }; } @@ -82,12 +88,14 @@ public abstract partial class MolarityTestsBase : QuantityTestsBase new object[] { MolarityUnit.CentimolePerLiter }, new object[] { MolarityUnit.DecimolePerLiter }, new object[] { MolarityUnit.FemtomolePerLiter }, + new object[] { MolarityUnit.KilomolePerCubicMeter }, new object[] { MolarityUnit.MicromolePerLiter }, new object[] { MolarityUnit.MillimolePerLiter }, new object[] { MolarityUnit.MolePerCubicMeter }, new object[] { MolarityUnit.MolePerLiter }, new object[] { MolarityUnit.NanomolePerLiter }, new object[] { MolarityUnit.PicomolePerLiter }, + new object[] { MolarityUnit.PoundMolePerCubicFoot }, }; [Fact] @@ -153,12 +161,14 @@ public void MolePerCubicMeterToMolarityUnits() AssertEx.EqualTolerance(CentimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.CentimolesPerLiter, CentimolesPerLiterTolerance); AssertEx.EqualTolerance(DecimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.DecimolesPerLiter, DecimolesPerLiterTolerance); AssertEx.EqualTolerance(FemtomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.FemtomolesPerLiter, FemtomolesPerLiterTolerance); + AssertEx.EqualTolerance(KilomolesPerCubicMeterInOneMolePerCubicMeter, molepercubicmeter.KilomolesPerCubicMeter, KilomolesPerCubicMeterTolerance); AssertEx.EqualTolerance(MicromolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.MicromolesPerLiter, MicromolesPerLiterTolerance); AssertEx.EqualTolerance(MillimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.MillimolesPerLiter, MillimolesPerLiterTolerance); AssertEx.EqualTolerance(MolesPerCubicMeterInOneMolePerCubicMeter, molepercubicmeter.MolesPerCubicMeter, MolesPerCubicMeterTolerance); AssertEx.EqualTolerance(MolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.MolesPerLiter, MolesPerLiterTolerance); AssertEx.EqualTolerance(NanomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.NanomolesPerLiter, NanomolesPerLiterTolerance); AssertEx.EqualTolerance(PicomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.PicomolesPerLiter, PicomolesPerLiterTolerance); + AssertEx.EqualTolerance(PoundMolesPerCubicFootInOneMolePerCubicMeter, molepercubicmeter.PoundMolesPerCubicFoot, PoundMolesPerCubicFootTolerance); } [Fact] @@ -176,29 +186,37 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity02.FemtomolesPerLiter, FemtomolesPerLiterTolerance); Assert.Equal(MolarityUnit.FemtomolePerLiter, quantity02.Unit); - var quantity03 = Molarity.From(1, MolarityUnit.MicromolePerLiter); - AssertEx.EqualTolerance(1, quantity03.MicromolesPerLiter, MicromolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MicromolePerLiter, quantity03.Unit); + var quantity03 = Molarity.From(1, MolarityUnit.KilomolePerCubicMeter); + AssertEx.EqualTolerance(1, quantity03.KilomolesPerCubicMeter, KilomolesPerCubicMeterTolerance); + Assert.Equal(MolarityUnit.KilomolePerCubicMeter, quantity03.Unit); - var quantity04 = Molarity.From(1, MolarityUnit.MillimolePerLiter); - AssertEx.EqualTolerance(1, quantity04.MillimolesPerLiter, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolePerLiter, quantity04.Unit); + var quantity04 = Molarity.From(1, MolarityUnit.MicromolePerLiter); + AssertEx.EqualTolerance(1, quantity04.MicromolesPerLiter, MicromolesPerLiterTolerance); + Assert.Equal(MolarityUnit.MicromolePerLiter, quantity04.Unit); - var quantity05 = Molarity.From(1, MolarityUnit.MolePerCubicMeter); - AssertEx.EqualTolerance(1, quantity05.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - Assert.Equal(MolarityUnit.MolePerCubicMeter, quantity05.Unit); + var quantity05 = Molarity.From(1, MolarityUnit.MillimolePerLiter); + AssertEx.EqualTolerance(1, quantity05.MillimolesPerLiter, MillimolesPerLiterTolerance); + Assert.Equal(MolarityUnit.MillimolePerLiter, quantity05.Unit); - var quantity06 = Molarity.From(1, MolarityUnit.MolePerLiter); - AssertEx.EqualTolerance(1, quantity06.MolesPerLiter, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolePerLiter, quantity06.Unit); + var quantity06 = Molarity.From(1, MolarityUnit.MolePerCubicMeter); + AssertEx.EqualTolerance(1, quantity06.MolesPerCubicMeter, MolesPerCubicMeterTolerance); + Assert.Equal(MolarityUnit.MolePerCubicMeter, quantity06.Unit); - var quantity07 = Molarity.From(1, MolarityUnit.NanomolePerLiter); - AssertEx.EqualTolerance(1, quantity07.NanomolesPerLiter, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolePerLiter, quantity07.Unit); + var quantity07 = Molarity.From(1, MolarityUnit.MolePerLiter); + AssertEx.EqualTolerance(1, quantity07.MolesPerLiter, MolesPerLiterTolerance); + Assert.Equal(MolarityUnit.MolePerLiter, quantity07.Unit); - var quantity08 = Molarity.From(1, MolarityUnit.PicomolePerLiter); - AssertEx.EqualTolerance(1, quantity08.PicomolesPerLiter, PicomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.PicomolePerLiter, quantity08.Unit); + var quantity08 = Molarity.From(1, MolarityUnit.NanomolePerLiter); + AssertEx.EqualTolerance(1, quantity08.NanomolesPerLiter, NanomolesPerLiterTolerance); + Assert.Equal(MolarityUnit.NanomolePerLiter, quantity08.Unit); + + var quantity09 = Molarity.From(1, MolarityUnit.PicomolePerLiter); + AssertEx.EqualTolerance(1, quantity09.PicomolesPerLiter, PicomolesPerLiterTolerance); + Assert.Equal(MolarityUnit.PicomolePerLiter, quantity09.Unit); + + var quantity10 = Molarity.From(1, MolarityUnit.PoundMolePerCubicFoot); + AssertEx.EqualTolerance(1, quantity10.PoundMolesPerCubicFoot, PoundMolesPerCubicFootTolerance); + Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, quantity10.Unit); } @@ -222,12 +240,14 @@ public void As() AssertEx.EqualTolerance(CentimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.CentimolePerLiter), CentimolesPerLiterTolerance); AssertEx.EqualTolerance(DecimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.DecimolePerLiter), DecimolesPerLiterTolerance); AssertEx.EqualTolerance(FemtomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.FemtomolePerLiter), FemtomolesPerLiterTolerance); + AssertEx.EqualTolerance(KilomolesPerCubicMeterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.KilomolePerCubicMeter), KilomolesPerCubicMeterTolerance); AssertEx.EqualTolerance(MicromolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.MicromolePerLiter), MicromolesPerLiterTolerance); AssertEx.EqualTolerance(MillimolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.MillimolePerLiter), MillimolesPerLiterTolerance); AssertEx.EqualTolerance(MolesPerCubicMeterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.MolePerCubicMeter), MolesPerCubicMeterTolerance); AssertEx.EqualTolerance(MolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.MolePerLiter), MolesPerLiterTolerance); AssertEx.EqualTolerance(NanomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.NanomolePerLiter), NanomolesPerLiterTolerance); AssertEx.EqualTolerance(PicomolesPerLiterInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.PicomolePerLiter), PicomolesPerLiterTolerance); + AssertEx.EqualTolerance(PoundMolesPerCubicFootInOneMolePerCubicMeter, molepercubicmeter.As(MolarityUnit.PoundMolePerCubicFoot), PoundMolesPerCubicFootTolerance); } [Fact] @@ -292,6 +312,13 @@ public void Parse() Assert.Equal(MolarityUnit.FemtomolePerLiter, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Molarity.Parse("1 kmol/m³", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilomolesPerCubicMeter, KilomolesPerCubicMeterTolerance); + Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Molarity.Parse("1 µmol/L", CultureInfo.GetCultureInfo("en-US")); @@ -369,6 +396,13 @@ public void Parse() Assert.Equal(MolarityUnit.PicomolePerLiter, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Molarity.Parse("1 lbmol/ft³", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerCubicFoot, PoundMolesPerCubicFootTolerance); + Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] @@ -410,6 +444,12 @@ public void TryParse() Assert.Equal(MolarityUnit.FemtomolePerLiter, parsed.Unit); } + { + Assert.True(Molarity.TryParse("1 kmol/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilomolesPerCubicMeter, KilomolesPerCubicMeterTolerance); + Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsed.Unit); + } + { Assert.True(Molarity.TryParse("1 µmol/L", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MicromolesPerLiter, MicromolesPerLiterTolerance); @@ -476,6 +516,12 @@ public void TryParse() Assert.Equal(MolarityUnit.PicomolePerLiter, parsed.Unit); } + { + Assert.True(Molarity.TryParse("1 lbmol/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerCubicFoot, PoundMolesPerCubicFootTolerance); + Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsed.Unit); + } + } [Fact] @@ -517,6 +563,12 @@ public void ParseUnit() Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = Molarity.ParseUnit("kmol/m³", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = Molarity.ParseUnit("µmol/L", CultureInfo.GetCultureInfo("en-US")); @@ -583,6 +635,12 @@ public void ParseUnit() Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = Molarity.ParseUnit("lbmol/ft³", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] @@ -618,6 +676,11 @@ public void TryParseUnit() Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); } + { + Assert.True(Molarity.TryParseUnit("kmol/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsedUnit); + } + { Assert.True(Molarity.TryParseUnit("µmol/L", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(MolarityUnit.MicromolePerLiter, parsedUnit); @@ -673,6 +736,11 @@ public void TryParseUnit() Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); } + { + Assert.True(Molarity.TryParseUnit("lbmol/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsedUnit); + } + } [Theory] @@ -724,12 +792,14 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Molarity.FromCentimolesPerLiter(molepercubicmeter.CentimolesPerLiter).MolesPerCubicMeter, CentimolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromDecimolesPerLiter(molepercubicmeter.DecimolesPerLiter).MolesPerCubicMeter, DecimolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromFemtomolesPerLiter(molepercubicmeter.FemtomolesPerLiter).MolesPerCubicMeter, FemtomolesPerLiterTolerance); + AssertEx.EqualTolerance(1, Molarity.FromKilomolesPerCubicMeter(molepercubicmeter.KilomolesPerCubicMeter).MolesPerCubicMeter, KilomolesPerCubicMeterTolerance); AssertEx.EqualTolerance(1, Molarity.FromMicromolesPerLiter(molepercubicmeter.MicromolesPerLiter).MolesPerCubicMeter, MicromolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromMillimolesPerLiter(molepercubicmeter.MillimolesPerLiter).MolesPerCubicMeter, MillimolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromMolesPerCubicMeter(molepercubicmeter.MolesPerCubicMeter).MolesPerCubicMeter, MolesPerCubicMeterTolerance); AssertEx.EqualTolerance(1, Molarity.FromMolesPerLiter(molepercubicmeter.MolesPerLiter).MolesPerCubicMeter, MolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromNanomolesPerLiter(molepercubicmeter.NanomolesPerLiter).MolesPerCubicMeter, NanomolesPerLiterTolerance); AssertEx.EqualTolerance(1, Molarity.FromPicomolesPerLiter(molepercubicmeter.PicomolesPerLiter).MolesPerCubicMeter, PicomolesPerLiterTolerance); + AssertEx.EqualTolerance(1, Molarity.FromPoundMolesPerCubicFoot(molepercubicmeter.PoundMolesPerCubicFoot).MolesPerCubicMeter, PoundMolesPerCubicFootTolerance); } [Fact] @@ -880,12 +950,14 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 cmol/L", new Molarity(1, MolarityUnit.CentimolePerLiter).ToString()); Assert.Equal("1 dmol/L", new Molarity(1, MolarityUnit.DecimolePerLiter).ToString()); Assert.Equal("1 fmol/L", new Molarity(1, MolarityUnit.FemtomolePerLiter).ToString()); + Assert.Equal("1 kmol/m³", new Molarity(1, MolarityUnit.KilomolePerCubicMeter).ToString()); Assert.Equal("1 µmol/L", new Molarity(1, MolarityUnit.MicromolePerLiter).ToString()); Assert.Equal("1 mmol/L", new Molarity(1, MolarityUnit.MillimolePerLiter).ToString()); Assert.Equal("1 mol/m³", new Molarity(1, MolarityUnit.MolePerCubicMeter).ToString()); Assert.Equal("1 mol/L", new Molarity(1, MolarityUnit.MolePerLiter).ToString()); Assert.Equal("1 nmol/L", new Molarity(1, MolarityUnit.NanomolePerLiter).ToString()); Assert.Equal("1 pmol/L", new Molarity(1, MolarityUnit.PicomolePerLiter).ToString()); + Assert.Equal("1 lbmol/ft³", new Molarity(1, MolarityUnit.PoundMolePerCubicFoot).ToString()); } finally { @@ -902,12 +974,14 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 cmol/L", new Molarity(1, MolarityUnit.CentimolePerLiter).ToString(swedishCulture)); Assert.Equal("1 dmol/L", new Molarity(1, MolarityUnit.DecimolePerLiter).ToString(swedishCulture)); Assert.Equal("1 fmol/L", new Molarity(1, MolarityUnit.FemtomolePerLiter).ToString(swedishCulture)); + Assert.Equal("1 kmol/m³", new Molarity(1, MolarityUnit.KilomolePerCubicMeter).ToString(swedishCulture)); Assert.Equal("1 µmol/L", new Molarity(1, MolarityUnit.MicromolePerLiter).ToString(swedishCulture)); Assert.Equal("1 mmol/L", new Molarity(1, MolarityUnit.MillimolePerLiter).ToString(swedishCulture)); Assert.Equal("1 mol/m³", new Molarity(1, MolarityUnit.MolePerCubicMeter).ToString(swedishCulture)); Assert.Equal("1 mol/L", new Molarity(1, MolarityUnit.MolePerLiter).ToString(swedishCulture)); Assert.Equal("1 nmol/L", new Molarity(1, MolarityUnit.NanomolePerLiter).ToString(swedishCulture)); Assert.Equal("1 pmol/L", new Molarity(1, MolarityUnit.PicomolePerLiter).ToString(swedishCulture)); + Assert.Equal("1 lbmol/ft³", new Molarity(1, MolarityUnit.PoundMolePerCubicFoot).ToString(swedishCulture)); } [Fact] diff --git a/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs b/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs new file mode 100644 index 0000000000..a6b58b2d9b --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs @@ -0,0 +1,26 @@ +using System; + +namespace UnitsNet +{ + public partial struct MolarFlow + { + /// Get from times . + public static AmountOfSubstance operator *(MolarFlow molarFlow, TimeSpan timeSpan) + { + return AmountOfSubstance.FromKilomoles(molarFlow.KilomolesPerSecond * timeSpan.TotalSeconds); + } + + /// Get from times . + public static AmountOfSubstance operator *(MolarFlow molarFlow, Duration duration) + { + return AmountOfSubstance.FromKilomoles(molarFlow.KilomolesPerSecond * duration.Seconds); + } + + /// Get from times . + public static MassFlow operator *(MolarFlow molarFlow, MolarMass molecularWeight) + { + return MassFlow.FromKilogramsPerSecond(molarFlow.KilomolesPerSecond * molecularWeight.KilogramsPerKilomole); + } + + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs new file mode 100644 index 0000000000..328d85b245 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -0,0 +1,995 @@ +//------------------------------------------------------------------------------ +// +// 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.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// Molar flow is the ratio of the amount of substance change to the time during which the change occurred (value of amount of substance changes per unit time). + /// + [DataContract] + public readonly partial struct MolarFlow : IArithmeticQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 0)] + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 1)] + private readonly MolarFlowUnit? _unit; + + static MolarFlow() + { + BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 1, 0); + BaseUnit = MolarFlowUnit.KilomolePerSecond; + Units = Enum.GetValues(typeof(MolarFlowUnit)).Cast().ToArray(); + Zero = new MolarFlow(0, BaseUnit); + Info = new QuantityInfo("MolarFlow", + new UnitInfo[] + { + new UnitInfo(MolarFlowUnit.KilomolePerHour, "KilomolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Kilomole)), + new UnitInfo(MolarFlowUnit.KilomolePerMinute, "KilomolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Kilomole)), + new UnitInfo(MolarFlowUnit.KilomolePerSecond, "KilomolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Kilomole)), + new UnitInfo(MolarFlowUnit.PoundMolePerHour, "PoundsMolePerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.PoundMole)), + new UnitInfo(MolarFlowUnit.PoundMolePerMinute, "PoundsMolePerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.PoundMole)), + new UnitInfo(MolarFlowUnit.PoundMolePerSecond, "PoundsMolePerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.PoundMole)), + }, + BaseUnit, Zero, BaseDimensions); + + DefaultConversionFunctions = new UnitConverter(); + RegisterDefaultConversions(DefaultConversionFunctions); + } + + /// + /// 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 MolarFlow(double value, MolarFlowUnit 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 MolarFlow(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 + + /// + /// The containing the default generated conversion functions for instances. + /// + public static UnitConverter DefaultConversionFunctions { get; } + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of MolarFlow, which is KilomolePerSecond. All conversions go via this value. + /// + public static MolarFlowUnit BaseUnit { get; } + + /// + /// All units of measurement for the MolarFlow quantity. + /// + public static MolarFlowUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit KilomolePerSecond. + /// + public static MolarFlow Zero { get; } + + /// + public static MolarFlow AdditiveIdentity => Zero; + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + QuantityValue IQuantity.Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public MolarFlowUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => MolarFlow.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerHour => As(MolarFlowUnit.KilomolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerMinute => As(MolarFlowUnit.KilomolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerSecond => As(MolarFlowUnit.KilomolePerSecond); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerHour => As(MolarFlowUnit.PoundMolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerMinute => As(MolarFlowUnit.PoundMolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double PoundsMolePerSecond => As(MolarFlowUnit.PoundMolePerSecond); + + #endregion + + #region Static Methods + + /// + /// Registers the default conversion functions in the given instance. + /// + /// The to register the default conversion functions in. + internal static void RegisterDefaultConversions(UnitConverter unitConverter) + { + // Register in unit converter: MolarFlowUnit -> BaseUnit + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerHour, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerSecond, quantity => quantity); + + // Register in unit converter: BaseUnit -> MolarFlowUnit + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerHour)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerMinute)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerHour)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerMinute)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerSecond)); + } + + internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) + { + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerHour, new CultureInfo("en-US"), false, true, new string[]{"kmol/h"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerMinute, new CultureInfo("en-US"), false, true, new string[]{"kmol/min"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerSecond, new CultureInfo("en-US"), false, true, new string[]{"kmol/s"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerHour, new CultureInfo("en-US"), false, true, new string[]{"lbmol/h"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerMinute, new CultureInfo("en-US"), false, true, new string[]{"lbmol/min"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerSecond, new CultureInfo("en-US"), false, true, new string[]{"lbmol/s"}); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(MolarFlowUnit 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(MolarFlowUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerHour(QuantityValue kilomolesperhour) + { + double value = (double) kilomolesperhour; + return new MolarFlow(value, MolarFlowUnit.KilomolePerHour); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerMinute(QuantityValue kilomolesperminute) + { + double value = (double) kilomolesperminute; + return new MolarFlow(value, MolarFlowUnit.KilomolePerMinute); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromKilomolesPerSecond(QuantityValue kilomolespersecond) + { + double value = (double) kilomolespersecond; + return new MolarFlow(value, MolarFlowUnit.KilomolePerSecond); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerHour(QuantityValue poundsmoleperhour) + { + double value = (double) poundsmoleperhour; + return new MolarFlow(value, MolarFlowUnit.PoundMolePerHour); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerMinute(QuantityValue poundsmoleperminute) + { + double value = (double) poundsmoleperminute; + return new MolarFlow(value, MolarFlowUnit.PoundMolePerMinute); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromPoundsMolePerSecond(QuantityValue poundsmolepersecond) + { + double value = (double) poundsmolepersecond; + return new MolarFlow(value, MolarFlowUnit.PoundMolePerSecond); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MolarFlow unit value. + public static MolarFlow From(QuantityValue value, MolarFlowUnit fromUnit) + { + return new MolarFlow((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 MolarFlow 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 MolarFlow 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 MolarFlow 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 MolarFlow 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 MolarFlowUnit 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 MolarFlowUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out MolarFlowUnit 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 MolarFlowUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static MolarFlow operator -(MolarFlow right) + { + return new MolarFlow(-right.Value, right.Unit); + } + + /// Get from adding two . + public static MolarFlow operator +(MolarFlow left, MolarFlow right) + { + return new MolarFlow(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static MolarFlow operator -(MolarFlow left, MolarFlow right) + { + return new MolarFlow(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static MolarFlow operator *(double left, MolarFlow right) + { + return new MolarFlow(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static MolarFlow operator *(MolarFlow left, double right) + { + return new MolarFlow(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static MolarFlow operator /(MolarFlow left, double right) + { + return new MolarFlow(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(MolarFlow left, MolarFlow right) + { + return left.KilomolesPerSecond / right.KilomolesPerSecond; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(MolarFlow left, MolarFlow right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(MolarFlow left, MolarFlow right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(MolarFlow left, MolarFlow right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(MolarFlow left, MolarFlow right) + { + return left.Value > right.ToUnit(left.Unit).Value; + } + + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #pragma warning disable CS0809 + + /// Indicates strict equality of two quantities, where both and are exactly equal. + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator ==(MolarFlow left, MolarFlow right) + { + return left.Equals(right); + } + + /// Indicates strict inequality of two quantities, where both and are exactly equal. + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MolarFlow left, MolarFlow right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public override bool Equals(object? obj) + { + if (obj is null || !(obj is MolarFlow otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public bool Equals(MolarFlow other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(object? obj) + { + if (obj is null) throw new ArgumentNullException(nameof(obj)); + if (!(obj is MolarFlow otherQuantity)) throw new ArgumentException("Expected type MolarFlow.", nameof(obj)); + + return CompareTo(otherQuantity); + } + + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(MolarFlow other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another MolarFlow 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 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(MolarFlow other, double tolerance, ComparisonType comparisonType) + { + if (tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = 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 MolarFlow. + 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(MolarFlowUnit unit) + { + if (Unit == unit) + return Value; + + return ToUnit(unit).Value; + } + + /// + 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 MolarFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); + + return (double)As(typedUnit); + } + + /// + /// Converts this MolarFlow to another MolarFlow with the unit representation . + /// + /// The unit to convert to. + /// A MolarFlow with the specified unit. + public MolarFlow ToUnit(MolarFlowUnit unit) + { + return ToUnit(unit, DefaultConversionFunctions); + } + + /// + /// Converts this to another using the given with the unit representation . + /// + /// The unit to convert to. + /// The to use for the conversion. + /// A MolarFlow with the specified unit. + public MolarFlow ToUnit(MolarFlowUnit unit, UnitConverter unitConverter) + { + if (TryToUnit(unit, out var converted)) + { + // Try to convert using the auto-generated conversion methods. + return converted!.Value; + } + else if (unitConverter.TryGetConversionFunction((typeof(MolarFlow), Unit, typeof(MolarFlow), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (MolarFlow)conversionFunction(this); + } + else if (Unit != BaseUnit) + { + // Conversion to requested unit NOT found. Try to convert to BaseUnit, and then from BaseUnit to requested unit. + var inBaseUnits = ToUnit(BaseUnit); + return inBaseUnits.ToUnit(unit); + } + else + { + // No possible conversion + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + /// + /// Attempts to convert this to another with the unit representation . + /// + /// The unit to convert to. + /// The converted in , if successful. + /// True if successful, otherwise false. + private bool TryToUnit(MolarFlowUnit unit, [NotNullWhen(true)] out MolarFlow? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + MolarFlow? convertedOrNull = (Unit, unit) switch + { + // MolarFlowUnit -> BaseUnit + (MolarFlowUnit.KilomolePerHour, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 3.599997e3, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 5.999988e1, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 7.93663391482404e3, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 1.32277406886626e2, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 2.2046244201838, MolarFlowUnit.KilomolePerSecond), + + // BaseUnit -> MolarFlowUnit + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerHour) => new MolarFlow(_value * 3.599997e3, MolarFlowUnit.KilomolePerHour), + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerMinute) => new MolarFlow(_value * 5.999988e1, MolarFlowUnit.KilomolePerMinute), + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerHour) => new MolarFlow(_value * 7.93663391482404e3, MolarFlowUnit.PoundMolePerHour), + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerMinute) => new MolarFlow(_value * 1.32277406886626e2, MolarFlowUnit.PoundMolePerMinute), + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerSecond) => new MolarFlow(_value * 2.2046244201838, MolarFlowUnit.PoundMolePerSecond), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public MolarFlow 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(MolarFlowUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + #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); + } + + /// + /// + /// 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.CurrentCulture); + } + + /// + /// + /// 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(MolarFlow)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(MolarFlow)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(MolarFlow)} 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(MolarFlow)) + return this; + else if (conversionType == typeof(MolarFlowUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return MolarFlow.Info; + else if (conversionType == typeof(BaseDimensions)) + return MolarFlow.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(MolarFlow)} 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/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index 28a370fd1a..37c5edb8aa 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -64,6 +64,7 @@ static MolarMass() new UnitInfo(MolarMassUnit.DecigramPerMole, "DecigramsPerMole", BaseUnits.Undefined), new UnitInfo(MolarMassUnit.GramPerMole, "GramsPerMole", BaseUnits.Undefined), new UnitInfo(MolarMassUnit.HectogramPerMole, "HectogramsPerMole", BaseUnits.Undefined), + new UnitInfo(MolarMassUnit.KilogramPerKilomole, "KilogramsPerKilomole", BaseUnits.Undefined), new UnitInfo(MolarMassUnit.KilogramPerMole, "KilogramsPerMole", BaseUnits.Undefined), new UnitInfo(MolarMassUnit.KilopoundPerMole, "KilopoundsPerMole", BaseUnits.Undefined), new UnitInfo(MolarMassUnit.MegapoundPerMole, "MegapoundsPerMole", BaseUnits.Undefined), @@ -199,6 +200,11 @@ public MolarMass(double value, UnitSystem unitSystem) /// public double HectogramsPerMole => As(MolarMassUnit.HectogramPerMole); + /// + /// Gets a value of this quantity converted into + /// + public double KilogramsPerKilomole => As(MolarMassUnit.KilogramPerKilomole); + /// /// Gets a value of this quantity converted into /// @@ -250,6 +256,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MolarMassUnit.DecigramPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.GramPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.HectogramPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); + unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerKilomole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.KilopoundPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.MegapoundPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.MicrogramPerMole, MolarMassUnit.KilogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerMole)); @@ -266,6 +273,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.DecigramPerMole, quantity => quantity.ToUnit(MolarMassUnit.DecigramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.GramPerMole, quantity => quantity.ToUnit(MolarMassUnit.GramPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.HectogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.HectogramPerMole)); + unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.KilogramPerKilomole, quantity => quantity.ToUnit(MolarMassUnit.KilogramPerKilomole)); unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.KilopoundPerMole, quantity => quantity.ToUnit(MolarMassUnit.KilopoundPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.MegapoundPerMole, quantity => quantity.ToUnit(MolarMassUnit.MegapoundPerMole)); unitConverter.SetConversionFunction(MolarMassUnit.KilogramPerMole, MolarMassUnit.MicrogramPerMole, quantity => quantity.ToUnit(MolarMassUnit.MicrogramPerMole)); @@ -286,6 +294,7 @@ internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbrev unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.GramPerMole, new CultureInfo("ru-RU"), false, true, new string[]{"г/моль"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.HectogramPerMole, new CultureInfo("en-US"), false, true, new string[]{"hg/mol"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.HectogramPerMole, new CultureInfo("ru-RU"), false, true, new string[]{"гг/моль"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.KilogramPerKilomole, new CultureInfo("en-US"), false, true, new string[]{"kg/kmol"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.KilogramPerMole, new CultureInfo("en-US"), false, true, new string[]{"kg/mol"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.KilogramPerMole, new CultureInfo("ru-RU"), false, true, new string[]{"кг/моль"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarMassUnit.KilopoundPerMole, new CultureInfo("en-US"), false, true, new string[]{"klb/mol"}); @@ -377,6 +386,16 @@ public static MolarMass FromHectogramsPerMole(QuantityValue hectogramspermole) return new MolarMass(value, MolarMassUnit.HectogramPerMole); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarMass FromKilogramsPerKilomole(QuantityValue kilogramsperkilomole) + { + double value = (double) kilogramsperkilomole; + return new MolarMass(value, MolarMassUnit.KilogramPerKilomole); + } + /// /// Creates a from . /// @@ -918,6 +937,7 @@ private bool TryToUnit(MolarMassUnit unit, [NotNullWhen(true)] out MolarMass? co (MolarMassUnit.DecigramPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass((_value / 1e3) * 1e-1d, MolarMassUnit.KilogramPerMole), (MolarMassUnit.GramPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass(_value / 1e3, MolarMassUnit.KilogramPerMole), (MolarMassUnit.HectogramPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass((_value / 1e3) * 1e2d, MolarMassUnit.KilogramPerMole), + (MolarMassUnit.KilogramPerKilomole, MolarMassUnit.KilogramPerMole) => new MolarMass(_value / 1e3, MolarMassUnit.KilogramPerMole), (MolarMassUnit.KilopoundPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass((_value * 0.45359237) * 1e3d, MolarMassUnit.KilogramPerMole), (MolarMassUnit.MegapoundPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass((_value * 0.45359237) * 1e6d, MolarMassUnit.KilogramPerMole), (MolarMassUnit.MicrogramPerMole, MolarMassUnit.KilogramPerMole) => new MolarMass((_value / 1e3) * 1e-6d, MolarMassUnit.KilogramPerMole), @@ -931,6 +951,7 @@ private bool TryToUnit(MolarMassUnit unit, [NotNullWhen(true)] out MolarMass? co (MolarMassUnit.KilogramPerMole, MolarMassUnit.DecigramPerMole) => new MolarMass((_value * 1e3) / 1e-1d, MolarMassUnit.DecigramPerMole), (MolarMassUnit.KilogramPerMole, MolarMassUnit.GramPerMole) => new MolarMass(_value * 1e3, MolarMassUnit.GramPerMole), (MolarMassUnit.KilogramPerMole, MolarMassUnit.HectogramPerMole) => new MolarMass((_value * 1e3) / 1e2d, MolarMassUnit.HectogramPerMole), + (MolarMassUnit.KilogramPerMole, MolarMassUnit.KilogramPerKilomole) => new MolarMass(_value * 1e3, MolarMassUnit.KilogramPerKilomole), (MolarMassUnit.KilogramPerMole, MolarMassUnit.KilopoundPerMole) => new MolarMass((_value / 0.45359237) / 1e3d, MolarMassUnit.KilopoundPerMole), (MolarMassUnit.KilogramPerMole, MolarMassUnit.MegapoundPerMole) => new MolarMass((_value / 0.45359237) / 1e6d, MolarMassUnit.MegapoundPerMole), (MolarMassUnit.KilogramPerMole, MolarMassUnit.MicrogramPerMole) => new MolarMass((_value * 1e3) / 1e-6d, MolarMassUnit.MicrogramPerMole), diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index 466c37b449..e8a203a918 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -65,12 +65,14 @@ static Molarity() new UnitInfo(MolarityUnit.CentimolePerLiter, "CentimolesPerLiter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.DecimolePerLiter, "DecimolesPerLiter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.FemtomolePerLiter, "FemtomolesPerLiter", BaseUnits.Undefined), + new UnitInfo(MolarityUnit.KilomolePerCubicMeter, "KilomolesPerCubicMeter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.MicromolePerLiter, "MicromolesPerLiter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.MillimolePerLiter, "MillimolesPerLiter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.MolePerCubicMeter, "MolesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.MolePerLiter, "MolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.NanomolePerLiter, "NanomolesPerLiter", BaseUnits.Undefined), new UnitInfo(MolarityUnit.PicomolePerLiter, "PicomolesPerLiter", BaseUnits.Undefined), + new UnitInfo(MolarityUnit.PoundMolePerCubicFoot, "PoundMolesPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, amount: AmountOfSubstanceUnit.PoundMole)), }, BaseUnit, Zero, BaseDimensions); @@ -189,6 +191,11 @@ public Molarity(double value, UnitSystem unitSystem) /// public double FemtomolesPerLiter => As(MolarityUnit.FemtomolePerLiter); + /// + /// Gets a value of this quantity converted into + /// + public double KilomolesPerCubicMeter => As(MolarityUnit.KilomolePerCubicMeter); + /// /// Gets a value of this quantity converted into /// @@ -219,6 +226,11 @@ public Molarity(double value, UnitSystem unitSystem) /// public double PicomolesPerLiter => As(MolarityUnit.PicomolePerLiter); + /// + /// Gets a value of this quantity converted into + /// + public double PoundMolesPerCubicFoot => As(MolarityUnit.PoundMolePerCubicFoot); + #endregion #region Static Methods @@ -233,11 +245,13 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MolarityUnit.CentimolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.DecimolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.FemtomolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); + unitConverter.SetConversionFunction(MolarityUnit.KilomolePerCubicMeter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.MicromolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.MillimolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.NanomolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.PicomolePerLiter, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); + unitConverter.SetConversionFunction(MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.MolePerCubicMeter)); // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.MolePerCubicMeter, quantity => quantity); @@ -246,11 +260,13 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.CentimolePerLiter, quantity => quantity.ToUnit(MolarityUnit.CentimolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.DecimolePerLiter, quantity => quantity.ToUnit(MolarityUnit.DecimolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.FemtomolePerLiter, quantity => quantity.ToUnit(MolarityUnit.FemtomolePerLiter)); + unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.KilomolePerCubicMeter, quantity => quantity.ToUnit(MolarityUnit.KilomolePerCubicMeter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.MicromolePerLiter, quantity => quantity.ToUnit(MolarityUnit.MicromolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.MillimolePerLiter, quantity => quantity.ToUnit(MolarityUnit.MillimolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.MolePerLiter, quantity => quantity.ToUnit(MolarityUnit.MolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.NanomolePerLiter, quantity => quantity.ToUnit(MolarityUnit.NanomolePerLiter)); unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.PicomolePerLiter, quantity => quantity.ToUnit(MolarityUnit.PicomolePerLiter)); + unitConverter.SetConversionFunction(MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot, quantity => quantity.ToUnit(MolarityUnit.PoundMolePerCubicFoot)); } internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) @@ -258,12 +274,14 @@ internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbrev unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.CentimolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"cmol/L", "cM"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.DecimolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"dmol/L", "dM"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.FemtomolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"fmol/L", "fM"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.KilomolePerCubicMeter, new CultureInfo("en-US"), false, true, new string[]{"kmol/m³"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.MicromolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"µmol/L", "µM"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.MillimolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"mmol/L", "mM"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.MolePerCubicMeter, new CultureInfo("en-US"), false, true, new string[]{"mol/m³"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.MolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"mol/L", "M"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.NanomolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"nmol/L", "nM"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.PicomolePerLiter, new CultureInfo("en-US"), false, true, new string[]{"pmol/L", "pM"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarityUnit.PoundMolePerCubicFoot, new CultureInfo("en-US"), false, true, new string[]{"lbmol/ft³"}); } /// @@ -321,6 +339,16 @@ public static Molarity FromFemtomolesPerLiter(QuantityValue femtomolesperliter) return new Molarity(value, MolarityUnit.FemtomolePerLiter); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Molarity FromKilomolesPerCubicMeter(QuantityValue kilomolespercubicmeter) + { + double value = (double) kilomolespercubicmeter; + return new Molarity(value, MolarityUnit.KilomolePerCubicMeter); + } + /// /// Creates a from . /// @@ -381,6 +409,16 @@ public static Molarity FromPicomolesPerLiter(QuantityValue picomolesperliter) return new Molarity(value, MolarityUnit.PicomolePerLiter); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Molarity FromPoundMolesPerCubicFoot(QuantityValue poundmolespercubicfoot) + { + double value = (double) poundmolespercubicfoot; + return new Molarity(value, MolarityUnit.PoundMolePerCubicFoot); + } + /// /// Dynamically convert from value and unit enum to . /// @@ -850,21 +888,25 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv (MolarityUnit.CentimolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-2d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.DecimolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-1d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.FemtomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-15d, MolarityUnit.MolePerCubicMeter), + (MolarityUnit.KilomolePerCubicMeter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value) * 1e3d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.MicromolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-6d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.MillimolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-3d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.MolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 1e-3, MolarityUnit.MolePerCubicMeter), (MolarityUnit.NanomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-9d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.PicomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-12d, MolarityUnit.MolePerCubicMeter), + (MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 6.242796e-5, MolarityUnit.MolePerCubicMeter), // BaseUnit -> MolarityUnit (MolarityUnit.MolePerCubicMeter, MolarityUnit.CentimolePerLiter) => new Molarity((_value * 1e-3) / 1e-2d, MolarityUnit.CentimolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.DecimolePerLiter) => new Molarity((_value * 1e-3) / 1e-1d, MolarityUnit.DecimolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.FemtomolePerLiter) => new Molarity((_value * 1e-3) / 1e-15d, MolarityUnit.FemtomolePerLiter), + (MolarityUnit.MolePerCubicMeter, MolarityUnit.KilomolePerCubicMeter) => new Molarity((_value) / 1e3d, MolarityUnit.KilomolePerCubicMeter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.MicromolePerLiter) => new Molarity((_value * 1e-3) / 1e-6d, MolarityUnit.MicromolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.MillimolePerLiter) => new Molarity((_value * 1e-3) / 1e-3d, MolarityUnit.MillimolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.MolePerLiter) => new Molarity(_value * 1e-3, MolarityUnit.MolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.NanomolePerLiter) => new Molarity((_value * 1e-3) / 1e-9d, MolarityUnit.NanomolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.PicomolePerLiter) => new Molarity((_value * 1e-3) / 1e-12d, MolarityUnit.PicomolePerLiter), + (MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot) => new Molarity(_value * 6.242796e-5, MolarityUnit.PoundMolePerCubicFoot), _ => null }; diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 43b643c9f2..cf12ec4a83 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -107,6 +107,7 @@ public static partial class Quantity { "MassMomentOfInertia", MassMomentOfInertia.Info }, { "MolarEnergy", MolarEnergy.Info }, { "MolarEntropy", MolarEntropy.Info }, + { "MolarFlow", MolarFlow.Info }, { "Molarity", Molarity.Info }, { "MolarMass", MolarMass.Info }, { "Permeability", Permeability.Info }, @@ -236,6 +237,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "MassMomentOfInertia" => MassMomentOfInertia.From(value, MassMomentOfInertia.BaseUnit), "MolarEnergy" => MolarEnergy.From(value, MolarEnergy.BaseUnit), "MolarEntropy" => MolarEntropy.From(value, MolarEntropy.BaseUnit), + "MolarFlow" => MolarFlow.From(value, MolarFlow.BaseUnit), "Molarity" => Molarity.From(value, Molarity.BaseUnit), "MolarMass" => MolarMass.From(value, MolarMass.BaseUnit), "Permeability" => Permeability.From(value, Permeability.BaseUnit), @@ -508,6 +510,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, [NotNullWhen(true)] o case MolarEntropyUnit molarEntropyUnit: quantity = MolarEntropy.From(value, molarEntropyUnit); return true; + case MolarFlowUnit molarFlowUnit: + quantity = MolarFlow.From(value, molarFlowUnit); + return true; case MolarityUnit molarityUnit: quantity = Molarity.From(value, molarityUnit); return true; @@ -746,6 +751,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(MassMomentOfInertia) => parser.TryParse(quantityString, formatProvider, MassMomentOfInertia.From, out quantity), Type _ when quantityType == typeof(MolarEnergy) => parser.TryParse(quantityString, formatProvider, MolarEnergy.From, out quantity), Type _ when quantityType == typeof(MolarEntropy) => parser.TryParse(quantityString, formatProvider, MolarEntropy.From, out quantity), + Type _ when quantityType == typeof(MolarFlow) => parser.TryParse(quantityString, formatProvider, MolarFlow.From, out quantity), Type _ when quantityType == typeof(Molarity) => parser.TryParse(quantityString, formatProvider, Molarity.From, out quantity), Type _ when quantityType == typeof(MolarMass) => parser.TryParse(quantityString, formatProvider, MolarMass.From, out quantity), Type _ when quantityType == typeof(Permeability) => parser.TryParse(quantityString, formatProvider, Permeability.From, out quantity), @@ -869,6 +875,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(MassMomentOfInertia); yield return typeof(MolarEnergy); yield return typeof(MolarEntropy); + yield return typeof(MolarFlow); yield return typeof(Molarity); yield return typeof(MolarMass); yield return typeof(Permeability); diff --git a/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs new file mode 100644 index 0000000000..c58c44ea9e --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 MolarFlowUnit + { + KilomolePerHour = 2, + KilomolePerMinute = 15, + KilomolePerSecond = 12, + PoundMolePerHour = 6, + PoundMolePerMinute = 7, + PoundMolePerSecond = 4, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs index 417075c855..4be43903ef 100644 --- a/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs @@ -30,6 +30,7 @@ public enum MolarMassUnit DecigramPerMole = 3, GramPerMole = 4, HectogramPerMole = 5, + KilogramPerKilomole = 15, KilogramPerMole = 6, KilopoundPerMole = 7, MegapoundPerMole = 8, diff --git a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs index 3119352a47..d9c7972422 100644 --- a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,12 +28,14 @@ public enum MolarityUnit CentimolePerLiter = 1, DecimolePerLiter = 3, FemtomolePerLiter = 5, + KilomolePerCubicMeter = 25, MicromolePerLiter = 6, MillimolePerLiter = 8, MolePerCubicMeter = 10, MolePerLiter = 11, NanomolePerLiter = 14, PicomolePerLiter = 16, + PoundMolePerCubicFoot = 18, } #pragma warning restore 1591 From 7030b55c41927705c8c34602daf7c7422c352f30 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Thu, 9 Feb 2023 10:10:38 -0500 Subject: [PATCH 2/8] Overload operator for MolarFlow / Molarity = VolumeFlow --- UnitsNet.Tests/CustomCode/MolarFlowTests.cs | 7 +++++++ UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs index 232d4e67a1..c54e40959a 100644 --- a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs @@ -61,5 +61,12 @@ public void MolarFlowTimesMolarMassEqualsMassFlow() Assert.Equal(MassFlow.FromKilogramsPerSecond(6), massFlow); } + [Fact] + public void MolarFlowOverMolarityEqualsVolumeFlow() + { + VolumeFlow volumeFlow = MolarFlow.FromKilomolesPerSecond(6) / Molarity.FromKilomolesPerCubicMeter(3); + Assert.Equal(VolumeFlow.FromCubicMetersPerSecond(2), volumeFlow); + } + } } diff --git a/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs b/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs index a6b58b2d9b..9a69147ce3 100644 --- a/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs +++ b/UnitsNet/CustomCode/Quantities/MolarFlow.extra.cs @@ -22,5 +22,11 @@ public partial struct MolarFlow return MassFlow.FromKilogramsPerSecond(molarFlow.KilomolesPerSecond * molecularWeight.KilogramsPerKilomole); } + /// Get from divided by . + public static VolumeFlow operator /(MolarFlow molarFlow, Molarity molarity) + { + return VolumeFlow.FromCubicMetersPerSecond(molarFlow.KilomolesPerSecond / molarity.KilomolesPerCubicMeter); + } + } } From 907a83593c5cb21572b8bdb5acb0b2b03cb65922 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Sat, 11 Feb 2023 00:30:50 -0500 Subject: [PATCH 3/8] Changes requested + HTC fix --- .../HeatTransferCoefficient.json | 18 +- Common/UnitDefinitions/MolarFlow.json | 53 +-- Common/UnitDefinitions/Molarity.json | 4 +- Common/UnitEnumValues.g.json | 9 +- .../Quantities/HeatTransferCoefficient.g.cs | 25 +- .../GeneratedCode/Quantities/MolarFlow.g.cs | 77 +++- .../GeneratedCode/Quantities/Molarity.g.cs | 4 +- .../Units/HeatTransferCoefficientUnit.g.cs | 3 +- .../GeneratedCode/Units/MolarFlowUnit.g.cs | 3 + ...HeatTransferCoefficientExtensionsTest.g.cs | 8 +- .../NumberToMolarFlowExtensionsTest.g.cs | 24 +- ...erToHeatTransferCoefficientExtensions.g.cs | 10 +- .../NumberToMolarFlowExtensions.g.cs | 30 +- .../HeatTransferCoefficientTests.cs | 3 +- UnitsNet.Tests/CustomCode/MolarFlowTests.cs | 20 +- .../HeatTransferCoefficientTestsBase.g.cs | 233 +++++++++-- .../TestsBase/MolarFlowTestsBase.g.cs | 391 +++++++++++------- .../Quantities/HeatTransferCoefficient.g.cs | 45 +- .../GeneratedCode/Quantities/MolarFlow.g.cs | 145 +++++-- .../GeneratedCode/Quantities/Molarity.g.cs | 4 +- .../Units/HeatTransferCoefficientUnit.g.cs | 3 +- .../GeneratedCode/Units/MolarFlowUnit.g.cs | 3 + 22 files changed, 805 insertions(+), 310 deletions(-) diff --git a/Common/UnitDefinitions/HeatTransferCoefficient.json b/Common/UnitDefinitions/HeatTransferCoefficient.json index 4e6e82abd1..a953d733b3 100644 --- a/Common/UnitDefinitions/HeatTransferCoefficient.json +++ b/Common/UnitDefinitions/HeatTransferCoefficient.json @@ -33,14 +33,26 @@ ] }, { - "SingularName": "BtuPerSquareFootDegreeFahrenheit", - "PluralName": "BtusPerSquareFootDegreeFahrenheit", + "SingularName": "BtuPerHourSquareFootDegreeFahrenheit", + "PluralName": "BtusPerHourSquareFootDegreeFahrenheit", "FromUnitToBaseFunc": "{x} * 5.6782633411134878", "FromBaseToUnitFunc": "{x} / 5.6782633411134878", "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "Btu/ft²·hr·°F" ] + "Abbreviations": [ "Btu/h·ft²·°F", "Btu/ft²·h·°F", "Btu/hr·ft²·°F", "Btu/ft²·hr·°F" ] + } + ] + }, + { + "SingularName": "KilocaloriePerHourSquareMeterDegreeCelsius", + "PluralName": "KilocaloriesPerHourSquareMeterDegreeCelsius", + "FromUnitToBaseFunc": "({x} * 4184) / 3600", + "FromBaseToUnitFunc": "({x} / 4184) * 3600", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kcal/h·m²·°C", "kcal/m²·h·°C", "kcal/hr·m²·°C", "kcal/m²·hr·°C" ] } ] } diff --git a/Common/UnitDefinitions/MolarFlow.json b/Common/UnitDefinitions/MolarFlow.json index c56d2b2bf5..e9d90d51e4 100644 --- a/Common/UnitDefinitions/MolarFlow.json +++ b/Common/UnitDefinitions/MolarFlow.json @@ -1,6 +1,6 @@ { "Name": "MolarFlow", - "BaseUnit": "KilomolePerSecond", + "BaseUnit": "MolePerSecond", "XmlDocSummary": "Molar flow is the ratio of the amount of substance change to the time during which the change occurred (value of amount of substance changes per unit time).", "BaseDimensions": { "N": 1, @@ -8,46 +8,49 @@ }, "Units": [ { - "SingularName": "KilomolePerSecond", - "PluralName": "KilomolesPerSecond", + "SingularName": "MolePerSecond", + "PluralName": "MolesPerSecond", "BaseUnits": { - "N": "Kilomole", + "N": "Mole", "T": "Second" }, + "Prefixes": [ "Kilo" ], "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "kmol/s" ] + "Abbreviations": [ "mol/s" ] } ] }, { - "SingularName": "KilomolePerMinute", - "PluralName": "KilomolesPerMinute", + "SingularName": "MolePerMinute", + "PluralName": "MolesPerMinute", "BaseUnits": { - "N": "Kilomole", + "N": "Mole", "T": "Minute" }, - "FromUnitToBaseFunc": "{x} / 5.999988e1", - "FromBaseToUnitFunc": "{x} * 5.999988e1", + "Prefixes": [ "Kilo" ], + "FromUnitToBaseFunc": "{x} / 60", + "FromBaseToUnitFunc": "{x} * 60", "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "kmol/min" ] + "Abbreviations": [ "mol/min" ] } ] }, { - "SingularName": "KilomolePerHour", - "PluralName": "KilomolesPerHour", + "SingularName": "MolePerHour", + "PluralName": "MolesPerHour", "BaseUnits": { - "N": "Kilomole", + "N": "Mole", "T": "Hour" }, - "FromUnitToBaseFunc": "{x} / 3.599997e3", - "FromBaseToUnitFunc": "{x} * 3.599997e3", + "Prefixes": [ "Kilo" ], + "FromUnitToBaseFunc": "{x} / 3600", + "FromBaseToUnitFunc": "{x} * 3600", "Localization": [ { "Culture": "en-US", @@ -57,13 +60,13 @@ }, { "SingularName": "PoundMolePerSecond", - "PluralName": "PoundsMolePerSecond", + "PluralName": "PoundMolesPerSecond", "BaseUnits": { "N": "PoundMole", "T": "Second" }, - "FromUnitToBaseFunc": "{x} / 2.2046244201838", - "FromBaseToUnitFunc": "{x} * 2.2046244201838", + "FromUnitToBaseFunc": "{x} * 453.59237", + "FromBaseToUnitFunc": "{x} / 453.59237", "Localization": [ { "Culture": "en-US", @@ -73,13 +76,13 @@ }, { "SingularName": "PoundMolePerMinute", - "PluralName": "PoundsMolePerMinute", + "PluralName": "PoundMolesPerMinute", "BaseUnits": { "N": "PoundMole", "T": "Minute" }, - "FromUnitToBaseFunc": "{x} / 1.32277406886626e2", - "FromBaseToUnitFunc": "{x} * 1.32277406886626e2", + "FromUnitToBaseFunc": "({x} * 453.59237) / 60", + "FromBaseToUnitFunc": "({x} / 453.59237) * 60", "Localization": [ { "Culture": "en-US", @@ -89,13 +92,13 @@ }, { "SingularName": "PoundMolePerHour", - "PluralName": "PoundsMolePerHour", + "PluralName": "PoundMolesPerHour", "BaseUnits": { "N": "PoundMole", "T": "Hour" }, - "FromUnitToBaseFunc": "{x} / 7.93663391482404e3", - "FromBaseToUnitFunc": "{x} * 7.93663391482404e3", + "FromUnitToBaseFunc": "({x} * 453.59237) / 3600", + "FromBaseToUnitFunc": "({x} / 453.59237) * 3600", "Localization": [ { "Culture": "en-US", diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index 806734424c..5914a0c048 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -49,8 +49,8 @@ "L": "Foot", "N": "PoundMole" }, - "FromUnitToBaseFunc": "{x} / 6.242796e-5", - "FromBaseToUnitFunc": "{x} * 6.242796e-5", + "FromUnitToBaseFunc": "{x} * 6.2427960576144611956325455827221e-5", + "FromBaseToUnitFunc": "{x} / 6.2427960576144611956325455827221e-5", "Localization": [ { "Culture": "en-US", diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 071cda7cfa..aa207afb46 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -537,7 +537,9 @@ "HeatTransferCoefficient": { "BtuPerSquareFootDegreeFahrenheit": 1, "WattPerSquareMeterCelsius": 2, - "WattPerSquareMeterKelvin": 3 + "WattPerSquareMeterKelvin": 3, + "BtuPerHourSquareFootDegreeFahrenheit": 11, + "KilocaloriePerHourSquareMeterDegreeCelsius": 8 }, "Illuminance": { "Kilolux": 1, @@ -1705,6 +1707,9 @@ "PoundMolePerSecond": 4, "KilomolePerHour": 2, "KilomolePerMinute": 15, - "KilomolePerSecond": 12 + "KilomolePerSecond": 12, + "MolePerHour": 8, + "MolePerMinute": 18, + "MolePerSecond": 3 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index b658044414..cb0857d30a 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -80,9 +80,14 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) #region Conversion Properties /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public double BtusPerSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + public double BtusPerHourSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + + /// + /// Gets a value of this quantity converted into + /// + public double KilocaloriesPerHourSquareMeterDegreeCelsius => As(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); /// /// Gets a value of this quantity converted into @@ -99,10 +104,16 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) #region Static Factory Methods /// - /// Creates a from . + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static HeatTransferCoefficient FromBtusPerHourSquareFootDegreeFahrenheit(double btusperhoursquarefootdegreefahrenheit) => new HeatTransferCoefficient(btusperhoursquarefootdegreefahrenheit, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + + /// + /// Creates a from . /// /// If value is NaN or Infinity. - public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(double btuspersquarefootdegreefahrenheit) => new HeatTransferCoefficient(btuspersquarefootdegreefahrenheit, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + public static HeatTransferCoefficient FromKilocaloriesPerHourSquareMeterDegreeCelsius(double kilocaloriesperhoursquaremeterdegreecelsius) => new HeatTransferCoefficient(kilocaloriesperhoursquaremeterdegreecelsius, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); /// /// Creates a from . @@ -156,7 +167,8 @@ private double GetValueInBaseUnit() { return Unit switch { - HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => _value * 5.6782633411134878, + HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => _value * 5.6782633411134878, + HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (_value * 4184) / 3600, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => _value, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => _value, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") @@ -172,7 +184,8 @@ private double GetValueAs(HeatTransferCoefficientUnit unit) return unit switch { - HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => baseUnitValue / 5.6782633411134878, + HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => baseUnitValue / 5.6782633411134878, + HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (baseUnitValue / 4184) * 3600, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => baseUnitValue, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => baseUnitValue, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs index 9eac852d38..387d2fdb60 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/MolarFlow.g.cs @@ -61,7 +61,7 @@ public MolarFlow(double value, MolarFlowUnit unit) /// /// The base unit of Duration, which is Second. All conversions go via this value. /// - public static MolarFlowUnit BaseUnit { get; } = MolarFlowUnit.KilomolePerSecond; + public static MolarFlowUnit BaseUnit { get; } = MolarFlowUnit.MolePerSecond; /// /// Represents the largest possible value of Duration @@ -94,20 +94,35 @@ public MolarFlow(double value, MolarFlowUnit unit) /// public double KilomolesPerSecond => As(MolarFlowUnit.KilomolePerSecond); + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerHour => As(MolarFlowUnit.MolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerMinute => As(MolarFlowUnit.MolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerSecond => As(MolarFlowUnit.MolePerSecond); + /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerHour => As(MolarFlowUnit.PoundMolePerHour); + public double PoundMolesPerHour => As(MolarFlowUnit.PoundMolePerHour); /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerMinute => As(MolarFlowUnit.PoundMolePerMinute); + public double PoundMolesPerMinute => As(MolarFlowUnit.PoundMolePerMinute); /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerSecond => As(MolarFlowUnit.PoundMolePerSecond); + public double PoundMolesPerSecond => As(MolarFlowUnit.PoundMolePerSecond); #endregion @@ -131,23 +146,41 @@ public MolarFlow(double value, MolarFlowUnit unit) /// If value is NaN or Infinity. public static MolarFlow FromKilomolesPerSecond(double kilomolespersecond) => new MolarFlow(kilomolespersecond, MolarFlowUnit.KilomolePerSecond); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerHour(double molesperhour) => new MolarFlow(molesperhour, MolarFlowUnit.MolePerHour); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerMinute(double molesperminute) => new MolarFlow(molesperminute, MolarFlowUnit.MolePerMinute); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerSecond(double molespersecond) => new MolarFlow(molespersecond, MolarFlowUnit.MolePerSecond); + /// /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerHour(double poundsmoleperhour) => new MolarFlow(poundsmoleperhour, MolarFlowUnit.PoundMolePerHour); + public static MolarFlow FromPoundMolesPerHour(double poundmolesperhour) => new MolarFlow(poundmolesperhour, MolarFlowUnit.PoundMolePerHour); /// /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerMinute(double poundsmoleperminute) => new MolarFlow(poundsmoleperminute, MolarFlowUnit.PoundMolePerMinute); + public static MolarFlow FromPoundMolesPerMinute(double poundmolesperminute) => new MolarFlow(poundmolesperminute, MolarFlowUnit.PoundMolePerMinute); /// /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerSecond(double poundsmolepersecond) => new MolarFlow(poundsmolepersecond, MolarFlowUnit.PoundMolePerSecond); + public static MolarFlow FromPoundMolesPerSecond(double poundmolespersecond) => new MolarFlow(poundmolespersecond, MolarFlowUnit.PoundMolePerSecond); /// /// Dynamically convert from value and unit enum to . @@ -189,12 +222,15 @@ private double GetValueInBaseUnit() { return Unit switch { - MolarFlowUnit.KilomolePerHour => _value / 3.599997e3, - MolarFlowUnit.KilomolePerMinute => _value / 5.999988e1, - MolarFlowUnit.KilomolePerSecond => _value, - MolarFlowUnit.PoundMolePerHour => _value / 7.93663391482404e3, - MolarFlowUnit.PoundMolePerMinute => _value / 1.32277406886626e2, - MolarFlowUnit.PoundMolePerSecond => _value / 2.2046244201838, + MolarFlowUnit.KilomolePerHour => (_value / 3600) * 1e3d, + MolarFlowUnit.KilomolePerMinute => (_value / 60) * 1e3d, + MolarFlowUnit.KilomolePerSecond => (_value) * 1e3d, + MolarFlowUnit.MolePerHour => _value / 3600, + MolarFlowUnit.MolePerMinute => _value / 60, + MolarFlowUnit.MolePerSecond => _value, + MolarFlowUnit.PoundMolePerHour => (_value * 453.59237) / 3600, + MolarFlowUnit.PoundMolePerMinute => (_value * 453.59237) / 60, + MolarFlowUnit.PoundMolePerSecond => _value * 453.59237, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -208,12 +244,15 @@ private double GetValueAs(MolarFlowUnit unit) return unit switch { - MolarFlowUnit.KilomolePerHour => baseUnitValue * 3.599997e3, - MolarFlowUnit.KilomolePerMinute => baseUnitValue * 5.999988e1, - MolarFlowUnit.KilomolePerSecond => baseUnitValue, - MolarFlowUnit.PoundMolePerHour => baseUnitValue * 7.93663391482404e3, - MolarFlowUnit.PoundMolePerMinute => baseUnitValue * 1.32277406886626e2, - MolarFlowUnit.PoundMolePerSecond => baseUnitValue * 2.2046244201838, + MolarFlowUnit.KilomolePerHour => (baseUnitValue * 3600) / 1e3d, + MolarFlowUnit.KilomolePerMinute => (baseUnitValue * 60) / 1e3d, + MolarFlowUnit.KilomolePerSecond => (baseUnitValue) / 1e3d, + MolarFlowUnit.MolePerHour => baseUnitValue * 3600, + MolarFlowUnit.MolePerMinute => baseUnitValue * 60, + MolarFlowUnit.MolePerSecond => baseUnitValue, + MolarFlowUnit.PoundMolePerHour => (baseUnitValue / 453.59237) * 3600, + MolarFlowUnit.PoundMolePerMinute => (baseUnitValue / 453.59237) * 60, + MolarFlowUnit.PoundMolePerSecond => baseUnitValue / 453.59237, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs index 533d58a67d..51fffbc3eb 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs @@ -257,7 +257,7 @@ private double GetValueInBaseUnit() MolarityUnit.MolePerLiter => _value / 1e-3, MolarityUnit.NanomolePerLiter => (_value / 1e-3) * 1e-9d, MolarityUnit.PicomolePerLiter => (_value / 1e-3) * 1e-12d, - MolarityUnit.PoundMolePerCubicFoot => _value / 6.242796e-5, + MolarityUnit.PoundMolePerCubicFoot => _value * 6.2427960576144611956325455827221e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -281,7 +281,7 @@ private double GetValueAs(MolarityUnit unit) MolarityUnit.MolePerLiter => baseUnitValue * 1e-3, MolarityUnit.NanomolePerLiter => (baseUnitValue * 1e-3) / 1e-9d, MolarityUnit.PicomolePerLiter => (baseUnitValue * 1e-3) / 1e-12d, - MolarityUnit.PoundMolePerCubicFoot => baseUnitValue * 6.242796e-5, + MolarityUnit.PoundMolePerCubicFoot => baseUnitValue / 6.2427960576144611956325455827221e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index e337b5095a..d19a94cb83 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -25,7 +25,8 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { - BtuPerSquareFootDegreeFahrenheit = 1, + BtuPerHourSquareFootDegreeFahrenheit = 11, + KilocaloriePerHourSquareMeterDegreeCelsius = 8, WattPerSquareMeterCelsius = 2, WattPerSquareMeterKelvin = 3, } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs index c58c44ea9e..48bc201810 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/MolarFlowUnit.g.cs @@ -28,6 +28,9 @@ public enum MolarFlowUnit KilomolePerHour = 2, KilomolePerMinute = 15, KilomolePerSecond = 12, + MolePerHour = 8, + MolePerMinute = 18, + MolePerSecond = 3, PoundMolePerHour = 6, PoundMolePerMinute = 7, PoundMolePerSecond = 4, diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs index c252afd20e..3eecd7afbd 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs @@ -25,8 +25,12 @@ namespace UnitsNet.Tests public class NumberToHeatTransferCoefficientExtensionsTests { [Fact] - public void NumberToBtusPerSquareFootDegreeFahrenheitTest() => - Assert.Equal(HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(2), 2.BtusPerSquareFootDegreeFahrenheit()); + public void NumberToBtusPerHourSquareFootDegreeFahrenheitTest() => + Assert.Equal(HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(2), 2.BtusPerHourSquareFootDegreeFahrenheit()); + + [Fact] + public void NumberToKilocaloriesPerHourSquareMeterDegreeCelsiusTest() => + Assert.Equal(HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(2), 2.KilocaloriesPerHourSquareMeterDegreeCelsius()); [Fact] public void NumberToWattsPerSquareMeterCelsiusTest() => diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs index 29e576da4c..3a4f360973 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMolarFlowExtensionsTest.g.cs @@ -37,16 +37,28 @@ public void NumberToKilomolesPerSecondTest() => Assert.Equal(MolarFlow.FromKilomolesPerSecond(2), 2.KilomolesPerSecond()); [Fact] - public void NumberToPoundsMolePerHourTest() => - Assert.Equal(MolarFlow.FromPoundsMolePerHour(2), 2.PoundsMolePerHour()); + public void NumberToMolesPerHourTest() => + Assert.Equal(MolarFlow.FromMolesPerHour(2), 2.MolesPerHour()); [Fact] - public void NumberToPoundsMolePerMinuteTest() => - Assert.Equal(MolarFlow.FromPoundsMolePerMinute(2), 2.PoundsMolePerMinute()); + public void NumberToMolesPerMinuteTest() => + Assert.Equal(MolarFlow.FromMolesPerMinute(2), 2.MolesPerMinute()); [Fact] - public void NumberToPoundsMolePerSecondTest() => - Assert.Equal(MolarFlow.FromPoundsMolePerSecond(2), 2.PoundsMolePerSecond()); + public void NumberToMolesPerSecondTest() => + Assert.Equal(MolarFlow.FromMolesPerSecond(2), 2.MolesPerSecond()); + + [Fact] + public void NumberToPoundMolesPerHourTest() => + Assert.Equal(MolarFlow.FromPoundMolesPerHour(2), 2.PoundMolesPerHour()); + + [Fact] + public void NumberToPoundMolesPerMinuteTest() => + Assert.Equal(MolarFlow.FromPoundMolesPerMinute(2), 2.PoundMolesPerMinute()); + + [Fact] + public void NumberToPoundMolesPerSecondTest() => + Assert.Equal(MolarFlow.FromPoundMolesPerSecond(2), 2.PoundMolesPerSecond()); } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs index d03e2febe0..9664bdd902 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs @@ -28,9 +28,13 @@ namespace UnitsNet.NumberExtensions.NumberToHeatTransferCoefficient /// public static class NumberToHeatTransferCoefficientExtensions { - /// - public static HeatTransferCoefficient BtusPerSquareFootDegreeFahrenheit(this T value) => - HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(Convert.ToDouble(value)); + /// + public static HeatTransferCoefficient BtusPerHourSquareFootDegreeFahrenheit(this T value) => + HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(Convert.ToDouble(value)); + + /// + public static HeatTransferCoefficient KilocaloriesPerHourSquareMeterDegreeCelsius(this T value) => + HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(Convert.ToDouble(value)); /// public static HeatTransferCoefficient WattsPerSquareMeterCelsius(this T value) => diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs index 91227f1b49..1dcdca6bbc 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMolarFlowExtensions.g.cs @@ -40,17 +40,29 @@ public static MolarFlow KilomolesPerMinute(this T value) => public static MolarFlow KilomolesPerSecond(this T value) => MolarFlow.FromKilomolesPerSecond(Convert.ToDouble(value)); - /// - public static MolarFlow PoundsMolePerHour(this T value) => - MolarFlow.FromPoundsMolePerHour(Convert.ToDouble(value)); + /// + public static MolarFlow MolesPerHour(this T value) => + MolarFlow.FromMolesPerHour(Convert.ToDouble(value)); - /// - public static MolarFlow PoundsMolePerMinute(this T value) => - MolarFlow.FromPoundsMolePerMinute(Convert.ToDouble(value)); + /// + public static MolarFlow MolesPerMinute(this T value) => + MolarFlow.FromMolesPerMinute(Convert.ToDouble(value)); - /// - public static MolarFlow PoundsMolePerSecond(this T value) => - MolarFlow.FromPoundsMolePerSecond(Convert.ToDouble(value)); + /// + public static MolarFlow MolesPerSecond(this T value) => + MolarFlow.FromMolesPerSecond(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundMolesPerHour(this T value) => + MolarFlow.FromPoundMolesPerHour(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundMolesPerMinute(this T value) => + MolarFlow.FromPoundMolesPerMinute(Convert.ToDouble(value)); + + /// + public static MolarFlow PoundMolesPerSecond(this T value) => + MolarFlow.FromPoundMolesPerSecond(Convert.ToDouble(value)); } } diff --git a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs index 4e07e9c612..fa31819c61 100644 --- a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs +++ b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs @@ -30,6 +30,7 @@ public class HeatTransferCoefficientTests : HeatTransferCoefficientTestsBase protected override bool SupportsSIUnitSystem => false; protected override double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin => 1; protected override double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin => 1; - protected override double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin => 1.7611018368230584e-1; + protected override double BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin => 1.7611018368230584e-1; + protected override double KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin => 8.6042065009560229e-1; } } diff --git a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs index c54e40959a..66288f3915 100644 --- a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs @@ -26,19 +26,25 @@ namespace UnitsNet.Tests.CustomCode public class MolarFlowTests : MolarFlowTestsBase { // Override properties in base class here - protected override bool SupportsSIUnitSystem => false; + protected override bool SupportsSIUnitSystem => true; - protected override double KilomolesPerHourInOneKilomolePerSecond => 3.599997e3; + protected override double KilomolesPerHourInOneMolePerSecond => 3.6; - protected override double KilomolesPerMinuteInOneKilomolePerSecond => 5.999988e1; + protected override double KilomolesPerMinuteInOneMolePerSecond => 0.06; - protected override double KilomolesPerSecondInOneKilomolePerSecond => 1.0; + protected override double KilomolesPerSecondInOneMolePerSecond => 0.001; - protected override double PoundsMolePerHourInOneKilomolePerSecond => 7.93663391482404e3; + protected override double PoundMolesPerHourInOneMolePerSecond => 7.93664143866; - protected override double PoundsMolePerMinuteInOneKilomolePerSecond => 1.32277406886626e2; + protected override double PoundMolesPerMinuteInOneMolePerSecond => 0.132277357311; - protected override double PoundsMolePerSecondInOneKilomolePerSecond => 2.2046244201838; + protected override double PoundMolesPerSecondInOneMolePerSecond => 2.204622621848e-3; + + protected override double MolesPerHourInOneMolePerSecond => 3600; + + protected override double MolesPerMinuteInOneMolePerSecond => 60; + + protected override double MolesPerSecondInOneMolePerSecond => 1.0; [Fact] public void MolarFlowTimesTimeSpanEqualsAmountOfSubstance() diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index 18d97a32b2..2dec850615 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -38,12 +38,14 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBase { - protected abstract double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin { get; } + protected abstract double BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin { get; } + protected abstract double KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin { get; } protected abstract double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin { get; } protected abstract double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin { get; } // ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BtusPerSquareFootDegreeFahrenheitTolerance { get { return 1e-5; } } + protected virtual double BtusPerHourSquareFootDegreeFahrenheitTolerance { get { return 1e-5; } } + protected virtual double KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance { get { return 1e-5; } } protected virtual double WattsPerSquareMeterCelsiusTolerance { get { return 1e-5; } } protected virtual double WattsPerSquareMeterKelvinTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -52,7 +54,8 @@ public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBa { return unit switch { - HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => (BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, BtusPerSquareFootDegreeFahrenheitTolerance), + HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => (BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, BtusPerHourSquareFootDegreeFahrenheitTolerance), + HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance), HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => (WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, WattsPerSquareMeterCelsiusTolerance), HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => (WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance), _ => throw new NotSupportedException() @@ -61,7 +64,8 @@ public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBa public static IEnumerable UnitTypes = new List { - new object[] { HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit }, + new object[] { HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit }, + new object[] { HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius }, new object[] { HeatTransferCoefficientUnit.WattPerSquareMeterCelsius }, new object[] { HeatTransferCoefficientUnit.WattPerSquareMeterKelvin }, }; @@ -126,7 +130,8 @@ public void HeatTransferCoefficient_QuantityInfo_ReturnsQuantityInfoDescribingQu public void WattPerSquareMeterKelvinToHeatTransferCoefficientUnits() { HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); } @@ -134,17 +139,21 @@ public void WattPerSquareMeterKelvinToHeatTransferCoefficientUnits() [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); - AssertEx.EqualTolerance(1, quantity00.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, quantity00.Unit); + var quantity00 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + AssertEx.EqualTolerance(1, quantity00.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, quantity00.Unit); - var quantity01 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius); - AssertEx.EqualTolerance(1, quantity01.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity01.Unit); + var quantity01 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); + AssertEx.EqualTolerance(1, quantity01.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, quantity01.Unit); - var quantity02 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin); - AssertEx.EqualTolerance(1, quantity02.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity02.Unit); + var quantity02 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius); + AssertEx.EqualTolerance(1, quantity02.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity02.Unit); + + var quantity03 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin); + AssertEx.EqualTolerance(1, quantity03.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); + Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity03.Unit); } @@ -165,7 +174,8 @@ public void FromWattsPerSquareMeterKelvin_WithNanValue_ThrowsArgumentException() public void As() { var wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit), BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit), BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius), KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius), WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), WattsPerSquareMeterKelvinTolerance); } @@ -190,11 +200,60 @@ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void Parse() { + try + { + var parsed = HeatTransferCoefficient.Parse("1 Btu/h·ft²·°F", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 Btu/ft²·h·°F", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 Btu/hr·ft²·°F", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = HeatTransferCoefficient.Parse("1 Btu/ft²·hr·°F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, parsed.Unit); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try @@ -216,10 +275,52 @@ public void Parse() [Fact] public void TryParse() { + { + Assert.True(HeatTransferCoefficient.TryParse("1 Btu/h·ft²·°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 Btu/ft²·h·°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 Btu/hr·ft²·°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } + { Assert.True(HeatTransferCoefficient.TryParse("1 Btu/ft²·hr·°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, parsed.Unit); + AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } { @@ -239,10 +340,52 @@ public void TryParse() [Fact] public void ParseUnit() { + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/h·ft²·°F", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/ft²·h·°F", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/hr·ft²·°F", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/ft²·hr·°F", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try @@ -262,9 +405,44 @@ public void ParseUnit() [Fact] public void TryParseUnit() { + { + Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/h·ft²·°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/ft²·h·°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/hr·ft²·°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } + { Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/ft²·hr·°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } { @@ -325,7 +503,8 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Heat public void ConversionRoundTrip() { HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(wattpersquaremeterkelvin.BtusPerSquareFootDegreeFahrenheit).WattsPerSquareMeterKelvin, BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(wattpersquaremeterkelvin.BtusPerHourSquareFootDegreeFahrenheit).WattsPerSquareMeterKelvin, BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(wattpersquaremeterkelvin.KilocaloriesPerHourSquareMeterDegreeCelsius).WattsPerSquareMeterKelvin, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterCelsius(wattpersquaremeterkelvin.WattsPerSquareMeterCelsius).WattsPerSquareMeterKelvin, WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(wattpersquaremeterkelvin.WattsPerSquareMeterKelvin).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); } @@ -386,8 +565,8 @@ public void CompareToThrowsOnNull() [Theory] [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, true)] // Same value and unit. [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 2, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, false)] // Different value. - [InlineData(2, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, false)] // Different value and unit. - [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, false)] // Different unit. + [InlineData(2, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, false)] // Different value and unit. + [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, false)] // Different unit. public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, HeatTransferCoefficientUnit unitA, double valueB, HeatTransferCoefficientUnit unitB, bool expectEqual) { var a = new HeatTransferCoefficient(valueA, unitA); @@ -475,7 +654,8 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { - Assert.Equal("1 Btu/ft²·hr·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit).ToString()); + Assert.Equal("1 Btu/h·ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit).ToString()); + Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString()); Assert.Equal("1 W/m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius).ToString()); Assert.Equal("1 W/m²·K", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin).ToString()); } @@ -491,7 +671,8 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 Btu/ft²·hr·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit).ToString(swedishCulture)); + Assert.Equal("1 Btu/h·ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit).ToString(swedishCulture)); + Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString(swedishCulture)); Assert.Equal("1 W/m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius).ToString(swedishCulture)); Assert.Equal("1 W/m²·K", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin).ToString(swedishCulture)); } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index 03a6024103..0f74380ec4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -38,32 +38,41 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class MolarFlowTestsBase : QuantityTestsBase { - protected abstract double KilomolesPerHourInOneKilomolePerSecond { get; } - protected abstract double KilomolesPerMinuteInOneKilomolePerSecond { get; } - protected abstract double KilomolesPerSecondInOneKilomolePerSecond { get; } - protected abstract double PoundsMolePerHourInOneKilomolePerSecond { get; } - protected abstract double PoundsMolePerMinuteInOneKilomolePerSecond { get; } - protected abstract double PoundsMolePerSecondInOneKilomolePerSecond { get; } + protected abstract double KilomolesPerHourInOneMolePerSecond { get; } + protected abstract double KilomolesPerMinuteInOneMolePerSecond { get; } + protected abstract double KilomolesPerSecondInOneMolePerSecond { get; } + protected abstract double MolesPerHourInOneMolePerSecond { get; } + protected abstract double MolesPerMinuteInOneMolePerSecond { get; } + protected abstract double MolesPerSecondInOneMolePerSecond { get; } + protected abstract double PoundMolesPerHourInOneMolePerSecond { get; } + protected abstract double PoundMolesPerMinuteInOneMolePerSecond { get; } + protected abstract double PoundMolesPerSecondInOneMolePerSecond { get; } // ReSharper disable VirtualMemberNeverOverriden.Global protected virtual double KilomolesPerHourTolerance { get { return 1e-5; } } protected virtual double KilomolesPerMinuteTolerance { get { return 1e-5; } } protected virtual double KilomolesPerSecondTolerance { get { return 1e-5; } } - protected virtual double PoundsMolePerHourTolerance { get { return 1e-5; } } - protected virtual double PoundsMolePerMinuteTolerance { get { return 1e-5; } } - protected virtual double PoundsMolePerSecondTolerance { get { return 1e-5; } } + protected virtual double MolesPerHourTolerance { get { return 1e-5; } } + protected virtual double MolesPerMinuteTolerance { get { return 1e-5; } } + protected virtual double MolesPerSecondTolerance { get { return 1e-5; } } + protected virtual double PoundMolesPerHourTolerance { get { return 1e-5; } } + protected virtual double PoundMolesPerMinuteTolerance { get { return 1e-5; } } + protected virtual double PoundMolesPerSecondTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(MolarFlowUnit unit) { return unit switch { - MolarFlowUnit.KilomolePerHour => (KilomolesPerHourInOneKilomolePerSecond, KilomolesPerHourTolerance), - MolarFlowUnit.KilomolePerMinute => (KilomolesPerMinuteInOneKilomolePerSecond, KilomolesPerMinuteTolerance), - MolarFlowUnit.KilomolePerSecond => (KilomolesPerSecondInOneKilomolePerSecond, KilomolesPerSecondTolerance), - MolarFlowUnit.PoundMolePerHour => (PoundsMolePerHourInOneKilomolePerSecond, PoundsMolePerHourTolerance), - MolarFlowUnit.PoundMolePerMinute => (PoundsMolePerMinuteInOneKilomolePerSecond, PoundsMolePerMinuteTolerance), - MolarFlowUnit.PoundMolePerSecond => (PoundsMolePerSecondInOneKilomolePerSecond, PoundsMolePerSecondTolerance), + MolarFlowUnit.KilomolePerHour => (KilomolesPerHourInOneMolePerSecond, KilomolesPerHourTolerance), + MolarFlowUnit.KilomolePerMinute => (KilomolesPerMinuteInOneMolePerSecond, KilomolesPerMinuteTolerance), + MolarFlowUnit.KilomolePerSecond => (KilomolesPerSecondInOneMolePerSecond, KilomolesPerSecondTolerance), + MolarFlowUnit.MolePerHour => (MolesPerHourInOneMolePerSecond, MolesPerHourTolerance), + MolarFlowUnit.MolePerMinute => (MolesPerMinuteInOneMolePerSecond, MolesPerMinuteTolerance), + MolarFlowUnit.MolePerSecond => (MolesPerSecondInOneMolePerSecond, MolesPerSecondTolerance), + MolarFlowUnit.PoundMolePerHour => (PoundMolesPerHourInOneMolePerSecond, PoundMolesPerHourTolerance), + MolarFlowUnit.PoundMolePerMinute => (PoundMolesPerMinuteInOneMolePerSecond, PoundMolesPerMinuteTolerance), + MolarFlowUnit.PoundMolePerSecond => (PoundMolesPerSecondInOneMolePerSecond, PoundMolesPerSecondTolerance), _ => throw new NotSupportedException() }; } @@ -73,6 +82,9 @@ public abstract partial class MolarFlowTestsBase : QuantityTestsBase new object[] { MolarFlowUnit.KilomolePerHour }, new object[] { MolarFlowUnit.KilomolePerMinute }, new object[] { MolarFlowUnit.KilomolePerSecond }, + new object[] { MolarFlowUnit.MolePerHour }, + new object[] { MolarFlowUnit.MolePerMinute }, + new object[] { MolarFlowUnit.MolePerSecond }, new object[] { MolarFlowUnit.PoundMolePerHour }, new object[] { MolarFlowUnit.PoundMolePerMinute }, new object[] { MolarFlowUnit.PoundMolePerSecond }, @@ -83,20 +95,20 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() { var quantity = new MolarFlow(); Assert.Equal(0, quantity.Value); - Assert.Equal(MolarFlowUnit.KilomolePerSecond, quantity.Unit); + Assert.Equal(MolarFlowUnit.MolePerSecond, quantity.Unit); } [Fact] public void Ctor_WithInfinityValue_ThrowsArgumentException() { - Assert.Throws(() => new MolarFlow(double.PositiveInfinity, MolarFlowUnit.KilomolePerSecond)); - Assert.Throws(() => new MolarFlow(double.NegativeInfinity, MolarFlowUnit.KilomolePerSecond)); + Assert.Throws(() => new MolarFlow(double.PositiveInfinity, MolarFlowUnit.MolePerSecond)); + Assert.Throws(() => new MolarFlow(double.NegativeInfinity, MolarFlowUnit.MolePerSecond)); } [Fact] public void Ctor_WithNaNValue_ThrowsArgumentException() { - Assert.Throws(() => new MolarFlow(double.NaN, MolarFlowUnit.KilomolePerSecond)); + Assert.Throws(() => new MolarFlow(double.NaN, MolarFlowUnit.MolePerSecond)); } [Fact] @@ -123,7 +135,7 @@ public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void MolarFlow_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { - var quantity = new MolarFlow(1, MolarFlowUnit.KilomolePerSecond); + var quantity = new MolarFlow(1, MolarFlowUnit.MolePerSecond); QuantityInfo quantityInfo = quantity.QuantityInfo; @@ -135,15 +147,18 @@ public void MolarFlow_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() } [Fact] - public void KilomolePerSecondToMolarFlowUnits() + public void MolePerSecondToMolarFlowUnits() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - AssertEx.EqualTolerance(KilomolesPerHourInOneKilomolePerSecond, kilomolepersecond.KilomolesPerHour, KilomolesPerHourTolerance); - AssertEx.EqualTolerance(KilomolesPerMinuteInOneKilomolePerSecond, kilomolepersecond.KilomolesPerMinute, KilomolesPerMinuteTolerance); - AssertEx.EqualTolerance(KilomolesPerSecondInOneKilomolePerSecond, kilomolepersecond.KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(PoundsMolePerHourInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerHour, PoundsMolePerHourTolerance); - AssertEx.EqualTolerance(PoundsMolePerMinuteInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); - AssertEx.EqualTolerance(PoundsMolePerSecondInOneKilomolePerSecond, kilomolepersecond.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + AssertEx.EqualTolerance(KilomolesPerHourInOneMolePerSecond, molepersecond.KilomolesPerHour, KilomolesPerHourTolerance); + AssertEx.EqualTolerance(KilomolesPerMinuteInOneMolePerSecond, molepersecond.KilomolesPerMinute, KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(KilomolesPerSecondInOneMolePerSecond, molepersecond.KilomolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(MolesPerHourInOneMolePerSecond, molepersecond.MolesPerHour, MolesPerHourTolerance); + AssertEx.EqualTolerance(MolesPerMinuteInOneMolePerSecond, molepersecond.MolesPerMinute, MolesPerMinuteTolerance); + AssertEx.EqualTolerance(MolesPerSecondInOneMolePerSecond, molepersecond.MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(PoundMolesPerHourInOneMolePerSecond, molepersecond.PoundMolesPerHour, PoundMolesPerHourTolerance); + AssertEx.EqualTolerance(PoundMolesPerMinuteInOneMolePerSecond, molepersecond.PoundMolesPerMinute, PoundMolesPerMinuteTolerance); + AssertEx.EqualTolerance(PoundMolesPerSecondInOneMolePerSecond, molepersecond.PoundMolesPerSecond, PoundMolesPerSecondTolerance); } [Fact] @@ -161,43 +176,58 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity02.KilomolesPerSecond, KilomolesPerSecondTolerance); Assert.Equal(MolarFlowUnit.KilomolePerSecond, quantity02.Unit); - var quantity03 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerHour); - AssertEx.EqualTolerance(1, quantity03.PoundsMolePerHour, PoundsMolePerHourTolerance); - Assert.Equal(MolarFlowUnit.PoundMolePerHour, quantity03.Unit); + var quantity03 = MolarFlow.From(1, MolarFlowUnit.MolePerHour); + AssertEx.EqualTolerance(1, quantity03.MolesPerHour, MolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.MolePerHour, quantity03.Unit); - var quantity04 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerMinute); - AssertEx.EqualTolerance(1, quantity04.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); - Assert.Equal(MolarFlowUnit.PoundMolePerMinute, quantity04.Unit); + var quantity04 = MolarFlow.From(1, MolarFlowUnit.MolePerMinute); + AssertEx.EqualTolerance(1, quantity04.MolesPerMinute, MolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.MolePerMinute, quantity04.Unit); - var quantity05 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerSecond); - AssertEx.EqualTolerance(1, quantity05.PoundsMolePerSecond, PoundsMolePerSecondTolerance); - Assert.Equal(MolarFlowUnit.PoundMolePerSecond, quantity05.Unit); + var quantity05 = MolarFlow.From(1, MolarFlowUnit.MolePerSecond); + AssertEx.EqualTolerance(1, quantity05.MolesPerSecond, MolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.MolePerSecond, quantity05.Unit); + + var quantity06 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerHour); + AssertEx.EqualTolerance(1, quantity06.PoundMolesPerHour, PoundMolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerHour, quantity06.Unit); + + var quantity07 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerMinute); + AssertEx.EqualTolerance(1, quantity07.PoundMolesPerMinute, PoundMolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerMinute, quantity07.Unit); + + var quantity08 = MolarFlow.From(1, MolarFlowUnit.PoundMolePerSecond); + AssertEx.EqualTolerance(1, quantity08.PoundMolesPerSecond, PoundMolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.PoundMolePerSecond, quantity08.Unit); } [Fact] - public void FromKilomolesPerSecond_WithInfinityValue_ThrowsArgumentException() + public void FromMolesPerSecond_WithInfinityValue_ThrowsArgumentException() { - Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.PositiveInfinity)); - Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.NegativeInfinity)); + Assert.Throws(() => MolarFlow.FromMolesPerSecond(double.PositiveInfinity)); + Assert.Throws(() => MolarFlow.FromMolesPerSecond(double.NegativeInfinity)); } [Fact] - public void FromKilomolesPerSecond_WithNanValue_ThrowsArgumentException() + public void FromMolesPerSecond_WithNanValue_ThrowsArgumentException() { - Assert.Throws(() => MolarFlow.FromKilomolesPerSecond(double.NaN)); + Assert.Throws(() => MolarFlow.FromMolesPerSecond(double.NaN)); } [Fact] public void As() { - var kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - AssertEx.EqualTolerance(KilomolesPerHourInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerHour), KilomolesPerHourTolerance); - AssertEx.EqualTolerance(KilomolesPerMinuteInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerMinute), KilomolesPerMinuteTolerance); - AssertEx.EqualTolerance(KilomolesPerSecondInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.KilomolePerSecond), KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(PoundsMolePerHourInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerHour), PoundsMolePerHourTolerance); - AssertEx.EqualTolerance(PoundsMolePerMinuteInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerMinute), PoundsMolePerMinuteTolerance); - AssertEx.EqualTolerance(PoundsMolePerSecondInOneKilomolePerSecond, kilomolepersecond.As(MolarFlowUnit.PoundMolePerSecond), PoundsMolePerSecondTolerance); + var molepersecond = MolarFlow.FromMolesPerSecond(1); + AssertEx.EqualTolerance(KilomolesPerHourInOneMolePerSecond, molepersecond.As(MolarFlowUnit.KilomolePerHour), KilomolesPerHourTolerance); + AssertEx.EqualTolerance(KilomolesPerMinuteInOneMolePerSecond, molepersecond.As(MolarFlowUnit.KilomolePerMinute), KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(KilomolesPerSecondInOneMolePerSecond, molepersecond.As(MolarFlowUnit.KilomolePerSecond), KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(MolesPerHourInOneMolePerSecond, molepersecond.As(MolarFlowUnit.MolePerHour), MolesPerHourTolerance); + AssertEx.EqualTolerance(MolesPerMinuteInOneMolePerSecond, molepersecond.As(MolarFlowUnit.MolePerMinute), MolesPerMinuteTolerance); + AssertEx.EqualTolerance(MolesPerSecondInOneMolePerSecond, molepersecond.As(MolarFlowUnit.MolePerSecond), MolesPerSecondTolerance); + AssertEx.EqualTolerance(PoundMolesPerHourInOneMolePerSecond, molepersecond.As(MolarFlowUnit.PoundMolePerHour), PoundMolesPerHourTolerance); + AssertEx.EqualTolerance(PoundMolesPerMinuteInOneMolePerSecond, molepersecond.As(MolarFlowUnit.PoundMolePerMinute), PoundMolesPerMinuteTolerance); + AssertEx.EqualTolerance(PoundMolesPerSecondInOneMolePerSecond, molepersecond.As(MolarFlowUnit.PoundMolePerSecond), PoundMolesPerSecondTolerance); } [Fact] @@ -222,7 +252,7 @@ public void Parse() { try { - var parsed = MolarFlow.Parse("1 kmol/h", CultureInfo.GetCultureInfo("en-US")); + var parsed = MolarFlow.Parse("1 kkmol/h", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.KilomolesPerHour, KilomolesPerHourTolerance); Assert.Equal(MolarFlowUnit.KilomolePerHour, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -241,24 +271,45 @@ public void Parse() Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = MolarFlow.Parse("1 kmol/h", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MolesPerHour, MolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.MolePerHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 mol/min", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MolesPerMinute, MolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.MolePerMinute, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = MolarFlow.Parse("1 mol/s", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MolesPerSecond, MolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.MolePerSecond, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = MolarFlow.Parse("1 lbmol/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerHour, PoundsMolePerHourTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerHour, PoundMolesPerHourTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { var parsed = MolarFlow.Parse("1 lbmol/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerMinute, PoundMolesPerMinuteTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { var parsed = MolarFlow.Parse("1 lbmol/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerSecond, PoundMolesPerSecondTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -268,7 +319,7 @@ public void Parse() public void TryParse() { { - Assert.True(MolarFlow.TryParse("1 kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(MolarFlow.TryParse("1 kkmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilomolesPerHour, KilomolesPerHourTolerance); Assert.Equal(MolarFlowUnit.KilomolePerHour, parsed.Unit); } @@ -285,21 +336,39 @@ public void TryParse() Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsed.Unit); } + { + Assert.True(MolarFlow.TryParse("1 kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MolesPerHour, MolesPerHourTolerance); + Assert.Equal(MolarFlowUnit.MolePerHour, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 mol/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MolesPerMinute, MolesPerMinuteTolerance); + Assert.Equal(MolarFlowUnit.MolePerMinute, parsed.Unit); + } + + { + Assert.True(MolarFlow.TryParse("1 mol/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MolesPerSecond, MolesPerSecondTolerance); + Assert.Equal(MolarFlowUnit.MolePerSecond, parsed.Unit); + } + { Assert.True(MolarFlow.TryParse("1 lbmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerHour, PoundsMolePerHourTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerHour, PoundMolesPerHourTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsed.Unit); } { Assert.True(MolarFlow.TryParse("1 lbmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerMinute, PoundsMolePerMinuteTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerMinute, PoundMolesPerMinuteTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsed.Unit); } { Assert.True(MolarFlow.TryParse("1 lbmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsMolePerSecond, PoundsMolePerSecondTolerance); + AssertEx.EqualTolerance(1, parsed.PoundMolesPerSecond, PoundMolesPerSecondTolerance); Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); } @@ -310,7 +379,7 @@ public void ParseUnit() { try { - var parsedUnit = MolarFlow.ParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US")); + var parsedUnit = MolarFlow.ParseUnit("kkmol/h", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -326,6 +395,24 @@ public void ParseUnit() Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = MolarFlow.ParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.MolePerHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("mol/min", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.MolePerMinute, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = MolarFlow.ParseUnit("mol/s", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(MolarFlowUnit.MolePerSecond, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = MolarFlow.ParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US")); @@ -350,7 +437,7 @@ public void ParseUnit() public void TryParseUnit() { { - Assert.True(MolarFlow.TryParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.True(MolarFlow.TryParseUnit("kkmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); } @@ -364,6 +451,21 @@ public void TryParseUnit() Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); } + { + Assert.True(MolarFlow.TryParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.MolePerHour, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("mol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.MolePerMinute, parsedUnit); + } + + { + Assert.True(MolarFlow.TryParseUnit("mol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(MolarFlowUnit.MolePerSecond, parsedUnit); + } + { Assert.True(MolarFlow.TryParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsedUnit); @@ -426,73 +528,76 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola [Fact] public void ConversionRoundTrip() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerHour(kilomolepersecond.KilomolesPerHour).KilomolesPerSecond, KilomolesPerHourTolerance); - AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerMinute(kilomolepersecond.KilomolesPerMinute).KilomolesPerSecond, KilomolesPerMinuteTolerance); - AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerSecond(kilomolepersecond.KilomolesPerSecond).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerHour(kilomolepersecond.PoundsMolePerHour).KilomolesPerSecond, PoundsMolePerHourTolerance); - AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerMinute(kilomolepersecond.PoundsMolePerMinute).KilomolesPerSecond, PoundsMolePerMinuteTolerance); - AssertEx.EqualTolerance(1, MolarFlow.FromPoundsMolePerSecond(kilomolepersecond.PoundsMolePerSecond).KilomolesPerSecond, PoundsMolePerSecondTolerance); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerHour(molepersecond.KilomolesPerHour).MolesPerSecond, KilomolesPerHourTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerMinute(molepersecond.KilomolesPerMinute).MolesPerSecond, KilomolesPerMinuteTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromKilomolesPerSecond(molepersecond.KilomolesPerSecond).MolesPerSecond, KilomolesPerSecondTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromMolesPerHour(molepersecond.MolesPerHour).MolesPerSecond, MolesPerHourTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromMolesPerMinute(molepersecond.MolesPerMinute).MolesPerSecond, MolesPerMinuteTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromMolesPerSecond(molepersecond.MolesPerSecond).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundMolesPerHour(molepersecond.PoundMolesPerHour).MolesPerSecond, PoundMolesPerHourTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundMolesPerMinute(molepersecond.PoundMolesPerMinute).MolesPerSecond, PoundMolesPerMinuteTolerance); + AssertEx.EqualTolerance(1, MolarFlow.FromPoundMolesPerSecond(molepersecond.PoundMolesPerSecond).MolesPerSecond, PoundMolesPerSecondTolerance); } [Fact] public void ArithmeticOperators() { - MolarFlow v = MolarFlow.FromKilomolesPerSecond(1); - AssertEx.EqualTolerance(-1, -v.KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(2, (MolarFlow.FromKilomolesPerSecond(3)-v).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(2, (MolarFlow.FromKilomolesPerSecond(10)/5).KilomolesPerSecond, KilomolesPerSecondTolerance); - AssertEx.EqualTolerance(2, MolarFlow.FromKilomolesPerSecond(10)/MolarFlow.FromKilomolesPerSecond(5), KilomolesPerSecondTolerance); + MolarFlow v = MolarFlow.FromMolesPerSecond(1); + AssertEx.EqualTolerance(-1, -v.MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (MolarFlow.FromMolesPerSecond(3)-v).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (v + v).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(10, (v*10).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(10, (10*v).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(2, (MolarFlow.FromMolesPerSecond(10)/5).MolesPerSecond, MolesPerSecondTolerance); + AssertEx.EqualTolerance(2, MolarFlow.FromMolesPerSecond(10)/MolarFlow.FromMolesPerSecond(5), MolesPerSecondTolerance); } [Fact] public void ComparisonOperators() { - MolarFlow oneKilomolePerSecond = MolarFlow.FromKilomolesPerSecond(1); - MolarFlow twoKilomolesPerSecond = MolarFlow.FromKilomolesPerSecond(2); + MolarFlow oneMolePerSecond = MolarFlow.FromMolesPerSecond(1); + MolarFlow twoMolesPerSecond = MolarFlow.FromMolesPerSecond(2); - Assert.True(oneKilomolePerSecond < twoKilomolesPerSecond); - Assert.True(oneKilomolePerSecond <= twoKilomolesPerSecond); - Assert.True(twoKilomolesPerSecond > oneKilomolePerSecond); - Assert.True(twoKilomolesPerSecond >= oneKilomolePerSecond); + Assert.True(oneMolePerSecond < twoMolesPerSecond); + Assert.True(oneMolePerSecond <= twoMolesPerSecond); + Assert.True(twoMolesPerSecond > oneMolePerSecond); + Assert.True(twoMolesPerSecond >= oneMolePerSecond); - Assert.False(oneKilomolePerSecond > twoKilomolesPerSecond); - Assert.False(oneKilomolePerSecond >= twoKilomolesPerSecond); - Assert.False(twoKilomolesPerSecond < oneKilomolePerSecond); - Assert.False(twoKilomolesPerSecond <= oneKilomolePerSecond); + Assert.False(oneMolePerSecond > twoMolesPerSecond); + Assert.False(oneMolePerSecond >= twoMolesPerSecond); + Assert.False(twoMolesPerSecond < oneMolePerSecond); + Assert.False(twoMolesPerSecond <= oneMolePerSecond); } [Fact] public void CompareToIsImplemented() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - Assert.Equal(0, kilomolepersecond.CompareTo(kilomolepersecond)); - Assert.True(kilomolepersecond.CompareTo(MolarFlow.Zero) > 0); - Assert.True(MolarFlow.Zero.CompareTo(kilomolepersecond) < 0); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + Assert.Equal(0, molepersecond.CompareTo(molepersecond)); + Assert.True(molepersecond.CompareTo(MolarFlow.Zero) > 0); + Assert.True(MolarFlow.Zero.CompareTo(molepersecond) < 0); } [Fact] public void CompareToThrowsOnTypeMismatch() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - Assert.Throws(() => kilomolepersecond.CompareTo(new object())); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + Assert.Throws(() => molepersecond.CompareTo(new object())); } [Fact] public void CompareToThrowsOnNull() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - Assert.Throws(() => kilomolepersecond.CompareTo(null)); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + Assert.Throws(() => molepersecond.CompareTo(null)); } [Theory] - [InlineData(1, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerSecond, true)] // Same value and unit. - [InlineData(1, MolarFlowUnit.KilomolePerSecond, 2, MolarFlowUnit.KilomolePerSecond, false)] // Different value. - [InlineData(2, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different value and unit. - [InlineData(1, MolarFlowUnit.KilomolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different unit. + [InlineData(1, MolarFlowUnit.MolePerSecond, 1, MolarFlowUnit.MolePerSecond, true)] // Same value and unit. + [InlineData(1, MolarFlowUnit.MolePerSecond, 2, MolarFlowUnit.MolePerSecond, false)] // Different value. + [InlineData(2, MolarFlowUnit.MolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different value and unit. + [InlineData(1, MolarFlowUnit.MolePerSecond, 1, MolarFlowUnit.KilomolePerHour, false)] // Different unit. public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarFlowUnit unitA, double valueB, MolarFlowUnit unitB, bool expectEqual) { var a = new MolarFlow(valueA, unitA); @@ -532,30 +637,30 @@ public void Equals_Null_ReturnsFalse() [Fact] public void Equals_RelativeTolerance_IsImplemented() { - var v = MolarFlow.FromKilomolesPerSecond(1); - Assert.True(v.Equals(MolarFlow.FromKilomolesPerSecond(1), KilomolesPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MolarFlow.Zero, KilomolesPerSecondTolerance, ComparisonType.Relative)); + var v = MolarFlow.FromMolesPerSecond(1); + Assert.True(v.Equals(MolarFlow.FromMolesPerSecond(1), MolesPerSecondTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(MolarFlow.Zero, MolesPerSecondTolerance, ComparisonType.Relative)); } [Fact] public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() { - var v = MolarFlow.FromKilomolesPerSecond(1); - Assert.Throws(() => v.Equals(MolarFlow.FromKilomolesPerSecond(1), -1, ComparisonType.Relative)); + var v = MolarFlow.FromMolesPerSecond(1); + Assert.Throws(() => v.Equals(MolarFlow.FromMolesPerSecond(1), -1, ComparisonType.Relative)); } [Fact] public void EqualsReturnsFalseOnTypeMismatch() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - Assert.False(kilomolepersecond.Equals(new object())); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + Assert.False(molepersecond.Equals(new object())); } [Fact] public void EqualsReturnsFalseOnNull() { - MolarFlow kilomolepersecond = MolarFlow.FromKilomolesPerSecond(1); - Assert.False(kilomolepersecond.Equals(null)); + MolarFlow molepersecond = MolarFlow.FromMolesPerSecond(1); + Assert.False(molepersecond.Equals(null)); } [Fact] @@ -580,9 +685,12 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { - Assert.Equal("1 kmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString()); + Assert.Equal("1 kkmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString()); Assert.Equal("1 kmol/min", new MolarFlow(1, MolarFlowUnit.KilomolePerMinute).ToString()); Assert.Equal("1 kmol/s", new MolarFlow(1, MolarFlowUnit.KilomolePerSecond).ToString()); + Assert.Equal("1 kmol/h", new MolarFlow(1, MolarFlowUnit.MolePerHour).ToString()); + Assert.Equal("1 mol/min", new MolarFlow(1, MolarFlowUnit.MolePerMinute).ToString()); + Assert.Equal("1 mol/s", new MolarFlow(1, MolarFlowUnit.MolePerSecond).ToString()); Assert.Equal("1 lbmol/h", new MolarFlow(1, MolarFlowUnit.PoundMolePerHour).ToString()); Assert.Equal("1 lbmol/min", new MolarFlow(1, MolarFlowUnit.PoundMolePerMinute).ToString()); Assert.Equal("1 lbmol/s", new MolarFlow(1, MolarFlowUnit.PoundMolePerSecond).ToString()); @@ -599,9 +707,12 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 kmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString(swedishCulture)); + Assert.Equal("1 kkmol/h", new MolarFlow(1, MolarFlowUnit.KilomolePerHour).ToString(swedishCulture)); Assert.Equal("1 kmol/min", new MolarFlow(1, MolarFlowUnit.KilomolePerMinute).ToString(swedishCulture)); Assert.Equal("1 kmol/s", new MolarFlow(1, MolarFlowUnit.KilomolePerSecond).ToString(swedishCulture)); + Assert.Equal("1 kmol/h", new MolarFlow(1, MolarFlowUnit.MolePerHour).ToString(swedishCulture)); + Assert.Equal("1 mol/min", new MolarFlow(1, MolarFlowUnit.MolePerMinute).ToString(swedishCulture)); + Assert.Equal("1 mol/s", new MolarFlow(1, MolarFlowUnit.MolePerSecond).ToString(swedishCulture)); Assert.Equal("1 lbmol/h", new MolarFlow(1, MolarFlowUnit.PoundMolePerHour).ToString(swedishCulture)); Assert.Equal("1 lbmol/min", new MolarFlow(1, MolarFlowUnit.PoundMolePerMinute).ToString(swedishCulture)); Assert.Equal("1 lbmol/s", new MolarFlow(1, MolarFlowUnit.PoundMolePerSecond).ToString(swedishCulture)); @@ -614,10 +725,10 @@ public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCul try { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s1")); - Assert.Equal("0.12 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s2")); - Assert.Equal("0.123 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s3")); - Assert.Equal("0.1235 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s4")); + Assert.Equal("0.1 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s1")); + Assert.Equal("0.12 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s2")); + Assert.Equal("0.123 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s3")); + Assert.Equal("0.1235 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s4")); } finally { @@ -629,10 +740,10 @@ public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCul public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() { var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s1", culture)); - Assert.Equal("0.12 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s2", culture)); - Assert.Equal("0.123 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s3", culture)); - Assert.Equal("0.1235 kmol/s", new MolarFlow(0.123456, MolarFlowUnit.KilomolePerSecond).ToString("s4", culture)); + Assert.Equal("0.1 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s1", culture)); + Assert.Equal("0.12 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s2", culture)); + Assert.Equal("0.123 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s3", culture)); + Assert.Equal("0.1235 mol/s", new MolarFlow(0.123456, MolarFlowUnit.MolePerSecond).ToString("s4", culture)); } [Theory] @@ -640,7 +751,7 @@ public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixFor [InlineData("en-US")] public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); CultureInfo formatProvider = cultureName == null ? null : CultureInfo.GetCultureInfo(cultureName); @@ -653,154 +764,154 @@ public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) [InlineData("g")] public void ToString_NullProvider_EqualsCurrentCulture(string format) { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); } [Fact] public void Convert_ToBool_ThrowsInvalidCastException() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Throws(() => Convert.ToBoolean(quantity)); } [Fact] public void Convert_ToByte_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); } [Fact] public void Convert_ToChar_ThrowsInvalidCastException() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Throws(() => Convert.ToChar(quantity)); } [Fact] public void Convert_ToDateTime_ThrowsInvalidCastException() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Throws(() => Convert.ToDateTime(quantity)); } [Fact] public void Convert_ToDecimal_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); } [Fact] public void Convert_ToDouble_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); } [Fact] public void Convert_ToInt16_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); } [Fact] public void Convert_ToInt32_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); } [Fact] public void Convert_ToInt64_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); } [Fact] public void Convert_ToSByte_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); } [Fact] public void Convert_ToSingle_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); } [Fact] public void Convert_ToString_EqualsToString() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); } [Fact] public void Convert_ToUInt16_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); } [Fact] public void Convert_ToUInt32_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); } [Fact] public void Convert_ToUInt64_EqualsValueAsSameType() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); } [Fact] public void Convert_ChangeType_SelfType_EqualsSelf() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(MolarFlow))); } [Fact] public void Convert_ChangeType_UnitType_EqualsUnit() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(MolarFlowUnit))); } [Fact] public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(MolarFlow.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); } [Fact] public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(MolarFlow.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); } [Fact] public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } [Fact] public void GetHashCode_Equals() { - var quantity = MolarFlow.FromKilomolesPerSecond(1.0); + var quantity = MolarFlow.FromMolesPerSecond(1.0); Assert.Equal(new {MolarFlow.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); } @@ -809,8 +920,8 @@ public void GetHashCode_Equals() [InlineData(-1.0)] public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { - var quantity = MolarFlow.FromKilomolesPerSecond(value); - Assert.Equal(MolarFlow.FromKilomolesPerSecond(-value), -quantity); + var quantity = MolarFlow.FromMolesPerSecond(value); + Assert.Equal(MolarFlow.FromMolesPerSecond(-value), -quantity); } } } diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 71606e8d8f..92e50b3549 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -59,7 +59,8 @@ static HeatTransferCoefficient() Info = new QuantityInfo("HeatTransferCoefficient", new UnitInfo[] { - new UnitInfo(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, "BtusPerSquareFootDegreeFahrenheit", BaseUnits.Undefined), + new UnitInfo(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "BtusPerHourSquareFootDegreeFahrenheit", BaseUnits.Undefined), + new UnitInfo(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "KilocaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined), new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattsPerSquareMeterCelsius", BaseUnits.Undefined), new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattsPerSquareMeterKelvin", BaseUnits.Undefined), }, @@ -166,9 +167,14 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) #region Conversion Properties /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public double BtusPerSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + public double BtusPerHourSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + + /// + /// Gets a value of this quantity converted into + /// + public double KilocaloriesPerHourSquareMeterDegreeCelsius => As(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); /// /// Gets a value of this quantity converted into @@ -191,20 +197,23 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: HeatTransferCoefficientUnit -> BaseUnit - unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity); // Register in unit converter: BaseUnit -> HeatTransferCoefficientUnit - unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)); } internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) { - unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, new CultureInfo("en-US"), false, true, new string[]{"Btu/ft²·hr·°F"}); + unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, new CultureInfo("en-US"), false, true, new string[]{"Btu/h·ft²·°F", "Btu/ft²·h·°F", "Btu/hr·ft²·°F", "Btu/ft²·hr·°F"}); + unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, new CultureInfo("en-US"), false, true, new string[]{"kcal/h·m²·°C", "kcal/m²·h·°C", "kcal/hr·m²·°C", "kcal/m²·hr·°C"}); unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, new CultureInfo("en-US"), false, true, new string[]{"W/m²·°C"}); unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, new CultureInfo("en-US"), false, true, new string[]{"W/m²·K"}); } @@ -235,13 +244,23 @@ public static string GetAbbreviation(HeatTransferCoefficientUnit unit, IFormatPr #region Static Factory Methods /// - /// Creates a from . + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static HeatTransferCoefficient FromBtusPerHourSquareFootDegreeFahrenheit(QuantityValue btusperhoursquarefootdegreefahrenheit) + { + double value = (double) btusperhoursquarefootdegreefahrenheit; + return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + } + + /// + /// Creates a from . /// /// If value is NaN or Infinity. - public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(QuantityValue btuspersquarefootdegreefahrenheit) + public static HeatTransferCoefficient FromKilocaloriesPerHourSquareMeterDegreeCelsius(QuantityValue kilocaloriesperhoursquaremeterdegreecelsius) { - double value = (double) btuspersquarefootdegreefahrenheit; - return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + double value = (double) kilocaloriesperhoursquaremeterdegreecelsius; + return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); } /// @@ -730,11 +749,13 @@ private bool TryToUnit(HeatTransferCoefficientUnit unit, [NotNullWhen(true)] out HeatTransferCoefficient? convertedOrNull = (Unit, unit) switch { // HeatTransferCoefficientUnit -> BaseUnit - (HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value * 5.6782633411134878, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), + (HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value * 5.6782633411134878, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), + (HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient((_value * 4184) / 3600, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), (HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), // BaseUnit -> HeatTransferCoefficientUnit - (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit) => new HeatTransferCoefficient(_value / 5.6782633411134878, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit), + (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit) => new HeatTransferCoefficient(_value / 5.6782633411134878, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit), + (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius) => new HeatTransferCoefficient((_value / 4184) * 3600, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius), (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius) => new HeatTransferCoefficient(_value, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius), _ => null diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index 328d85b245..0cf791e10f 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -53,18 +53,21 @@ namespace UnitsNet static MolarFlow() { BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 1, 0); - BaseUnit = MolarFlowUnit.KilomolePerSecond; + BaseUnit = MolarFlowUnit.MolePerSecond; Units = Enum.GetValues(typeof(MolarFlowUnit)).Cast().ToArray(); Zero = new MolarFlow(0, BaseUnit); Info = new QuantityInfo("MolarFlow", new UnitInfo[] { - new UnitInfo(MolarFlowUnit.KilomolePerHour, "KilomolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Kilomole)), - new UnitInfo(MolarFlowUnit.KilomolePerMinute, "KilomolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Kilomole)), - new UnitInfo(MolarFlowUnit.KilomolePerSecond, "KilomolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Kilomole)), - new UnitInfo(MolarFlowUnit.PoundMolePerHour, "PoundsMolePerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.PoundMole)), - new UnitInfo(MolarFlowUnit.PoundMolePerMinute, "PoundsMolePerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.PoundMole)), - new UnitInfo(MolarFlowUnit.PoundMolePerSecond, "PoundsMolePerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.PoundMole)), + new UnitInfo(MolarFlowUnit.KilomolePerHour, "KilomolesPerHour", BaseUnits.Undefined), + new UnitInfo(MolarFlowUnit.KilomolePerMinute, "KilomolesPerMinute", BaseUnits.Undefined), + new UnitInfo(MolarFlowUnit.KilomolePerSecond, "KilomolesPerSecond", BaseUnits.Undefined), + new UnitInfo(MolarFlowUnit.MolePerHour, "MolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarFlowUnit.MolePerMinute, "MolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarFlowUnit.MolePerSecond, "MolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarFlowUnit.PoundMolePerHour, "PoundMolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.PoundMole)), + new UnitInfo(MolarFlowUnit.PoundMolePerMinute, "PoundMolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.PoundMole)), + new UnitInfo(MolarFlowUnit.PoundMolePerSecond, "PoundMolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.PoundMole)), }, BaseUnit, Zero, BaseDimensions); @@ -119,7 +122,7 @@ public MolarFlow(double value, UnitSystem unitSystem) public static BaseDimensions BaseDimensions { get; } /// - /// The base unit of MolarFlow, which is KilomolePerSecond. All conversions go via this value. + /// The base unit of MolarFlow, which is MolePerSecond. All conversions go via this value. /// public static MolarFlowUnit BaseUnit { get; } @@ -129,7 +132,7 @@ public MolarFlow(double value, UnitSystem unitSystem) public static MolarFlowUnit[] Units { get; } /// - /// Gets an instance of this quantity with a value of 0 in the base unit KilomolePerSecond. + /// Gets an instance of this quantity with a value of 0 in the base unit MolePerSecond. /// public static MolarFlow Zero { get; } @@ -183,20 +186,35 @@ public MolarFlow(double value, UnitSystem unitSystem) /// public double KilomolesPerSecond => As(MolarFlowUnit.KilomolePerSecond); + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerHour => As(MolarFlowUnit.MolePerHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerMinute => As(MolarFlowUnit.MolePerMinute); + + /// + /// Gets a value of this quantity converted into + /// + public double MolesPerSecond => As(MolarFlowUnit.MolePerSecond); + /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerHour => As(MolarFlowUnit.PoundMolePerHour); + public double PoundMolesPerHour => As(MolarFlowUnit.PoundMolePerHour); /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerMinute => As(MolarFlowUnit.PoundMolePerMinute); + public double PoundMolesPerMinute => As(MolarFlowUnit.PoundMolePerMinute); /// /// Gets a value of this quantity converted into /// - public double PoundsMolePerSecond => As(MolarFlowUnit.PoundMolePerSecond); + public double PoundMolesPerSecond => As(MolarFlowUnit.PoundMolePerSecond); #endregion @@ -209,28 +227,37 @@ public MolarFlow(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: MolarFlowUnit -> BaseUnit - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerHour, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); - unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); - unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); - unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerHour, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerHour, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerMinute, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.MolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.MolePerSecond)); // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerSecond, quantity => quantity); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.MolePerSecond, quantity => quantity); // Register in unit converter: BaseUnit -> MolarFlowUnit - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerHour)); - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerMinute)); - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerHour)); - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerMinute)); - unitConverter.SetConversionFunction(MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerHour)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerMinute)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.KilomolePerSecond)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.MolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.MolePerHour)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.MolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.MolePerMinute)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerHour, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerHour)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerMinute, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerMinute)); + unitConverter.SetConversionFunction(MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerSecond, quantity => quantity.ToUnit(MolarFlowUnit.PoundMolePerSecond)); } internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) { - unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerHour, new CultureInfo("en-US"), false, true, new string[]{"kmol/h"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerHour, new CultureInfo("en-US"), false, true, new string[]{"kkmol/h"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerMinute, new CultureInfo("en-US"), false, true, new string[]{"kmol/min"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.KilomolePerSecond, new CultureInfo("en-US"), false, true, new string[]{"kmol/s"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.MolePerHour, new CultureInfo("en-US"), false, true, new string[]{"kmol/h"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.MolePerMinute, new CultureInfo("en-US"), false, true, new string[]{"mol/min"}); + unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.MolePerSecond, new CultureInfo("en-US"), false, true, new string[]{"mol/s"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerHour, new CultureInfo("en-US"), false, true, new string[]{"lbmol/h"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerMinute, new CultureInfo("en-US"), false, true, new string[]{"lbmol/min"}); unitAbbreviationsCache.PerformAbbreviationMapping(MolarFlowUnit.PoundMolePerSecond, new CultureInfo("en-US"), false, true, new string[]{"lbmol/s"}); @@ -291,13 +318,43 @@ public static MolarFlow FromKilomolesPerSecond(QuantityValue kilomolespersecond) return new MolarFlow(value, MolarFlowUnit.KilomolePerSecond); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerHour(QuantityValue molesperhour) + { + double value = (double) molesperhour; + return new MolarFlow(value, MolarFlowUnit.MolePerHour); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerMinute(QuantityValue molesperminute) + { + double value = (double) molesperminute; + return new MolarFlow(value, MolarFlowUnit.MolePerMinute); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static MolarFlow FromMolesPerSecond(QuantityValue molespersecond) + { + double value = (double) molespersecond; + return new MolarFlow(value, MolarFlowUnit.MolePerSecond); + } + /// /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerHour(QuantityValue poundsmoleperhour) + public static MolarFlow FromPoundMolesPerHour(QuantityValue poundmolesperhour) { - double value = (double) poundsmoleperhour; + double value = (double) poundmolesperhour; return new MolarFlow(value, MolarFlowUnit.PoundMolePerHour); } @@ -305,9 +362,9 @@ public static MolarFlow FromPoundsMolePerHour(QuantityValue poundsmoleperhour) /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerMinute(QuantityValue poundsmoleperminute) + public static MolarFlow FromPoundMolesPerMinute(QuantityValue poundmolesperminute) { - double value = (double) poundsmoleperminute; + double value = (double) poundmolesperminute; return new MolarFlow(value, MolarFlowUnit.PoundMolePerMinute); } @@ -315,9 +372,9 @@ public static MolarFlow FromPoundsMolePerMinute(QuantityValue poundsmoleperminut /// Creates a from . /// /// If value is NaN or Infinity. - public static MolarFlow FromPoundsMolePerSecond(QuantityValue poundsmolepersecond) + public static MolarFlow FromPoundMolesPerSecond(QuantityValue poundmolespersecond) { - double value = (double) poundsmolepersecond; + double value = (double) poundmolespersecond; return new MolarFlow(value, MolarFlowUnit.PoundMolePerSecond); } @@ -519,7 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// Get ratio value from dividing by . public static double operator /(MolarFlow left, MolarFlow right) { - return left.KilomolesPerSecond / right.KilomolesPerSecond; + return left.MolesPerSecond / right.MolesPerSecond; } #endregion @@ -787,18 +844,24 @@ private bool TryToUnit(MolarFlowUnit unit, [NotNullWhen(true)] out MolarFlow? co MolarFlow? convertedOrNull = (Unit, unit) switch { // MolarFlowUnit -> BaseUnit - (MolarFlowUnit.KilomolePerHour, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 3.599997e3, MolarFlowUnit.KilomolePerSecond), - (MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 5.999988e1, MolarFlowUnit.KilomolePerSecond), - (MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 7.93663391482404e3, MolarFlowUnit.KilomolePerSecond), - (MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 1.32277406886626e2, MolarFlowUnit.KilomolePerSecond), - (MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.KilomolePerSecond) => new MolarFlow(_value / 2.2046244201838, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.KilomolePerHour, MolarFlowUnit.MolePerSecond) => new MolarFlow((_value / 3600) * 1e3d, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.KilomolePerMinute, MolarFlowUnit.MolePerSecond) => new MolarFlow((_value / 60) * 1e3d, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.MolePerSecond) => new MolarFlow((_value) * 1e3d, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.MolePerHour, MolarFlowUnit.MolePerSecond) => new MolarFlow(_value / 3600, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.MolePerMinute, MolarFlowUnit.MolePerSecond) => new MolarFlow(_value / 60, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.PoundMolePerHour, MolarFlowUnit.MolePerSecond) => new MolarFlow((_value * 453.59237) / 3600, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.PoundMolePerMinute, MolarFlowUnit.MolePerSecond) => new MolarFlow((_value * 453.59237) / 60, MolarFlowUnit.MolePerSecond), + (MolarFlowUnit.PoundMolePerSecond, MolarFlowUnit.MolePerSecond) => new MolarFlow(_value * 453.59237, MolarFlowUnit.MolePerSecond), // BaseUnit -> MolarFlowUnit - (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerHour) => new MolarFlow(_value * 3.599997e3, MolarFlowUnit.KilomolePerHour), - (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.KilomolePerMinute) => new MolarFlow(_value * 5.999988e1, MolarFlowUnit.KilomolePerMinute), - (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerHour) => new MolarFlow(_value * 7.93663391482404e3, MolarFlowUnit.PoundMolePerHour), - (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerMinute) => new MolarFlow(_value * 1.32277406886626e2, MolarFlowUnit.PoundMolePerMinute), - (MolarFlowUnit.KilomolePerSecond, MolarFlowUnit.PoundMolePerSecond) => new MolarFlow(_value * 2.2046244201838, MolarFlowUnit.PoundMolePerSecond), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerHour) => new MolarFlow((_value * 3600) / 1e3d, MolarFlowUnit.KilomolePerHour), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerMinute) => new MolarFlow((_value * 60) / 1e3d, MolarFlowUnit.KilomolePerMinute), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.KilomolePerSecond) => new MolarFlow((_value) / 1e3d, MolarFlowUnit.KilomolePerSecond), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.MolePerHour) => new MolarFlow(_value * 3600, MolarFlowUnit.MolePerHour), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.MolePerMinute) => new MolarFlow(_value * 60, MolarFlowUnit.MolePerMinute), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerHour) => new MolarFlow((_value / 453.59237) * 3600, MolarFlowUnit.PoundMolePerHour), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerMinute) => new MolarFlow((_value / 453.59237) * 60, MolarFlowUnit.PoundMolePerMinute), + (MolarFlowUnit.MolePerSecond, MolarFlowUnit.PoundMolePerSecond) => new MolarFlow(_value / 453.59237, MolarFlowUnit.PoundMolePerSecond), _ => null }; diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index e8a203a918..24cc9f897e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -894,7 +894,7 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv (MolarityUnit.MolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 1e-3, MolarityUnit.MolePerCubicMeter), (MolarityUnit.NanomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-9d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.PicomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-12d, MolarityUnit.MolePerCubicMeter), - (MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 6.242796e-5, MolarityUnit.MolePerCubicMeter), + (MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter) => new Molarity(_value * 6.2427960576144611956325455827221e-5, MolarityUnit.MolePerCubicMeter), // BaseUnit -> MolarityUnit (MolarityUnit.MolePerCubicMeter, MolarityUnit.CentimolePerLiter) => new Molarity((_value * 1e-3) / 1e-2d, MolarityUnit.CentimolePerLiter), @@ -906,7 +906,7 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv (MolarityUnit.MolePerCubicMeter, MolarityUnit.MolePerLiter) => new Molarity(_value * 1e-3, MolarityUnit.MolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.NanomolePerLiter) => new Molarity((_value * 1e-3) / 1e-9d, MolarityUnit.NanomolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.PicomolePerLiter) => new Molarity((_value * 1e-3) / 1e-12d, MolarityUnit.PicomolePerLiter), - (MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot) => new Molarity(_value * 6.242796e-5, MolarityUnit.PoundMolePerCubicFoot), + (MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot) => new Molarity(_value / 6.2427960576144611956325455827221e-5, MolarityUnit.PoundMolePerCubicFoot), _ => null }; diff --git a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index e337b5095a..d19a94cb83 100644 --- a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -25,7 +25,8 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { - BtuPerSquareFootDegreeFahrenheit = 1, + BtuPerHourSquareFootDegreeFahrenheit = 11, + KilocaloriePerHourSquareMeterDegreeCelsius = 8, WattPerSquareMeterCelsius = 2, WattPerSquareMeterKelvin = 3, } diff --git a/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs index c58c44ea9e..48bc201810 100644 --- a/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MolarFlowUnit.g.cs @@ -28,6 +28,9 @@ public enum MolarFlowUnit KilomolePerHour = 2, KilomolePerMinute = 15, KilomolePerSecond = 12, + MolePerHour = 8, + MolePerMinute = 18, + MolePerSecond = 3, PoundMolePerHour = 6, PoundMolePerMinute = 7, PoundMolePerSecond = 4, From 2ba3c453470e7426759ba9057c5fbaa49410c3d1 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Sat, 11 Feb 2023 01:21:34 -0500 Subject: [PATCH 4/8] Molarity unit fix --- Common/UnitDefinitions/Molarity.json | 4 ++-- UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs | 4 ++-- UnitsNet/GeneratedCode/Quantities/Molarity.g.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index 5914a0c048..9dc937c082 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -49,8 +49,8 @@ "L": "Foot", "N": "PoundMole" }, - "FromUnitToBaseFunc": "{x} * 6.2427960576144611956325455827221e-5", - "FromBaseToUnitFunc": "{x} / 6.2427960576144611956325455827221e-5", + "FromUnitToBaseFunc": "{x} / 6.2427960576144611956325455827221e-5", + "FromBaseToUnitFunc": "{x} * 6.2427960576144611956325455827221e-5", "Localization": [ { "Culture": "en-US", diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs index 51fffbc3eb..abf7d40884 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.g.cs @@ -257,7 +257,7 @@ private double GetValueInBaseUnit() MolarityUnit.MolePerLiter => _value / 1e-3, MolarityUnit.NanomolePerLiter => (_value / 1e-3) * 1e-9d, MolarityUnit.PicomolePerLiter => (_value / 1e-3) * 1e-12d, - MolarityUnit.PoundMolePerCubicFoot => _value * 6.2427960576144611956325455827221e-5, + MolarityUnit.PoundMolePerCubicFoot => _value / 6.2427960576144611956325455827221e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -281,7 +281,7 @@ private double GetValueAs(MolarityUnit unit) MolarityUnit.MolePerLiter => baseUnitValue * 1e-3, MolarityUnit.NanomolePerLiter => (baseUnitValue * 1e-3) / 1e-9d, MolarityUnit.PicomolePerLiter => (baseUnitValue * 1e-3) / 1e-12d, - MolarityUnit.PoundMolePerCubicFoot => baseUnitValue / 6.2427960576144611956325455827221e-5, + MolarityUnit.PoundMolePerCubicFoot => baseUnitValue * 6.2427960576144611956325455827221e-5, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index 24cc9f897e..13370129df 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -894,7 +894,7 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv (MolarityUnit.MolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 1e-3, MolarityUnit.MolePerCubicMeter), (MolarityUnit.NanomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-9d, MolarityUnit.MolePerCubicMeter), (MolarityUnit.PicomolePerLiter, MolarityUnit.MolePerCubicMeter) => new Molarity((_value / 1e-3) * 1e-12d, MolarityUnit.MolePerCubicMeter), - (MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter) => new Molarity(_value * 6.2427960576144611956325455827221e-5, MolarityUnit.MolePerCubicMeter), + (MolarityUnit.PoundMolePerCubicFoot, MolarityUnit.MolePerCubicMeter) => new Molarity(_value / 6.2427960576144611956325455827221e-5, MolarityUnit.MolePerCubicMeter), // BaseUnit -> MolarityUnit (MolarityUnit.MolePerCubicMeter, MolarityUnit.CentimolePerLiter) => new Molarity((_value * 1e-3) / 1e-2d, MolarityUnit.CentimolePerLiter), @@ -906,7 +906,7 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv (MolarityUnit.MolePerCubicMeter, MolarityUnit.MolePerLiter) => new Molarity(_value * 1e-3, MolarityUnit.MolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.NanomolePerLiter) => new Molarity((_value * 1e-3) / 1e-9d, MolarityUnit.NanomolePerLiter), (MolarityUnit.MolePerCubicMeter, MolarityUnit.PicomolePerLiter) => new Molarity((_value * 1e-3) / 1e-12d, MolarityUnit.PicomolePerLiter), - (MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot) => new Molarity(_value / 6.2427960576144611956325455827221e-5, MolarityUnit.PoundMolePerCubicFoot), + (MolarityUnit.MolePerCubicMeter, MolarityUnit.PoundMolePerCubicFoot) => new Molarity(_value * 6.2427960576144611956325455827221e-5, MolarityUnit.PoundMolePerCubicFoot), _ => null }; From 210e9071caef71412bf435eb23447f503f1a4b6f Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 12 Feb 2023 12:38:51 +0100 Subject: [PATCH 5/8] Update MolarFlowTests.cs Improve precision of test case --- UnitsNet.Tests/CustomCode/MolarFlowTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs index 66288f3915..f11828b446 100644 --- a/UnitsNet.Tests/CustomCode/MolarFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarFlowTests.cs @@ -38,7 +38,7 @@ public class MolarFlowTests : MolarFlowTestsBase protected override double PoundMolesPerMinuteInOneMolePerSecond => 0.132277357311; - protected override double PoundMolesPerSecondInOneMolePerSecond => 2.204622621848e-3; + protected override double PoundMolesPerSecondInOneMolePerSecond => 2.2046226218488e-3; protected override double MolesPerHourInOneMolePerSecond => 3600; From e37d7663ec5ec5d5e0d55a56e8e9e903c4390578 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Mon, 13 Feb 2023 18:47:14 -0500 Subject: [PATCH 6/8] Changed to cal (IT) + marked obsolete property --- .../HeatTransferCoefficient.json | 22 ++- Common/UnitEnumValues.g.json | 3 +- .../Quantities/HeatTransferCoefficient.g.cs | 32 +++- .../Units/HeatTransferCoefficientUnit.g.cs | 3 + ...HeatTransferCoefficientExtensionsTest.g.cs | 10 +- ...erToHeatTransferCoefficientExtensions.g.cs | 9 + .../HeatTransferCoefficientTests.cs | 4 +- .../HeatTransferCoefficientTestsBase.g.cs | 168 +++++++++++++++--- .../Quantities/HeatTransferCoefficient.g.cs | 52 +++++- .../Units/HeatTransferCoefficientUnit.g.cs | 3 + 10 files changed, 270 insertions(+), 36 deletions(-) diff --git a/Common/UnitDefinitions/HeatTransferCoefficient.json b/Common/UnitDefinitions/HeatTransferCoefficient.json index a953d733b3..75db786ba7 100644 --- a/Common/UnitDefinitions/HeatTransferCoefficient.json +++ b/Common/UnitDefinitions/HeatTransferCoefficient.json @@ -32,6 +32,19 @@ } ] }, + { + "SingularName": "BtuPerSquareFootDegreeFahrenheit", + "PluralName": "BtusPerSquareFootDegreeFahrenheit", + "ObsoleteText": "The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead", + "FromUnitToBaseFunc": "{x} * 5.6782633411134878", + "FromBaseToUnitFunc": "{x} / 5.6782633411134878", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Btu/ft²·°F" ] + } + ] + }, { "SingularName": "BtuPerHourSquareFootDegreeFahrenheit", "PluralName": "BtusPerHourSquareFootDegreeFahrenheit", @@ -45,10 +58,11 @@ ] }, { - "SingularName": "KilocaloriePerHourSquareMeterDegreeCelsius", - "PluralName": "KilocaloriesPerHourSquareMeterDegreeCelsius", - "FromUnitToBaseFunc": "({x} * 4184) / 3600", - "FromBaseToUnitFunc": "({x} / 4184) * 3600", + "SingularName": "CaloriePerHourSquareMeterDegreeCelsius", + "PluralName": "CaloriesPerHourSquareMeterDegreeCelsius", + "Prefixes": [ "Kilo" ], + "FromUnitToBaseFunc": "({x} * 4.1868) / 3600", + "FromBaseToUnitFunc": "({x} / 4.1868) * 3600", "Localization": [ { "Culture": "en-US", diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index aa207afb46..d2cb2ed2d6 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -539,7 +539,8 @@ "WattPerSquareMeterCelsius": 2, "WattPerSquareMeterKelvin": 3, "BtuPerHourSquareFootDegreeFahrenheit": 11, - "KilocaloriePerHourSquareMeterDegreeCelsius": 8 + "KilocaloriePerHourSquareMeterDegreeCelsius": 8, + "CaloriePerHourSquareMeterDegreeCelsius": 5 }, "Illuminance": { "Kilolux": 1, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index cb0857d30a..979123176b 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -84,6 +84,17 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// public double BtusPerHourSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + /// + /// Gets a value of this quantity converted into + /// + [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + public double BtusPerSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + + /// + /// Gets a value of this quantity converted into + /// + public double CaloriesPerHourSquareMeterDegreeCelsius => As(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius); + /// /// Gets a value of this quantity converted into /// @@ -109,6 +120,19 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// If value is NaN or Infinity. public static HeatTransferCoefficient FromBtusPerHourSquareFootDegreeFahrenheit(double btusperhoursquarefootdegreefahrenheit) => new HeatTransferCoefficient(btusperhoursquarefootdegreefahrenheit, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(double btuspersquarefootdegreefahrenheit) => new HeatTransferCoefficient(btuspersquarefootdegreefahrenheit, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static HeatTransferCoefficient FromCaloriesPerHourSquareMeterDegreeCelsius(double caloriesperhoursquaremeterdegreecelsius) => new HeatTransferCoefficient(caloriesperhoursquaremeterdegreecelsius, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius); + /// /// Creates a from . /// @@ -168,7 +192,9 @@ private double GetValueInBaseUnit() return Unit switch { HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => _value * 5.6782633411134878, - HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (_value * 4184) / 3600, + HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => _value * 5.6782633411134878, + HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius => (_value * 4.1868) / 3600, + HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => ((_value * 4.1868) / 3600) * 1e3d, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => _value, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => _value, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") @@ -185,7 +211,9 @@ private double GetValueAs(HeatTransferCoefficientUnit unit) return unit switch { HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => baseUnitValue / 5.6782633411134878, - HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (baseUnitValue / 4184) * 3600, + HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => baseUnitValue / 5.6782633411134878, + HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius => (baseUnitValue / 4.1868) * 3600, + HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => ((baseUnitValue / 4.1868) * 3600) / 1e3d, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => baseUnitValue, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => baseUnitValue, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index d19a94cb83..4c8b3da7cd 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -26,6 +26,9 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { BtuPerHourSquareFootDegreeFahrenheit = 11, + [System.Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + BtuPerSquareFootDegreeFahrenheit = 1, + CaloriePerHourSquareMeterDegreeCelsius = 5, KilocaloriePerHourSquareMeterDegreeCelsius = 8, WattPerSquareMeterCelsius = 2, WattPerSquareMeterKelvin = 3, diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs index 3eecd7afbd..e43998fec0 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -28,6 +28,14 @@ public class NumberToHeatTransferCoefficientExtensionsTests public void NumberToBtusPerHourSquareFootDegreeFahrenheitTest() => Assert.Equal(HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(2), 2.BtusPerHourSquareFootDegreeFahrenheit()); + [Fact] + public void NumberToBtusPerSquareFootDegreeFahrenheitTest() => + Assert.Equal(HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(2), 2.BtusPerSquareFootDegreeFahrenheit()); + + [Fact] + public void NumberToCaloriesPerHourSquareMeterDegreeCelsiusTest() => + Assert.Equal(HeatTransferCoefficient.FromCaloriesPerHourSquareMeterDegreeCelsius(2), 2.CaloriesPerHourSquareMeterDegreeCelsius()); + [Fact] public void NumberToKilocaloriesPerHourSquareMeterDegreeCelsiusTest() => Assert.Equal(HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(2), 2.KilocaloriesPerHourSquareMeterDegreeCelsius()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs index 9664bdd902..9184523f66 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs @@ -32,6 +32,15 @@ public static class NumberToHeatTransferCoefficientExtensions public static HeatTransferCoefficient BtusPerHourSquareFootDegreeFahrenheit(this T value) => HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(Convert.ToDouble(value)); + /// + [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + public static HeatTransferCoefficient BtusPerSquareFootDegreeFahrenheit(this T value) => + HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(Convert.ToDouble(value)); + + /// + public static HeatTransferCoefficient CaloriesPerHourSquareMeterDegreeCelsius(this T value) => + HeatTransferCoefficient.FromCaloriesPerHourSquareMeterDegreeCelsius(Convert.ToDouble(value)); + /// public static HeatTransferCoefficient KilocaloriesPerHourSquareMeterDegreeCelsius(this T value) => HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(Convert.ToDouble(value)); diff --git a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs index fa31819c61..ab1846a381 100644 --- a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs +++ b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs @@ -31,6 +31,8 @@ public class HeatTransferCoefficientTests : HeatTransferCoefficientTestsBase protected override double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin => 1; protected override double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin => 1; protected override double BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin => 1.7611018368230584e-1; - protected override double KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin => 8.6042065009560229e-1; + protected override double KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin => 0.859845227859; + protected override double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin => 1.7611018368230584e-1; + protected override double CaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin => 859.845227859; } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index 2dec850615..565a16cc33 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -39,12 +39,16 @@ namespace UnitsNet.Tests public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBase { protected abstract double BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin { get; } + protected abstract double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin { get; } + protected abstract double CaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin { get; } protected abstract double KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin { get; } protected abstract double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin { get; } protected abstract double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin { get; } // ReSharper disable VirtualMemberNeverOverriden.Global protected virtual double BtusPerHourSquareFootDegreeFahrenheitTolerance { get { return 1e-5; } } + protected virtual double BtusPerSquareFootDegreeFahrenheitTolerance { get { return 1e-5; } } + protected virtual double CaloriesPerHourSquareMeterDegreeCelsiusTolerance { get { return 1e-5; } } protected virtual double KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance { get { return 1e-5; } } protected virtual double WattsPerSquareMeterCelsiusTolerance { get { return 1e-5; } } protected virtual double WattsPerSquareMeterKelvinTolerance { get { return 1e-5; } } @@ -55,6 +59,8 @@ public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBa return unit switch { HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit => (BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, BtusPerHourSquareFootDegreeFahrenheitTolerance), + HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit => (BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, BtusPerSquareFootDegreeFahrenheitTolerance), + HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius => (CaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, CaloriesPerHourSquareMeterDegreeCelsiusTolerance), HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius => (KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance), HeatTransferCoefficientUnit.WattPerSquareMeterCelsius => (WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, WattsPerSquareMeterCelsiusTolerance), HeatTransferCoefficientUnit.WattPerSquareMeterKelvin => (WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance), @@ -65,6 +71,8 @@ public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBa public static IEnumerable UnitTypes = new List { new object[] { HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit }, + new object[] { HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit }, + new object[] { HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius }, new object[] { HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius }, new object[] { HeatTransferCoefficientUnit.WattPerSquareMeterCelsius }, new object[] { HeatTransferCoefficientUnit.WattPerSquareMeterKelvin }, @@ -131,6 +139,8 @@ public void WattPerSquareMeterKelvinToHeatTransferCoefficientUnits() { HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); AssertEx.EqualTolerance(BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(CaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); @@ -143,17 +153,25 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity00.BtusPerHourSquareFootDegreeFahrenheit, BtusPerHourSquareFootDegreeFahrenheitTolerance); Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, quantity00.Unit); - var quantity01 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); - AssertEx.EqualTolerance(1, quantity01.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, quantity01.Unit); + var quantity01 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + AssertEx.EqualTolerance(1, quantity01.BtusPerSquareFootDegreeFahrenheit, BtusPerSquareFootDegreeFahrenheitTolerance); + Assert.Equal(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, quantity01.Unit); - var quantity02 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius); - AssertEx.EqualTolerance(1, quantity02.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity02.Unit); + var quantity02 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius); + AssertEx.EqualTolerance(1, quantity02.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, quantity02.Unit); - var quantity03 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin); - AssertEx.EqualTolerance(1, quantity03.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity03.Unit); + var quantity03 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius); + AssertEx.EqualTolerance(1, quantity03.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, quantity03.Unit); + + var quantity04 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius); + AssertEx.EqualTolerance(1, quantity04.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity04.Unit); + + var quantity05 = HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin); + AssertEx.EqualTolerance(1, quantity05.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); + Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity05.Unit); } @@ -175,6 +193,8 @@ public void As() { var wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); AssertEx.EqualTolerance(BtusPerHourSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit), BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit), BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(CaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius), CaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterDegreeCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius), KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius), WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), WattsPerSquareMeterKelvinTolerance); @@ -231,27 +251,55 @@ public void Parse() try { var parsed = HeatTransferCoefficient.Parse("1 kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = HeatTransferCoefficient.Parse("1 kkcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { - var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); + var parsed = HeatTransferCoefficient.Parse("1 kkcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { - var parsed = HeatTransferCoefficient.Parse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); + var parsed = HeatTransferCoefficient.Parse("1 kkcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { - var parsed = HeatTransferCoefficient.Parse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); + var parsed = HeatTransferCoefficient.Parse("1 kkcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -301,24 +349,48 @@ public void TryParse() { Assert.True(HeatTransferCoefficient.TryParse("1 kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.CaloriesPerHourSquareMeterDegreeCelsius, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); + } + + { + Assert.True(HeatTransferCoefficient.TryParse("1 kkcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } { - Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(HeatTransferCoefficient.TryParse("1 kkcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } { - Assert.True(HeatTransferCoefficient.TryParse("1 kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(HeatTransferCoefficient.TryParse("1 kkcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } { - Assert.True(HeatTransferCoefficient.TryParse("1 kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(HeatTransferCoefficient.TryParse("1 kkcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeterDegreeCelsius, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsed.Unit); } @@ -367,24 +439,48 @@ public void ParseUnit() try { var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -427,21 +523,41 @@ public void TryParseUnit() { Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } { Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } { Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } { Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/h·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/m²·h·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/hr·m²·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); + } + + { + Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/m²·hr·°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); } @@ -504,6 +620,8 @@ public void ConversionRoundTrip() { HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(wattpersquaremeterkelvin.BtusPerHourSquareFootDegreeFahrenheit).WattsPerSquareMeterKelvin, BtusPerHourSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(wattpersquaremeterkelvin.BtusPerSquareFootDegreeFahrenheit).WattsPerSquareMeterKelvin, BtusPerSquareFootDegreeFahrenheitTolerance); + AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromCaloriesPerHourSquareMeterDegreeCelsius(wattpersquaremeterkelvin.CaloriesPerHourSquareMeterDegreeCelsius).WattsPerSquareMeterKelvin, CaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromKilocaloriesPerHourSquareMeterDegreeCelsius(wattpersquaremeterkelvin.KilocaloriesPerHourSquareMeterDegreeCelsius).WattsPerSquareMeterKelvin, KilocaloriesPerHourSquareMeterDegreeCelsiusTolerance); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterCelsius(wattpersquaremeterkelvin.WattsPerSquareMeterCelsius).WattsPerSquareMeterKelvin, WattsPerSquareMeterCelsiusTolerance); AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(wattpersquaremeterkelvin.WattsPerSquareMeterKelvin).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); @@ -655,7 +773,9 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { Assert.Equal("1 Btu/h·ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit).ToString()); - Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString()); + Assert.Equal("1 Btu/ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit).ToString()); + Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius).ToString()); + Assert.Equal("1 kkcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString()); Assert.Equal("1 W/m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius).ToString()); Assert.Equal("1 W/m²·K", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin).ToString()); } @@ -672,7 +792,9 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); Assert.Equal("1 Btu/h·ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit).ToString(swedishCulture)); - Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString(swedishCulture)); + Assert.Equal("1 Btu/ft²·°F", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit).ToString(swedishCulture)); + Assert.Equal("1 kcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius).ToString(swedishCulture)); + Assert.Equal("1 kkcal/h·m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius).ToString(swedishCulture)); Assert.Equal("1 W/m²·°C", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius).ToString(swedishCulture)); Assert.Equal("1 W/m²·K", new HeatTransferCoefficient(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin).ToString(swedishCulture)); } diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 92e50b3549..a584a9dc94 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -60,6 +60,8 @@ static HeatTransferCoefficient() new UnitInfo[] { new UnitInfo(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "BtusPerHourSquareFootDegreeFahrenheit", BaseUnits.Undefined), + new UnitInfo(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, "BtusPerSquareFootDegreeFahrenheit", BaseUnits.Undefined), + new UnitInfo(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, "CaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined), new UnitInfo(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "KilocaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined), new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattsPerSquareMeterCelsius", BaseUnits.Undefined), new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattsPerSquareMeterKelvin", BaseUnits.Undefined), @@ -171,6 +173,17 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) /// public double BtusPerHourSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); + /// + /// Gets a value of this quantity converted into + /// + [Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + public double BtusPerSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + + /// + /// Gets a value of this quantity converted into + /// + public double CaloriesPerHourSquareMeterDegreeCelsius => As(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius); + /// /// Gets a value of this quantity converted into /// @@ -198,6 +211,8 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: HeatTransferCoefficientUnit -> BaseUnit unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); @@ -206,6 +221,8 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) // Register in unit converter: BaseUnit -> HeatTransferCoefficientUnit unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit)); + unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)); unitConverter.SetConversionFunction(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, quantity => quantity.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)); } @@ -213,7 +230,9 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) { unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, new CultureInfo("en-US"), false, true, new string[]{"Btu/h·ft²·°F", "Btu/ft²·h·°F", "Btu/hr·ft²·°F", "Btu/ft²·hr·°F"}); - unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, new CultureInfo("en-US"), false, true, new string[]{"kcal/h·m²·°C", "kcal/m²·h·°C", "kcal/hr·m²·°C", "kcal/m²·hr·°C"}); + unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, new CultureInfo("en-US"), false, true, new string[]{"Btu/ft²·°F"}); + unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, new CultureInfo("en-US"), false, true, new string[]{"kcal/h·m²·°C", "kcal/m²·h·°C", "kcal/hr·m²·°C", "kcal/m²·hr·°C"}); + unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, new CultureInfo("en-US"), false, true, new string[]{"kkcal/h·m²·°C", "kkcal/m²·h·°C", "kkcal/hr·m²·°C", "kkcal/m²·hr·°C"}); unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, new CultureInfo("en-US"), false, true, new string[]{"W/m²·°C"}); unitAbbreviationsCache.PerformAbbreviationMapping(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, new CultureInfo("en-US"), false, true, new string[]{"W/m²·K"}); } @@ -253,6 +272,27 @@ public static HeatTransferCoefficient FromBtusPerHourSquareFootDegreeFahrenheit( return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(QuantityValue btuspersquarefootdegreefahrenheit) + { + double value = (double) btuspersquarefootdegreefahrenheit; + return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static HeatTransferCoefficient FromCaloriesPerHourSquareMeterDegreeCelsius(QuantityValue caloriesperhoursquaremeterdegreecelsius) + { + double value = (double) caloriesperhoursquaremeterdegreecelsius; + return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius); + } + /// /// Creates a from . /// @@ -750,12 +790,16 @@ private bool TryToUnit(HeatTransferCoefficientUnit unit, [NotNullWhen(true)] out { // HeatTransferCoefficientUnit -> BaseUnit (HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value * 5.6782633411134878, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), - (HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient((_value * 4184) / 3600, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), + (HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value * 5.6782633411134878, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), + (HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient((_value * 4.1868) / 3600, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), + (HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(((_value * 4.1868) / 3600) * 1e3d, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), (HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin) => new HeatTransferCoefficient(_value, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), // BaseUnit -> HeatTransferCoefficientUnit (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit) => new HeatTransferCoefficient(_value / 5.6782633411134878, HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit), - (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius) => new HeatTransferCoefficient((_value / 4184) * 3600, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius), + (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit) => new HeatTransferCoefficient(_value / 5.6782633411134878, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit), + (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius) => new HeatTransferCoefficient((_value / 4.1868) * 3600, HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius), + (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius) => new HeatTransferCoefficient(((_value / 4.1868) * 3600) / 1e3d, HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius), (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius) => new HeatTransferCoefficient(_value, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius), _ => null diff --git a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index d19a94cb83..4c8b3da7cd 100644 --- a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -26,6 +26,9 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { BtuPerHourSquareFootDegreeFahrenheit = 11, + [System.Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + BtuPerSquareFootDegreeFahrenheit = 1, + CaloriePerHourSquareMeterDegreeCelsius = 5, KilocaloriePerHourSquareMeterDegreeCelsius = 8, WattPerSquareMeterCelsius = 2, WattPerSquareMeterKelvin = 3, From fd7661027b53e19d8b80bc9136b42cb22e8ea615 Mon Sep 17 00:00:00 2001 From: David Casaseca Date: Tue, 14 Feb 2023 09:33:05 -0500 Subject: [PATCH 7/8] Missing using directive --- .../NumberToHeatTransferCoefficientExtensionsTest.g.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs index e43998fec0..e4b2eacf79 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs @@ -17,6 +17,7 @@ // 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.NumberExtensions.NumberToHeatTransferCoefficient; using Xunit; @@ -29,6 +30,7 @@ public void NumberToBtusPerHourSquareFootDegreeFahrenheitTest() => Assert.Equal(HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(2), 2.BtusPerHourSquareFootDegreeFahrenheit()); [Fact] + [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public void NumberToBtusPerSquareFootDegreeFahrenheitTest() => Assert.Equal(HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(2), 2.BtusPerSquareFootDegreeFahrenheit()); From 38452a7eb015f99b8b3326da67906bed60feb65f Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Wed, 15 Feb 2023 16:59:19 +0100 Subject: [PATCH 8/8] Fix build error, remove obsolete attribute in generated test case There is no reason to annotate generated test methods with obsolete attributes. Only the types and methods related to the implementation of the unit needs it, not tests. --- .../UnitsNetGen/NumberExtensionsTestClassGenerator.cs | 7 ------- .../GeneratedCode/Quantities/HeatTransferCoefficient.g.cs | 4 ++-- .../GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs | 2 +- .../NumberToHeatTransferCoefficientExtensionsTest.g.cs | 4 +--- .../NumberToHeatTransferCoefficientExtensions.g.cs | 2 +- .../GeneratedCode/Quantities/HeatTransferCoefficient.g.cs | 4 ++-- .../GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs | 2 +- 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs index d272d23ebc..b5cced30fd 100644 --- a/CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs @@ -38,8 +38,6 @@ public class NumberTo{_quantityName}ExtensionsTests Writer.WL(2, $@" [Fact]"); - Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText)); - Writer.WL(2, $@"public void NumberTo{unit.PluralName}Test() => Assert.Equal({_quantityName}.From{unit.PluralName}(2), 2.{unit.PluralName}()); "); @@ -49,10 +47,5 @@ public class NumberTo{_quantityName}ExtensionsTests }"); return Writer.ToString(); } - - private static string? GetObsoleteAttributeOrNull(string? obsoleteText) => - string.IsNullOrWhiteSpace(obsoleteText) ? - null : - $"[Obsolete(\"{obsoleteText}\")]"; } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 979123176b..5330ee5a83 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -87,7 +87,7 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// /// Gets a value of this quantity converted into /// - [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public double BtusPerSquareFootDegreeFahrenheit => As(HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); /// @@ -124,7 +124,7 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// Creates a from . /// /// If value is NaN or Infinity. - [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(double btuspersquarefootdegreefahrenheit) => new HeatTransferCoefficient(btuspersquarefootdegreefahrenheit, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit); /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index 4c8b3da7cd..beaabc3f3b 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -26,7 +26,7 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { BtuPerHourSquareFootDegreeFahrenheit = 11, - [System.Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [System.Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] BtuPerSquareFootDegreeFahrenheit = 1, CaloriePerHourSquareMeterDegreeCelsius = 5, KilocaloriePerHourSquareMeterDegreeCelsius = 8, diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs index e4b2eacf79..9f317e64d2 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToHeatTransferCoefficientExtensionsTest.g.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -17,7 +17,6 @@ // 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.NumberExtensions.NumberToHeatTransferCoefficient; using Xunit; @@ -30,7 +29,6 @@ public void NumberToBtusPerHourSquareFootDegreeFahrenheitTest() => Assert.Equal(HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(2), 2.BtusPerHourSquareFootDegreeFahrenheit()); [Fact] - [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public void NumberToBtusPerSquareFootDegreeFahrenheitTest() => Assert.Equal(HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(2), 2.BtusPerSquareFootDegreeFahrenheit()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs index 9184523f66..81575bbcda 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToHeatTransferCoefficientExtensions.g.cs @@ -33,7 +33,7 @@ public static HeatTransferCoefficient BtusPerHourSquareFootDegreeFahrenheit(t HeatTransferCoefficient.FromBtusPerHourSquareFootDegreeFahrenheit(Convert.ToDouble(value)); /// - [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public static HeatTransferCoefficient BtusPerSquareFootDegreeFahrenheit(this T value) => HeatTransferCoefficient.FromBtusPerSquareFootDegreeFahrenheit(Convert.ToDouble(value)); diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index a584a9dc94..2574b8dc77 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -276,7 +276,7 @@ public static HeatTransferCoefficient FromBtusPerHourSquareFootDegreeFahrenheit( /// Creates a from . /// /// If value is NaN or Infinity. - [Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] public static HeatTransferCoefficient FromBtusPerSquareFootDegreeFahrenheit(QuantityValue btuspersquarefootdegreefahrenheit) { double value = (double) btuspersquarefootdegreefahrenheit; diff --git a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs index 4c8b3da7cd..beaabc3f3b 100644 --- a/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/HeatTransferCoefficientUnit.g.cs @@ -26,7 +26,7 @@ namespace UnitsNet.Units public enum HeatTransferCoefficientUnit { BtuPerHourSquareFootDegreeFahrenheit = 11, - [System.Obsolete("The name of this definition incorrectly omitted the hours as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] + [System.Obsolete("The name of this definition incorrectly omitted time as divisor, please use BtuPerHourSquareFootDegreeFahrenheit instead")] BtuPerSquareFootDegreeFahrenheit = 1, CaloriePerHourSquareMeterDegreeCelsius = 5, KilocaloriePerHourSquareMeterDegreeCelsius = 8,