From ce9edcff7750df00a2516e1a59dbadcbaad12a2c Mon Sep 17 00:00:00 2001 From: Conrad Date: Fri, 2 Jun 2023 00:06:54 -0400 Subject: [PATCH] Added Imperial Quart --- Common/UnitDefinitions/Volume.json | 14 +- Common/UnitEnumValues.g.json | 3 +- .../GeneratedCode/Quantities/Volume.g.cs | 13 ++ .../GeneratedCode/Units/VolumeUnit.g.cs | 1 + .../NumberToVolumeExtensionsTest.g.cs | 4 + .../NumberToVolumeExtensions.g.cs | 4 + UnitsNet.Tests/CustomCode/VolumeTests.cs | 5 + .../TestsBase/VolumeTestsBase.g.cs | 193 +++++++++++------- .../Quantities/Acceleration.g.cs | 2 +- UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 21 ++ UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs | 1 + 11 files changed, 180 insertions(+), 81 deletions(-) diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index 8619623831..e5ab2458ae 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -78,7 +78,7 @@ } ] }, - { + { "SingularName": "CubicDecimeter", "PluralName": "CubicDecimeters", "FromUnitToBaseFunc": "{x} / 1e3", @@ -461,6 +461,18 @@ } ] }, + { + "SingularName": "ImperialQuart", + "PluralName": "ImperialQuarts", + "FromUnitToBaseFunc": "{x} * 1.1365225e-3", + "FromBaseToUnitFunc": "{x} / 1.1365225e-3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "qt (imp.)" ] + } + ] + }, { "SingularName": "UsPint", "PluralName": "UsPints", diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 6583a221f6..972493a759 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1556,7 +1556,8 @@ "UsQuart": 50, "UsTablespoon": 51, "UsTeaspoon": 52, - "Nanoliter": 53 + "Nanoliter": 53, + "ImperialQuart": 57 }, "VolumeConcentration": { "CentilitersPerLiter": 1, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs index df331816a4..294afc745e 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs @@ -214,6 +214,11 @@ public Volume(double value, VolumeUnit unit) /// public double ImperialPints => As(VolumeUnit.ImperialPint); + /// + /// Gets a value of this quantity converted into + /// + public double ImperialQuarts => As(VolumeUnit.ImperialQuart); + /// /// Gets a value of this quantity converted into /// @@ -510,6 +515,12 @@ public Volume(double value, VolumeUnit unit) /// If value is NaN or Infinity. public static Volume FromImperialPints(double imperialpints) => new Volume(imperialpints, VolumeUnit.ImperialPint); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Volume FromImperialQuarts(double imperialquarts) => new Volume(imperialquarts, VolumeUnit.ImperialQuart); + /// /// Creates a from . /// @@ -733,6 +744,7 @@ private double GetValueInBaseUnit() VolumeUnit.ImperialGallon => _value * 0.00454609, VolumeUnit.ImperialOunce => _value * 2.8413062499962901241875439064617e-5, VolumeUnit.ImperialPint => _value * 5.6826125e-4, + VolumeUnit.ImperialQuart => _value * 1.1365225e-3, VolumeUnit.KilocubicFoot => (_value * 2.8316846592e-2) * 1e3d, VolumeUnit.KilocubicMeter => (_value) * 1e3d, VolumeUnit.KiloimperialGallon => (_value * 0.00454609) * 1e3d, @@ -799,6 +811,7 @@ private double GetValueAs(VolumeUnit unit) VolumeUnit.ImperialGallon => baseUnitValue / 0.00454609, VolumeUnit.ImperialOunce => baseUnitValue / 2.8413062499962901241875439064617e-5, VolumeUnit.ImperialPint => baseUnitValue / 5.6826125e-4, + VolumeUnit.ImperialQuart => baseUnitValue / 1.1365225e-3, VolumeUnit.KilocubicFoot => (baseUnitValue / 2.8316846592e-2) / 1e3d, VolumeUnit.KilocubicMeter => (baseUnitValue) / 1e3d, VolumeUnit.KiloimperialGallon => (baseUnitValue / 0.00454609) / 1e3d, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs index 9cabb3b9f8..c35715428b 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs @@ -57,6 +57,7 @@ public enum VolumeUnit ImperialGallon = 25, ImperialOunce = 26, ImperialPint = 27, + ImperialQuart = 57, KilocubicFoot = 28, KilocubicMeter = 29, KiloimperialGallon = 30, diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs index 2f403381b2..b8450bdd38 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs @@ -132,6 +132,10 @@ public void NumberToImperialOuncesTest() => public void NumberToImperialPintsTest() => Assert.Equal(Volume.FromImperialPints(2), 2.ImperialPints()); + [Fact] + public void NumberToImperialQuartsTest() => + Assert.Equal(Volume.FromImperialQuarts(2), 2.ImperialQuarts()); + [Fact] public void NumberToKilocubicFeetTest() => Assert.Equal(Volume.FromKilocubicFeet(2), 2.KilocubicFeet()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs index 75b18801fe..17bad109c4 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs @@ -136,6 +136,10 @@ public static Volume ImperialOunces(this T value) => public static Volume ImperialPints(this T value) => Volume.FromImperialPints(Convert.ToDouble(value)); + /// + public static Volume ImperialQuarts(this T value) => + Volume.FromImperialQuarts(Convert.ToDouble(value)); + /// public static Volume KilocubicFeet(this T value) => Volume.FromKilocubicFeet(Convert.ToDouble(value)); diff --git a/UnitsNet.Tests/CustomCode/VolumeTests.cs b/UnitsNet.Tests/CustomCode/VolumeTests.cs index e55d7ef463..17cb52f922 100644 --- a/UnitsNet.Tests/CustomCode/VolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeTests.cs @@ -106,6 +106,11 @@ public class VolumeTests : VolumeTestsBase protected override double DecalitersInOneCubicMeter => 1e2; + /// + /// https://www.legislation.gov.uk/uksi/1995/1804/made + /// + protected override double ImperialQuartsInOneCubicMeter => 879.876993196; + [Fact] public void VolumeDividedByAreaEqualsLength() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index af0271bb30..d1252a6a5d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -65,6 +65,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase protected abstract double ImperialGallonsInOneCubicMeter { get; } protected abstract double ImperialOuncesInOneCubicMeter { get; } protected abstract double ImperialPintsInOneCubicMeter { get; } + protected abstract double ImperialQuartsInOneCubicMeter { get; } protected abstract double KilocubicFeetInOneCubicMeter { get; } protected abstract double KilocubicMetersInOneCubicMeter { get; } protected abstract double KiloimperialGallonsInOneCubicMeter { get; } @@ -120,6 +121,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase protected virtual double ImperialGallonsTolerance { get { return 1e-5; } } protected virtual double ImperialOuncesTolerance { get { return 1e-5; } } protected virtual double ImperialPintsTolerance { get { return 1e-5; } } + protected virtual double ImperialQuartsTolerance { get { return 1e-5; } } protected virtual double KilocubicFeetTolerance { get { return 1e-5; } } protected virtual double KilocubicMetersTolerance { get { return 1e-5; } } protected virtual double KiloimperialGallonsTolerance { get { return 1e-5; } } @@ -179,6 +181,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase VolumeUnit.ImperialGallon => (ImperialGallonsInOneCubicMeter, ImperialGallonsTolerance), VolumeUnit.ImperialOunce => (ImperialOuncesInOneCubicMeter, ImperialOuncesTolerance), VolumeUnit.ImperialPint => (ImperialPintsInOneCubicMeter, ImperialPintsTolerance), + VolumeUnit.ImperialQuart => (ImperialQuartsInOneCubicMeter, ImperialQuartsTolerance), VolumeUnit.KilocubicFoot => (KilocubicFeetInOneCubicMeter, KilocubicFeetTolerance), VolumeUnit.KilocubicMeter => (KilocubicMetersInOneCubicMeter, KilocubicMetersTolerance), VolumeUnit.KiloimperialGallon => (KiloimperialGallonsInOneCubicMeter, KiloimperialGallonsTolerance), @@ -238,6 +241,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase new object[] { VolumeUnit.ImperialGallon }, new object[] { VolumeUnit.ImperialOunce }, new object[] { VolumeUnit.ImperialPint }, + new object[] { VolumeUnit.ImperialQuart }, new object[] { VolumeUnit.KilocubicFoot }, new object[] { VolumeUnit.KilocubicMeter }, new object[] { VolumeUnit.KiloimperialGallon }, @@ -353,6 +357,7 @@ public void CubicMeterToVolumeUnits() AssertEx.EqualTolerance(ImperialGallonsInOneCubicMeter, cubicmeter.ImperialGallons, ImperialGallonsTolerance); AssertEx.EqualTolerance(ImperialOuncesInOneCubicMeter, cubicmeter.ImperialOunces, ImperialOuncesTolerance); AssertEx.EqualTolerance(ImperialPintsInOneCubicMeter, cubicmeter.ImperialPints, ImperialPintsTolerance); + AssertEx.EqualTolerance(ImperialQuartsInOneCubicMeter, cubicmeter.ImperialQuarts, ImperialQuartsTolerance); AssertEx.EqualTolerance(KilocubicFeetInOneCubicMeter, cubicmeter.KilocubicFeet, KilocubicFeetTolerance); AssertEx.EqualTolerance(KilocubicMetersInOneCubicMeter, cubicmeter.KilocubicMeters, KilocubicMetersTolerance); AssertEx.EqualTolerance(KiloimperialGallonsInOneCubicMeter, cubicmeter.KiloimperialGallons, KiloimperialGallonsTolerance); @@ -492,109 +497,113 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity26.ImperialPints, ImperialPintsTolerance); Assert.Equal(VolumeUnit.ImperialPint, quantity26.Unit); - var quantity27 = Volume.From(1, VolumeUnit.KilocubicFoot); - AssertEx.EqualTolerance(1, quantity27.KilocubicFeet, KilocubicFeetTolerance); - Assert.Equal(VolumeUnit.KilocubicFoot, quantity27.Unit); + var quantity27 = Volume.From(1, VolumeUnit.ImperialQuart); + AssertEx.EqualTolerance(1, quantity27.ImperialQuarts, ImperialQuartsTolerance); + Assert.Equal(VolumeUnit.ImperialQuart, quantity27.Unit); - var quantity28 = Volume.From(1, VolumeUnit.KilocubicMeter); - AssertEx.EqualTolerance(1, quantity28.KilocubicMeters, KilocubicMetersTolerance); - Assert.Equal(VolumeUnit.KilocubicMeter, quantity28.Unit); + var quantity28 = Volume.From(1, VolumeUnit.KilocubicFoot); + AssertEx.EqualTolerance(1, quantity28.KilocubicFeet, KilocubicFeetTolerance); + Assert.Equal(VolumeUnit.KilocubicFoot, quantity28.Unit); - var quantity29 = Volume.From(1, VolumeUnit.KiloimperialGallon); - AssertEx.EqualTolerance(1, quantity29.KiloimperialGallons, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, quantity29.Unit); + var quantity29 = Volume.From(1, VolumeUnit.KilocubicMeter); + AssertEx.EqualTolerance(1, quantity29.KilocubicMeters, KilocubicMetersTolerance); + Assert.Equal(VolumeUnit.KilocubicMeter, quantity29.Unit); - var quantity30 = Volume.From(1, VolumeUnit.Kiloliter); - AssertEx.EqualTolerance(1, quantity30.Kiloliters, KilolitersTolerance); - Assert.Equal(VolumeUnit.Kiloliter, quantity30.Unit); + var quantity30 = Volume.From(1, VolumeUnit.KiloimperialGallon); + AssertEx.EqualTolerance(1, quantity30.KiloimperialGallons, KiloimperialGallonsTolerance); + Assert.Equal(VolumeUnit.KiloimperialGallon, quantity30.Unit); - var quantity31 = Volume.From(1, VolumeUnit.KilousGallon); - AssertEx.EqualTolerance(1, quantity31.KilousGallons, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, quantity31.Unit); + var quantity31 = Volume.From(1, VolumeUnit.Kiloliter); + AssertEx.EqualTolerance(1, quantity31.Kiloliters, KilolitersTolerance); + Assert.Equal(VolumeUnit.Kiloliter, quantity31.Unit); - var quantity32 = Volume.From(1, VolumeUnit.Liter); - AssertEx.EqualTolerance(1, quantity32.Liters, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, quantity32.Unit); + var quantity32 = Volume.From(1, VolumeUnit.KilousGallon); + AssertEx.EqualTolerance(1, quantity32.KilousGallons, KilousGallonsTolerance); + Assert.Equal(VolumeUnit.KilousGallon, quantity32.Unit); - var quantity33 = Volume.From(1, VolumeUnit.MegacubicFoot); - AssertEx.EqualTolerance(1, quantity33.MegacubicFeet, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, quantity33.Unit); + var quantity33 = Volume.From(1, VolumeUnit.Liter); + AssertEx.EqualTolerance(1, quantity33.Liters, LitersTolerance); + Assert.Equal(VolumeUnit.Liter, quantity33.Unit); - var quantity34 = Volume.From(1, VolumeUnit.MegaimperialGallon); - AssertEx.EqualTolerance(1, quantity34.MegaimperialGallons, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, quantity34.Unit); + var quantity34 = Volume.From(1, VolumeUnit.MegacubicFoot); + AssertEx.EqualTolerance(1, quantity34.MegacubicFeet, MegacubicFeetTolerance); + Assert.Equal(VolumeUnit.MegacubicFoot, quantity34.Unit); - var quantity35 = Volume.From(1, VolumeUnit.Megaliter); - AssertEx.EqualTolerance(1, quantity35.Megaliters, MegalitersTolerance); - Assert.Equal(VolumeUnit.Megaliter, quantity35.Unit); + var quantity35 = Volume.From(1, VolumeUnit.MegaimperialGallon); + AssertEx.EqualTolerance(1, quantity35.MegaimperialGallons, MegaimperialGallonsTolerance); + Assert.Equal(VolumeUnit.MegaimperialGallon, quantity35.Unit); - var quantity36 = Volume.From(1, VolumeUnit.MegausGallon); - AssertEx.EqualTolerance(1, quantity36.MegausGallons, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, quantity36.Unit); + var quantity36 = Volume.From(1, VolumeUnit.Megaliter); + AssertEx.EqualTolerance(1, quantity36.Megaliters, MegalitersTolerance); + Assert.Equal(VolumeUnit.Megaliter, quantity36.Unit); - var quantity37 = Volume.From(1, VolumeUnit.MetricCup); - AssertEx.EqualTolerance(1, quantity37.MetricCups, MetricCupsTolerance); - Assert.Equal(VolumeUnit.MetricCup, quantity37.Unit); + var quantity37 = Volume.From(1, VolumeUnit.MegausGallon); + AssertEx.EqualTolerance(1, quantity37.MegausGallons, MegausGallonsTolerance); + Assert.Equal(VolumeUnit.MegausGallon, quantity37.Unit); - var quantity38 = Volume.From(1, VolumeUnit.MetricTeaspoon); - AssertEx.EqualTolerance(1, quantity38.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, quantity38.Unit); + var quantity38 = Volume.From(1, VolumeUnit.MetricCup); + AssertEx.EqualTolerance(1, quantity38.MetricCups, MetricCupsTolerance); + Assert.Equal(VolumeUnit.MetricCup, quantity38.Unit); - var quantity39 = Volume.From(1, VolumeUnit.Microliter); - AssertEx.EqualTolerance(1, quantity39.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, quantity39.Unit); + var quantity39 = Volume.From(1, VolumeUnit.MetricTeaspoon); + AssertEx.EqualTolerance(1, quantity39.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, quantity39.Unit); - var quantity40 = Volume.From(1, VolumeUnit.Milliliter); - AssertEx.EqualTolerance(1, quantity40.Milliliters, MillilitersTolerance); - Assert.Equal(VolumeUnit.Milliliter, quantity40.Unit); + var quantity40 = Volume.From(1, VolumeUnit.Microliter); + AssertEx.EqualTolerance(1, quantity40.Microliters, MicrolitersTolerance); + Assert.Equal(VolumeUnit.Microliter, quantity40.Unit); - var quantity41 = Volume.From(1, VolumeUnit.Nanoliter); - AssertEx.EqualTolerance(1, quantity41.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, quantity41.Unit); + var quantity41 = Volume.From(1, VolumeUnit.Milliliter); + AssertEx.EqualTolerance(1, quantity41.Milliliters, MillilitersTolerance); + Assert.Equal(VolumeUnit.Milliliter, quantity41.Unit); - var quantity42 = Volume.From(1, VolumeUnit.OilBarrel); - AssertEx.EqualTolerance(1, quantity42.OilBarrels, OilBarrelsTolerance); - Assert.Equal(VolumeUnit.OilBarrel, quantity42.Unit); + var quantity42 = Volume.From(1, VolumeUnit.Nanoliter); + AssertEx.EqualTolerance(1, quantity42.Nanoliters, NanolitersTolerance); + Assert.Equal(VolumeUnit.Nanoliter, quantity42.Unit); - var quantity43 = Volume.From(1, VolumeUnit.UkTablespoon); - AssertEx.EqualTolerance(1, quantity43.UkTablespoons, UkTablespoonsTolerance); - Assert.Equal(VolumeUnit.UkTablespoon, quantity43.Unit); + var quantity43 = Volume.From(1, VolumeUnit.OilBarrel); + AssertEx.EqualTolerance(1, quantity43.OilBarrels, OilBarrelsTolerance); + Assert.Equal(VolumeUnit.OilBarrel, quantity43.Unit); - var quantity44 = Volume.From(1, VolumeUnit.UsBeerBarrel); - AssertEx.EqualTolerance(1, quantity44.UsBeerBarrels, UsBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.UsBeerBarrel, quantity44.Unit); + var quantity44 = Volume.From(1, VolumeUnit.UkTablespoon); + AssertEx.EqualTolerance(1, quantity44.UkTablespoons, UkTablespoonsTolerance); + Assert.Equal(VolumeUnit.UkTablespoon, quantity44.Unit); - var quantity45 = Volume.From(1, VolumeUnit.UsCustomaryCup); - AssertEx.EqualTolerance(1, quantity45.UsCustomaryCups, UsCustomaryCupsTolerance); - Assert.Equal(VolumeUnit.UsCustomaryCup, quantity45.Unit); + var quantity45 = Volume.From(1, VolumeUnit.UsBeerBarrel); + AssertEx.EqualTolerance(1, quantity45.UsBeerBarrels, UsBeerBarrelsTolerance); + Assert.Equal(VolumeUnit.UsBeerBarrel, quantity45.Unit); - var quantity46 = Volume.From(1, VolumeUnit.UsGallon); - AssertEx.EqualTolerance(1, quantity46.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, quantity46.Unit); + var quantity46 = Volume.From(1, VolumeUnit.UsCustomaryCup); + AssertEx.EqualTolerance(1, quantity46.UsCustomaryCups, UsCustomaryCupsTolerance); + Assert.Equal(VolumeUnit.UsCustomaryCup, quantity46.Unit); - var quantity47 = Volume.From(1, VolumeUnit.UsLegalCup); - AssertEx.EqualTolerance(1, quantity47.UsLegalCups, UsLegalCupsTolerance); - Assert.Equal(VolumeUnit.UsLegalCup, quantity47.Unit); + var quantity47 = Volume.From(1, VolumeUnit.UsGallon); + AssertEx.EqualTolerance(1, quantity47.UsGallons, UsGallonsTolerance); + Assert.Equal(VolumeUnit.UsGallon, quantity47.Unit); - var quantity48 = Volume.From(1, VolumeUnit.UsOunce); - AssertEx.EqualTolerance(1, quantity48.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, quantity48.Unit); + var quantity48 = Volume.From(1, VolumeUnit.UsLegalCup); + AssertEx.EqualTolerance(1, quantity48.UsLegalCups, UsLegalCupsTolerance); + Assert.Equal(VolumeUnit.UsLegalCup, quantity48.Unit); - var quantity49 = Volume.From(1, VolumeUnit.UsPint); - AssertEx.EqualTolerance(1, quantity49.UsPints, UsPintsTolerance); - Assert.Equal(VolumeUnit.UsPint, quantity49.Unit); + var quantity49 = Volume.From(1, VolumeUnit.UsOunce); + AssertEx.EqualTolerance(1, quantity49.UsOunces, UsOuncesTolerance); + Assert.Equal(VolumeUnit.UsOunce, quantity49.Unit); - var quantity50 = Volume.From(1, VolumeUnit.UsQuart); - AssertEx.EqualTolerance(1, quantity50.UsQuarts, UsQuartsTolerance); - Assert.Equal(VolumeUnit.UsQuart, quantity50.Unit); + var quantity50 = Volume.From(1, VolumeUnit.UsPint); + AssertEx.EqualTolerance(1, quantity50.UsPints, UsPintsTolerance); + Assert.Equal(VolumeUnit.UsPint, quantity50.Unit); - var quantity51 = Volume.From(1, VolumeUnit.UsTablespoon); - AssertEx.EqualTolerance(1, quantity51.UsTablespoons, UsTablespoonsTolerance); - Assert.Equal(VolumeUnit.UsTablespoon, quantity51.Unit); + var quantity51 = Volume.From(1, VolumeUnit.UsQuart); + AssertEx.EqualTolerance(1, quantity51.UsQuarts, UsQuartsTolerance); + Assert.Equal(VolumeUnit.UsQuart, quantity51.Unit); - var quantity52 = Volume.From(1, VolumeUnit.UsTeaspoon); - AssertEx.EqualTolerance(1, quantity52.UsTeaspoons, UsTeaspoonsTolerance); - Assert.Equal(VolumeUnit.UsTeaspoon, quantity52.Unit); + var quantity52 = Volume.From(1, VolumeUnit.UsTablespoon); + AssertEx.EqualTolerance(1, quantity52.UsTablespoons, UsTablespoonsTolerance); + Assert.Equal(VolumeUnit.UsTablespoon, quantity52.Unit); + + var quantity53 = Volume.From(1, VolumeUnit.UsTeaspoon); + AssertEx.EqualTolerance(1, quantity53.UsTeaspoons, UsTeaspoonsTolerance); + Assert.Equal(VolumeUnit.UsTeaspoon, quantity53.Unit); } @@ -642,6 +651,7 @@ public void As() AssertEx.EqualTolerance(ImperialGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialGallon), ImperialGallonsTolerance); AssertEx.EqualTolerance(ImperialOuncesInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialOunce), ImperialOuncesTolerance); AssertEx.EqualTolerance(ImperialPintsInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialPint), ImperialPintsTolerance); + AssertEx.EqualTolerance(ImperialQuartsInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialQuart), ImperialQuartsTolerance); AssertEx.EqualTolerance(KilocubicFeetInOneCubicMeter, cubicmeter.As(VolumeUnit.KilocubicFoot), KilocubicFeetTolerance); AssertEx.EqualTolerance(KilocubicMetersInOneCubicMeter, cubicmeter.As(VolumeUnit.KilocubicMeter), KilocubicMetersTolerance); AssertEx.EqualTolerance(KiloimperialGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.KiloimperialGallon), KiloimperialGallonsTolerance); @@ -1096,6 +1106,13 @@ public void Parse() Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 qt (imp.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.ImperialQuarts, ImperialQuartsTolerance); + Assert.Equal(VolumeUnit.ImperialQuart, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 kft³", CultureInfo.GetCultureInfo("en-US")); @@ -1714,6 +1731,12 @@ public void TryParse() Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 qt (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.ImperialQuarts, ImperialQuartsTolerance); + Assert.Equal(VolumeUnit.ImperialQuart, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 kft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilocubicFeet, KilocubicFeetTolerance); @@ -2289,6 +2312,12 @@ public void ParseUnit() Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = Volume.ParseUnit("qt (imp.)", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(VolumeUnit.ImperialQuart, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = Volume.ParseUnit("kft³", CultureInfo.GetCultureInfo("en-US")); @@ -2812,6 +2841,11 @@ public void TryParseUnit() Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); } + { + Assert.True(Volume.TryParseUnit("qt (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(VolumeUnit.ImperialQuart, parsedUnit); + } + { Assert.True(Volume.TryParseUnit("kft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(VolumeUnit.KilocubicFoot, parsedUnit); @@ -3072,6 +3106,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Volume.FromImperialGallons(cubicmeter.ImperialGallons).CubicMeters, ImperialGallonsTolerance); AssertEx.EqualTolerance(1, Volume.FromImperialOunces(cubicmeter.ImperialOunces).CubicMeters, ImperialOuncesTolerance); AssertEx.EqualTolerance(1, Volume.FromImperialPints(cubicmeter.ImperialPints).CubicMeters, ImperialPintsTolerance); + AssertEx.EqualTolerance(1, Volume.FromImperialQuarts(cubicmeter.ImperialQuarts).CubicMeters, ImperialQuartsTolerance); AssertEx.EqualTolerance(1, Volume.FromKilocubicFeet(cubicmeter.KilocubicFeet).CubicMeters, KilocubicFeetTolerance); AssertEx.EqualTolerance(1, Volume.FromKilocubicMeters(cubicmeter.KilocubicMeters).CubicMeters, KilocubicMetersTolerance); AssertEx.EqualTolerance(1, Volume.FromKiloimperialGallons(cubicmeter.KiloimperialGallons).CubicMeters, KiloimperialGallonsTolerance); @@ -3272,6 +3307,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 gal (imp.)", new Volume(1, VolumeUnit.ImperialGallon).ToString()); Assert.Equal("1 oz (imp.)", new Volume(1, VolumeUnit.ImperialOunce).ToString()); Assert.Equal("1 pt (imp.)", new Volume(1, VolumeUnit.ImperialPint).ToString()); + Assert.Equal("1 qt (imp.)", new Volume(1, VolumeUnit.ImperialQuart).ToString()); Assert.Equal("1 kft³", new Volume(1, VolumeUnit.KilocubicFoot).ToString()); Assert.Equal("1 km³", new Volume(1, VolumeUnit.KilocubicMeter).ToString()); Assert.Equal("1 kgal (imp.)", new Volume(1, VolumeUnit.KiloimperialGallon).ToString()); @@ -3338,6 +3374,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 gal (imp.)", new Volume(1, VolumeUnit.ImperialGallon).ToString(swedishCulture)); Assert.Equal("1 oz (imp.)", new Volume(1, VolumeUnit.ImperialOunce).ToString(swedishCulture)); Assert.Equal("1 pt (imp.)", new Volume(1, VolumeUnit.ImperialPint).ToString(swedishCulture)); + Assert.Equal("1 qt (imp.)", new Volume(1, VolumeUnit.ImperialQuart).ToString(swedishCulture)); Assert.Equal("1 kft³", new Volume(1, VolumeUnit.KilocubicFoot).ToString(swedishCulture)); Assert.Equal("1 km³", new Volume(1, VolumeUnit.KilocubicMeter).ToString(swedishCulture)); Assert.Equal("1 kgal (imp.)", new Volume(1, VolumeUnit.KiloimperialGallon).ToString(swedishCulture)); diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 6d6e96aef6..f448e2af59 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -151,7 +151,7 @@ public Acceleration(double value, UnitSystem unitSystem) public static Acceleration AdditiveIdentity => Zero; #endregion - + #region Properties /// diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index c64f46f91a..c752bec0a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -92,6 +92,7 @@ static Volume() new UnitInfo(VolumeUnit.ImperialGallon, "ImperialGallons", BaseUnits.Undefined), new UnitInfo(VolumeUnit.ImperialOunce, "ImperialOunces", BaseUnits.Undefined), new UnitInfo(VolumeUnit.ImperialPint, "ImperialPints", new BaseUnits(length: LengthUnit.Decimeter)), + new UnitInfo(VolumeUnit.ImperialQuart, "ImperialQuarts", BaseUnits.Undefined), new UnitInfo(VolumeUnit.KilocubicFoot, "KilocubicFeet", BaseUnits.Undefined), new UnitInfo(VolumeUnit.KilocubicMeter, "KilocubicMeters", BaseUnits.Undefined), new UnitInfo(VolumeUnit.KiloimperialGallon, "KiloimperialGallons", BaseUnits.Undefined), @@ -356,6 +357,11 @@ public Volume(double value, UnitSystem unitSystem) /// public double ImperialPints => As(VolumeUnit.ImperialPint); + /// + /// Gets a value of this quantity converted into + /// + public double ImperialQuarts => As(VolumeUnit.ImperialQuart); + /// /// Gets a value of this quantity converted into /// @@ -523,6 +529,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(VolumeUnit.ImperialGallon, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.ImperialOunce, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.ImperialPint, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); + unitConverter.SetConversionFunction(VolumeUnit.ImperialQuart, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.KilocubicFoot, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.KilocubicMeter, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.KiloimperialGallon, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); @@ -580,6 +587,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.ImperialGallon, quantity => quantity.ToUnit(VolumeUnit.ImperialGallon)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.ImperialOunce, quantity => quantity.ToUnit(VolumeUnit.ImperialOunce)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.ImperialPint, quantity => quantity.ToUnit(VolumeUnit.ImperialPint)); + unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.ImperialQuart, quantity => quantity.ToUnit(VolumeUnit.ImperialQuart)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.KilocubicFoot, quantity => quantity.ToUnit(VolumeUnit.KilocubicFoot)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.KilocubicMeter, quantity => quantity.ToUnit(VolumeUnit.KilocubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.KiloimperialGallon, quantity => quantity.ToUnit(VolumeUnit.KiloimperialGallon)); @@ -662,6 +670,7 @@ internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbrev unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.ImperialOunce, new CultureInfo("en-US"), false, true, new string[]{"oz (imp.)"}); unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.ImperialOunce, new CultureInfo("ru-RU"), false, true, new string[]{"Английская унция"}); unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.ImperialPint, new CultureInfo("en-US"), false, true, new string[]{"pt (imp.)", "UK pt", "pt", "p"}); + unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.ImperialQuart, new CultureInfo("en-US"), false, true, new string[]{"qt (imp.)"}); unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.KilocubicFoot, new CultureInfo("en-US"), false, true, new string[]{"kft³"}); unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.KilocubicFoot, new CultureInfo("ru-RU"), false, true, new string[]{"кфут³"}); unitAbbreviationsCache.PerformAbbreviationMapping(VolumeUnit.KilocubicMeter, new CultureInfo("en-US"), false, true, new string[]{"km³"}); @@ -1008,6 +1017,16 @@ public static Volume FromImperialPints(QuantityValue imperialpints) return new Volume(value, VolumeUnit.ImperialPint); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Volume FromImperialQuarts(QuantityValue imperialquarts) + { + double value = (double) imperialquarts; + return new Volume(value, VolumeUnit.ImperialQuart); + } + /// /// Creates a from . /// @@ -1787,6 +1806,7 @@ private bool TryToUnit(VolumeUnit unit, [NotNullWhen(true)] out Volume? converte (VolumeUnit.ImperialGallon, VolumeUnit.CubicMeter) => new Volume(_value * 0.00454609, VolumeUnit.CubicMeter), (VolumeUnit.ImperialOunce, VolumeUnit.CubicMeter) => new Volume(_value * 2.8413062499962901241875439064617e-5, VolumeUnit.CubicMeter), (VolumeUnit.ImperialPint, VolumeUnit.CubicMeter) => new Volume(_value * 5.6826125e-4, VolumeUnit.CubicMeter), + (VolumeUnit.ImperialQuart, VolumeUnit.CubicMeter) => new Volume(_value * 1.1365225e-3, VolumeUnit.CubicMeter), (VolumeUnit.KilocubicFoot, VolumeUnit.CubicMeter) => new Volume((_value * 2.8316846592e-2) * 1e3d, VolumeUnit.CubicMeter), (VolumeUnit.KilocubicMeter, VolumeUnit.CubicMeter) => new Volume((_value) * 1e3d, VolumeUnit.CubicMeter), (VolumeUnit.KiloimperialGallon, VolumeUnit.CubicMeter) => new Volume((_value * 0.00454609) * 1e3d, VolumeUnit.CubicMeter), @@ -1841,6 +1861,7 @@ private bool TryToUnit(VolumeUnit unit, [NotNullWhen(true)] out Volume? converte (VolumeUnit.CubicMeter, VolumeUnit.ImperialGallon) => new Volume(_value / 0.00454609, VolumeUnit.ImperialGallon), (VolumeUnit.CubicMeter, VolumeUnit.ImperialOunce) => new Volume(_value / 2.8413062499962901241875439064617e-5, VolumeUnit.ImperialOunce), (VolumeUnit.CubicMeter, VolumeUnit.ImperialPint) => new Volume(_value / 5.6826125e-4, VolumeUnit.ImperialPint), + (VolumeUnit.CubicMeter, VolumeUnit.ImperialQuart) => new Volume(_value / 1.1365225e-3, VolumeUnit.ImperialQuart), (VolumeUnit.CubicMeter, VolumeUnit.KilocubicFoot) => new Volume((_value / 2.8316846592e-2) / 1e3d, VolumeUnit.KilocubicFoot), (VolumeUnit.CubicMeter, VolumeUnit.KilocubicMeter) => new Volume((_value) / 1e3d, VolumeUnit.KilocubicMeter), (VolumeUnit.CubicMeter, VolumeUnit.KiloimperialGallon) => new Volume((_value / 0.00454609) / 1e3d, VolumeUnit.KiloimperialGallon), diff --git a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs index 9cabb3b9f8..c35715428b 100644 --- a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs @@ -57,6 +57,7 @@ public enum VolumeUnit ImperialGallon = 25, ImperialOunce = 26, ImperialPint = 27, + ImperialQuart = 57, KilocubicFoot = 28, KilocubicMeter = 29, KiloimperialGallon = 30,