From bb306428c5616a3bba52711ab6137384a7eb9bf5 Mon Sep 17 00:00:00 2001 From: Craig Russell Date: Wed, 30 Jul 2025 21:35:09 -0400 Subject: [PATCH 1/4] Add Metric Tablespoon --- Common/UnitDefinitions/Volume.json | 18 +- Common/UnitEnumValues.g.json | 3 +- .../GeneratedCode/Quantities/Volume.g.cs | 12 + .../GeneratedCode/Units/VolumeUnit.g.cs | 6 + .../NumberToVolumeExtensionsTest.g.cs | 4 + .../NumberToVolumeExtensions.g.cs | 11 + .../TestsBase/VolumeTestsBase.g.cs | 236 +++++++++++++----- UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 18 ++ .../GeneratedCode/Resources/Volume.restext | 1 + UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs | 6 + 10 files changed, 250 insertions(+), 65 deletions(-) diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index 60734a1b7d..a858b42158 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -347,6 +347,20 @@ } ] }, + { + "SingularName": "MetricTablespoon", + "PluralName": "MetricTablespoons", + "XmlDocSummary": "An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Tablespoon#International_metric", + "FromUnitToBaseFunc": "{x} * 1.5e-5", + "FromBaseToUnitFunc": "{x} / 1.5e-5", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "tablespoon", "tbsp", "tbsp.", "T", "T.", "Tsp", "Tsp." ] + } + ] + }, { "SingularName": "UkTablespoon", "PluralName": "UkTablespoons", @@ -413,7 +427,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": ["cup (U.S. customary)"] + "Abbreviations": [ "cup (U.S. customary)" ] } ] }, @@ -427,7 +441,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": ["cup (U.S.)"] + "Abbreviations": [ "cup (U.S.)" ] } ] }, diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 025e39f28b..d46535fa20 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1599,7 +1599,8 @@ "UsTablespoon": 51, "UsTeaspoon": 52, "Nanoliter": 53, - "ImperialQuart": 57 + "ImperialQuart": 57, + "MetricTablespoon": 63 }, "VolumeConcentration": { "CentiliterPerLiter": 1, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs index 71a9f8ae2b..7da09ee253 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Volume.g.cs @@ -273,6 +273,11 @@ public Volume(double value, VolumeUnit unit) /// public double MetricCups => As(VolumeUnit.MetricCup); + /// + /// Gets a value of this quantity converted into + /// + public double MetricTablespoons => As(VolumeUnit.MetricTablespoon); + /// /// Gets a value of this quantity converted into /// @@ -547,6 +552,11 @@ public Volume(double value, VolumeUnit unit) /// public static Volume FromMetricCups(double metriccups) => new Volume(metriccups, VolumeUnit.MetricCup); + /// + /// Creates a from . + /// + public static Volume FromMetricTablespoons(double metrictablespoons) => new Volume(metrictablespoons, VolumeUnit.MetricTablespoon); + /// /// Creates a from . /// @@ -701,6 +711,7 @@ private double GetValueInBaseUnit() VolumeUnit.Megaliter => (_value / 1e3) * 1e6d, VolumeUnit.MegausGallon => (_value * 0.003785411784) * 1e6d, VolumeUnit.MetricCup => _value * 0.00025, + VolumeUnit.MetricTablespoon => _value * 1.5e-5, VolumeUnit.MetricTeaspoon => _value * 0.5e-5, VolumeUnit.Microliter => (_value / 1e3) * 1e-6d, VolumeUnit.Milliliter => (_value / 1e3) * 1e-3d, @@ -768,6 +779,7 @@ private double GetValueAs(VolumeUnit unit) VolumeUnit.Megaliter => (baseUnitValue * 1e3) / 1e6d, VolumeUnit.MegausGallon => (baseUnitValue / 0.003785411784) / 1e6d, VolumeUnit.MetricCup => baseUnitValue / 0.00025, + VolumeUnit.MetricTablespoon => baseUnitValue / 1.5e-5, VolumeUnit.MetricTeaspoon => baseUnitValue / 0.5e-5, VolumeUnit.Microliter => (baseUnitValue * 1e3) / 1e-6d, VolumeUnit.Milliliter => (baseUnitValue * 1e3) / 1e-3d, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs index 84dbccfb05..eae5768dfc 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs @@ -130,6 +130,12 @@ public enum VolumeUnit /// https://en.wikipedia.org/wiki/Cup_(unit)#Metric_cup MetricCup = 38, + /// + /// An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons + /// + /// https://en.wikipedia.org/wiki/Tablespoon#International_metric + MetricTablespoon = 63, + /// /// The metric teaspoon as a unit of culinary measure is 5 ml (0.18 imp fl oz; 0.17 US fl oz),[17] equal to 5 cm3, 1⁄3 UK/Canadian metric tablespoon, or 1⁄4 Australian metric tablespoon. /// diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs index b8450bdd38..7a047c5df7 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToVolumeExtensionsTest.g.cs @@ -180,6 +180,10 @@ public void NumberToMegausGallonsTest() => public void NumberToMetricCupsTest() => Assert.Equal(Volume.FromMetricCups(2), 2.MetricCups()); + [Fact] + public void NumberToMetricTablespoonsTest() => + Assert.Equal(Volume.FromMetricTablespoons(2), 2.MetricTablespoons()); + [Fact] public void NumberToMetricTeaspoonsTest() => Assert.Equal(Volume.FromMetricTeaspoons(2), 2.MetricTeaspoons()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs index d425a5ed28..82828124f6 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToVolumeExtensions.g.cs @@ -461,6 +461,17 @@ public static Volume MetricCups(this T value) => Volume.FromMetricCups(value.ToDouble(null)); #endif + /// + public static Volume MetricTablespoons(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber + => Volume.FromMetricTablespoons(double.CreateChecked(value)); +#else + , IConvertible + => Volume.FromMetricTablespoons(value.ToDouble(null)); +#endif + /// public static Volume MetricTeaspoons(this T value) where T : notnull diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index bb7f1dabf7..0f34c75e6d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -78,6 +78,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase protected abstract double MegalitersInOneCubicMeter { get; } protected abstract double MegausGallonsInOneCubicMeter { get; } protected abstract double MetricCupsInOneCubicMeter { get; } + protected abstract double MetricTablespoonsInOneCubicMeter { get; } protected abstract double MetricTeaspoonsInOneCubicMeter { get; } protected abstract double MicrolitersInOneCubicMeter { get; } protected abstract double MillilitersInOneCubicMeter { get; } @@ -134,6 +135,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase protected virtual double MegalitersTolerance { get { return 1e-5; } } protected virtual double MegausGallonsTolerance { get { return 1e-5; } } protected virtual double MetricCupsTolerance { get { return 1e-5; } } + protected virtual double MetricTablespoonsTolerance { get { return 1e-5; } } protected virtual double MetricTeaspoonsTolerance { get { return 1e-5; } } protected virtual double MicrolitersTolerance { get { return 1e-5; } } protected virtual double MillilitersTolerance { get { return 1e-5; } } @@ -194,6 +196,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase VolumeUnit.Megaliter => (MegalitersInOneCubicMeter, MegalitersTolerance), VolumeUnit.MegausGallon => (MegausGallonsInOneCubicMeter, MegausGallonsTolerance), VolumeUnit.MetricCup => (MetricCupsInOneCubicMeter, MetricCupsTolerance), + VolumeUnit.MetricTablespoon => (MetricTablespoonsInOneCubicMeter, MetricTablespoonsTolerance), VolumeUnit.MetricTeaspoon => (MetricTeaspoonsInOneCubicMeter, MetricTeaspoonsTolerance), VolumeUnit.Microliter => (MicrolitersInOneCubicMeter, MicrolitersTolerance), VolumeUnit.Milliliter => (MillilitersInOneCubicMeter, MillilitersTolerance), @@ -254,6 +257,7 @@ public abstract partial class VolumeTestsBase : QuantityTestsBase new object[] { VolumeUnit.Megaliter }, new object[] { VolumeUnit.MegausGallon }, new object[] { VolumeUnit.MetricCup }, + new object[] { VolumeUnit.MetricTablespoon }, new object[] { VolumeUnit.MetricTeaspoon }, new object[] { VolumeUnit.Microliter }, new object[] { VolumeUnit.Milliliter }, @@ -375,6 +379,7 @@ public void CubicMeterToVolumeUnits() AssertEx.EqualTolerance(MegalitersInOneCubicMeter, cubicmeter.Megaliters, MegalitersTolerance); AssertEx.EqualTolerance(MegausGallonsInOneCubicMeter, cubicmeter.MegausGallons, MegausGallonsTolerance); AssertEx.EqualTolerance(MetricCupsInOneCubicMeter, cubicmeter.MetricCups, MetricCupsTolerance); + AssertEx.EqualTolerance(MetricTablespoonsInOneCubicMeter, cubicmeter.MetricTablespoons, MetricTablespoonsTolerance); AssertEx.EqualTolerance(MetricTeaspoonsInOneCubicMeter, cubicmeter.MetricTeaspoons, MetricTeaspoonsTolerance); AssertEx.EqualTolerance(MicrolitersInOneCubicMeter, cubicmeter.Microliters, MicrolitersTolerance); AssertEx.EqualTolerance(MillilitersInOneCubicMeter, cubicmeter.Milliliters, MillilitersTolerance); @@ -551,65 +556,69 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity38.MetricCups, MetricCupsTolerance); Assert.Equal(VolumeUnit.MetricCup, quantity38.Unit); - var quantity39 = Volume.From(1, VolumeUnit.MetricTeaspoon); - AssertEx.EqualTolerance(1, quantity39.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, quantity39.Unit); + var quantity39 = Volume.From(1, VolumeUnit.MetricTablespoon); + AssertEx.EqualTolerance(1, quantity39.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, quantity39.Unit); - var quantity40 = Volume.From(1, VolumeUnit.Microliter); - AssertEx.EqualTolerance(1, quantity40.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, quantity40.Unit); + var quantity40 = Volume.From(1, VolumeUnit.MetricTeaspoon); + AssertEx.EqualTolerance(1, quantity40.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, quantity40.Unit); - var quantity41 = Volume.From(1, VolumeUnit.Milliliter); - AssertEx.EqualTolerance(1, quantity41.Milliliters, MillilitersTolerance); - Assert.Equal(VolumeUnit.Milliliter, quantity41.Unit); + var quantity41 = Volume.From(1, VolumeUnit.Microliter); + AssertEx.EqualTolerance(1, quantity41.Microliters, MicrolitersTolerance); + Assert.Equal(VolumeUnit.Microliter, quantity41.Unit); - var quantity42 = Volume.From(1, VolumeUnit.Nanoliter); - AssertEx.EqualTolerance(1, quantity42.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, quantity42.Unit); + var quantity42 = Volume.From(1, VolumeUnit.Milliliter); + AssertEx.EqualTolerance(1, quantity42.Milliliters, MillilitersTolerance); + Assert.Equal(VolumeUnit.Milliliter, quantity42.Unit); - var quantity43 = Volume.From(1, VolumeUnit.OilBarrel); - AssertEx.EqualTolerance(1, quantity43.OilBarrels, OilBarrelsTolerance); - Assert.Equal(VolumeUnit.OilBarrel, quantity43.Unit); + var quantity43 = Volume.From(1, VolumeUnit.Nanoliter); + AssertEx.EqualTolerance(1, quantity43.Nanoliters, NanolitersTolerance); + Assert.Equal(VolumeUnit.Nanoliter, quantity43.Unit); - var quantity44 = Volume.From(1, VolumeUnit.UkTablespoon); - AssertEx.EqualTolerance(1, quantity44.UkTablespoons, UkTablespoonsTolerance); - Assert.Equal(VolumeUnit.UkTablespoon, quantity44.Unit); + var quantity44 = Volume.From(1, VolumeUnit.OilBarrel); + AssertEx.EqualTolerance(1, quantity44.OilBarrels, OilBarrelsTolerance); + Assert.Equal(VolumeUnit.OilBarrel, quantity44.Unit); - var quantity45 = Volume.From(1, VolumeUnit.UsBeerBarrel); - AssertEx.EqualTolerance(1, quantity45.UsBeerBarrels, UsBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.UsBeerBarrel, quantity45.Unit); + var quantity45 = Volume.From(1, VolumeUnit.UkTablespoon); + AssertEx.EqualTolerance(1, quantity45.UkTablespoons, UkTablespoonsTolerance); + Assert.Equal(VolumeUnit.UkTablespoon, quantity45.Unit); - var quantity46 = Volume.From(1, VolumeUnit.UsCustomaryCup); - AssertEx.EqualTolerance(1, quantity46.UsCustomaryCups, UsCustomaryCupsTolerance); - Assert.Equal(VolumeUnit.UsCustomaryCup, quantity46.Unit); + var quantity46 = Volume.From(1, VolumeUnit.UsBeerBarrel); + AssertEx.EqualTolerance(1, quantity46.UsBeerBarrels, UsBeerBarrelsTolerance); + Assert.Equal(VolumeUnit.UsBeerBarrel, quantity46.Unit); - var quantity47 = Volume.From(1, VolumeUnit.UsGallon); - AssertEx.EqualTolerance(1, quantity47.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, quantity47.Unit); + var quantity47 = Volume.From(1, VolumeUnit.UsCustomaryCup); + AssertEx.EqualTolerance(1, quantity47.UsCustomaryCups, UsCustomaryCupsTolerance); + Assert.Equal(VolumeUnit.UsCustomaryCup, quantity47.Unit); - var quantity48 = Volume.From(1, VolumeUnit.UsLegalCup); - AssertEx.EqualTolerance(1, quantity48.UsLegalCups, UsLegalCupsTolerance); - Assert.Equal(VolumeUnit.UsLegalCup, quantity48.Unit); + var quantity48 = Volume.From(1, VolumeUnit.UsGallon); + AssertEx.EqualTolerance(1, quantity48.UsGallons, UsGallonsTolerance); + Assert.Equal(VolumeUnit.UsGallon, quantity48.Unit); - var quantity49 = Volume.From(1, VolumeUnit.UsOunce); - AssertEx.EqualTolerance(1, quantity49.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, quantity49.Unit); + var quantity49 = Volume.From(1, VolumeUnit.UsLegalCup); + AssertEx.EqualTolerance(1, quantity49.UsLegalCups, UsLegalCupsTolerance); + Assert.Equal(VolumeUnit.UsLegalCup, quantity49.Unit); - var quantity50 = Volume.From(1, VolumeUnit.UsPint); - AssertEx.EqualTolerance(1, quantity50.UsPints, UsPintsTolerance); - Assert.Equal(VolumeUnit.UsPint, quantity50.Unit); + var quantity50 = Volume.From(1, VolumeUnit.UsOunce); + AssertEx.EqualTolerance(1, quantity50.UsOunces, UsOuncesTolerance); + Assert.Equal(VolumeUnit.UsOunce, quantity50.Unit); - var quantity51 = Volume.From(1, VolumeUnit.UsQuart); - AssertEx.EqualTolerance(1, quantity51.UsQuarts, UsQuartsTolerance); - Assert.Equal(VolumeUnit.UsQuart, quantity51.Unit); + var quantity51 = Volume.From(1, VolumeUnit.UsPint); + AssertEx.EqualTolerance(1, quantity51.UsPints, UsPintsTolerance); + Assert.Equal(VolumeUnit.UsPint, quantity51.Unit); - var quantity52 = Volume.From(1, VolumeUnit.UsTablespoon); - AssertEx.EqualTolerance(1, quantity52.UsTablespoons, UsTablespoonsTolerance); - Assert.Equal(VolumeUnit.UsTablespoon, quantity52.Unit); + var quantity52 = Volume.From(1, VolumeUnit.UsQuart); + AssertEx.EqualTolerance(1, quantity52.UsQuarts, UsQuartsTolerance); + Assert.Equal(VolumeUnit.UsQuart, quantity52.Unit); - var quantity53 = Volume.From(1, VolumeUnit.UsTeaspoon); - AssertEx.EqualTolerance(1, quantity53.UsTeaspoons, UsTeaspoonsTolerance); - Assert.Equal(VolumeUnit.UsTeaspoon, quantity53.Unit); + var quantity53 = Volume.From(1, VolumeUnit.UsTablespoon); + AssertEx.EqualTolerance(1, quantity53.UsTablespoons, UsTablespoonsTolerance); + Assert.Equal(VolumeUnit.UsTablespoon, quantity53.Unit); + + var quantity54 = Volume.From(1, VolumeUnit.UsTeaspoon); + AssertEx.EqualTolerance(1, quantity54.UsTeaspoons, UsTeaspoonsTolerance); + Assert.Equal(VolumeUnit.UsTeaspoon, quantity54.Unit); } @@ -674,6 +683,7 @@ public void As() AssertEx.EqualTolerance(MegalitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Megaliter), MegalitersTolerance); AssertEx.EqualTolerance(MegausGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MegausGallon), MegausGallonsTolerance); AssertEx.EqualTolerance(MetricCupsInOneCubicMeter, cubicmeter.As(VolumeUnit.MetricCup), MetricCupsTolerance); + AssertEx.EqualTolerance(MetricTablespoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MetricTablespoon), MetricTablespoonsTolerance); AssertEx.EqualTolerance(MetricTeaspoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MetricTeaspoon), MetricTeaspoonsTolerance); AssertEx.EqualTolerance(MicrolitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Microliter), MicrolitersTolerance); AssertEx.EqualTolerance(MillilitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Milliliter), MillilitersTolerance); @@ -1367,6 +1377,55 @@ public void Parse() Assert.Equal(VolumeUnit.MetricCup, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 tablespoon", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 tbsp", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 tbsp.", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 T", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 T.", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 Tsp", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 Tsp.", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 tsp", CultureInfo.GetCultureInfo("en-US")); @@ -1995,31 +2054,31 @@ public void TryParse() } { - Assert.True(Volume.TryParse("1 tsp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + Assert.True(Volume.TryParse("1 tablespoon", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } { - Assert.True(Volume.TryParse("1 t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + Assert.True(Volume.TryParse("1 tbsp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } { - Assert.True(Volume.TryParse("1 ts", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + Assert.True(Volume.TryParse("1 tbsp.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } { - Assert.True(Volume.TryParse("1 tspn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(Volume.TryParse("1 ts", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); } { - Assert.True(Volume.TryParse("1 t.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + Assert.True(Volume.TryParse("1 tspn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); } @@ -2030,12 +2089,6 @@ public void TryParse() Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); } - { - Assert.True(Volume.TryParse("1 tsp.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } - { Assert.True(Volume.TryParse("1 tspn.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); @@ -2195,6 +2248,13 @@ public void TryParse() [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("metric cup", VolumeUnit.MetricCup)] + [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("T", VolumeUnit.MetricTablespoon)] + [InlineData("T.", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2269,6 +2329,13 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUni [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("metric cup", VolumeUnit.MetricCup)] + [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("T", VolumeUnit.MetricTablespoon)] + [InlineData("T.", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2343,6 +2410,13 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] + [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2452,6 +2526,13 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] + [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2570,6 +2651,13 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("metric cup", VolumeUnit.MetricCup)] + [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("T", VolumeUnit.MetricTablespoon)] + [InlineData("T.", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2644,6 +2732,13 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, Volume [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("metric cup", VolumeUnit.MetricCup)] + [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("T", VolumeUnit.MetricTablespoon)] + [InlineData("T.", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2718,6 +2813,13 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] + [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2827,6 +2929,13 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] + [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -3006,6 +3115,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Volume.FromMegaliters(cubicmeter.Megaliters).CubicMeters, MegalitersTolerance); AssertEx.EqualTolerance(1, Volume.FromMegausGallons(cubicmeter.MegausGallons).CubicMeters, MegausGallonsTolerance); AssertEx.EqualTolerance(1, Volume.FromMetricCups(cubicmeter.MetricCups).CubicMeters, MetricCupsTolerance); + AssertEx.EqualTolerance(1, Volume.FromMetricTablespoons(cubicmeter.MetricTablespoons).CubicMeters, MetricTablespoonsTolerance); AssertEx.EqualTolerance(1, Volume.FromMetricTeaspoons(cubicmeter.MetricTeaspoons).CubicMeters, MetricTeaspoonsTolerance); AssertEx.EqualTolerance(1, Volume.FromMicroliters(cubicmeter.Microliters).CubicMeters, MicrolitersTolerance); AssertEx.EqualTolerance(1, Volume.FromMilliliters(cubicmeter.Milliliters).CubicMeters, MillilitersTolerance); @@ -3207,6 +3317,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 Ml", new Volume(1, VolumeUnit.Megaliter).ToString()); Assert.Equal("1 Mgal (U.S.)", new Volume(1, VolumeUnit.MegausGallon).ToString()); Assert.Equal("1 metric cup", new Volume(1, VolumeUnit.MetricCup).ToString()); + Assert.Equal("1 tablespoon", new Volume(1, VolumeUnit.MetricTablespoon).ToString()); Assert.Equal("1 tsp", new Volume(1, VolumeUnit.MetricTeaspoon).ToString()); Assert.Equal("1 µl", new Volume(1, VolumeUnit.Microliter).ToString()); Assert.Equal("1 ml", new Volume(1, VolumeUnit.Milliliter).ToString()); @@ -3269,6 +3380,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 Ml", new Volume(1, VolumeUnit.Megaliter).ToString(swedishCulture)); Assert.Equal("1 Mgal (U.S.)", new Volume(1, VolumeUnit.MegausGallon).ToString(swedishCulture)); Assert.Equal("1 metric cup", new Volume(1, VolumeUnit.MetricCup).ToString(swedishCulture)); + Assert.Equal("1 tablespoon", new Volume(1, VolumeUnit.MetricTablespoon).ToString(swedishCulture)); Assert.Equal("1 tsp", new Volume(1, VolumeUnit.MetricTeaspoon).ToString(swedishCulture)); Assert.Equal("1 µl", new Volume(1, VolumeUnit.Microliter).ToString(swedishCulture)); Assert.Equal("1 ml", new Volume(1, VolumeUnit.Milliliter).ToString(swedishCulture)); diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index b4446c02b9..1d0f05f656 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -170,6 +170,7 @@ public static IEnumerable> GetDefaultMappings() yield return new (VolumeUnit.Megaliter, "Megaliter", "Megaliters", new BaseUnits(length: LengthUnit.Decameter)); yield return new (VolumeUnit.MegausGallon, "MegausGallon", "MegausGallons", BaseUnits.Undefined); yield return new (VolumeUnit.MetricCup, "MetricCup", "MetricCups", BaseUnits.Undefined); + yield return new (VolumeUnit.MetricTablespoon, "MetricTablespoon", "MetricTablespoons", BaseUnits.Undefined); yield return new (VolumeUnit.MetricTeaspoon, "MetricTeaspoon", "MetricTeaspoons", BaseUnits.Undefined); yield return new (VolumeUnit.Microliter, "Microliter", "Microliters", new BaseUnits(length: LengthUnit.Millimeter)); yield return new (VolumeUnit.Milliliter, "Milliliter", "Milliliters", new BaseUnits(length: LengthUnit.Centimeter)); @@ -488,6 +489,11 @@ public Volume(double value, UnitSystem unitSystem) /// public double MetricCups => As(VolumeUnit.MetricCup); + /// + /// Gets a value of this quantity converted into + /// + public double MetricTablespoons => As(VolumeUnit.MetricTablespoon); + /// /// Gets a value of this quantity converted into /// @@ -612,6 +618,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(VolumeUnit.Megaliter, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.MegausGallon, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.MetricCup, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); + unitConverter.SetConversionFunction(VolumeUnit.MetricTablespoon, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.MetricTeaspoon, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.Microliter, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); unitConverter.SetConversionFunction(VolumeUnit.Milliliter, VolumeUnit.CubicMeter, quantity => quantity.ToUnit(VolumeUnit.CubicMeter)); @@ -670,6 +677,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.Megaliter, quantity => quantity.ToUnit(VolumeUnit.Megaliter)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.MegausGallon, quantity => quantity.ToUnit(VolumeUnit.MegausGallon)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.MetricCup, quantity => quantity.ToUnit(VolumeUnit.MetricCup)); + unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.MetricTablespoon, quantity => quantity.ToUnit(VolumeUnit.MetricTablespoon)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.MetricTeaspoon, quantity => quantity.ToUnit(VolumeUnit.MetricTeaspoon)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.Microliter, quantity => quantity.ToUnit(VolumeUnit.Microliter)); unitConverter.SetConversionFunction(VolumeUnit.CubicMeter, VolumeUnit.Milliliter, quantity => quantity.ToUnit(VolumeUnit.Milliliter)); @@ -1024,6 +1032,14 @@ public static Volume FromMetricCups(double value) return new Volume(value, VolumeUnit.MetricCup); } + /// + /// Creates a from . + /// + public static Volume FromMetricTablespoons(double value) + { + return new Volume(value, VolumeUnit.MetricTablespoon); + } + /// /// Creates a from . /// @@ -1730,6 +1746,7 @@ private bool TryToUnit(VolumeUnit unit, [NotNullWhen(true)] out Volume? converte (VolumeUnit.Megaliter, VolumeUnit.CubicMeter) => new Volume((_value / 1e3) * 1e6d, VolumeUnit.CubicMeter), (VolumeUnit.MegausGallon, VolumeUnit.CubicMeter) => new Volume((_value * 0.003785411784) * 1e6d, VolumeUnit.CubicMeter), (VolumeUnit.MetricCup, VolumeUnit.CubicMeter) => new Volume(_value * 0.00025, VolumeUnit.CubicMeter), + (VolumeUnit.MetricTablespoon, VolumeUnit.CubicMeter) => new Volume(_value * 1.5e-5, VolumeUnit.CubicMeter), (VolumeUnit.MetricTeaspoon, VolumeUnit.CubicMeter) => new Volume(_value * 0.5e-5, VolumeUnit.CubicMeter), (VolumeUnit.Microliter, VolumeUnit.CubicMeter) => new Volume((_value / 1e3) * 1e-6d, VolumeUnit.CubicMeter), (VolumeUnit.Milliliter, VolumeUnit.CubicMeter) => new Volume((_value / 1e3) * 1e-3d, VolumeUnit.CubicMeter), @@ -1785,6 +1802,7 @@ private bool TryToUnit(VolumeUnit unit, [NotNullWhen(true)] out Volume? converte (VolumeUnit.CubicMeter, VolumeUnit.Megaliter) => new Volume((_value * 1e3) / 1e6d, VolumeUnit.Megaliter), (VolumeUnit.CubicMeter, VolumeUnit.MegausGallon) => new Volume((_value / 0.003785411784) / 1e6d, VolumeUnit.MegausGallon), (VolumeUnit.CubicMeter, VolumeUnit.MetricCup) => new Volume(_value / 0.00025, VolumeUnit.MetricCup), + (VolumeUnit.CubicMeter, VolumeUnit.MetricTablespoon) => new Volume(_value / 1.5e-5, VolumeUnit.MetricTablespoon), (VolumeUnit.CubicMeter, VolumeUnit.MetricTeaspoon) => new Volume(_value / 0.5e-5, VolumeUnit.MetricTeaspoon), (VolumeUnit.CubicMeter, VolumeUnit.Microliter) => new Volume((_value * 1e3) / 1e-6d, VolumeUnit.Microliter), (VolumeUnit.CubicMeter, VolumeUnit.Milliliter) => new Volume((_value * 1e3) / 1e-3d, VolumeUnit.Milliliter), diff --git a/UnitsNet/GeneratedCode/Resources/Volume.restext b/UnitsNet/GeneratedCode/Resources/Volume.restext index ddf8cb58da..d3781d1a31 100644 --- a/UnitsNet/GeneratedCode/Resources/Volume.restext +++ b/UnitsNet/GeneratedCode/Resources/Volume.restext @@ -37,6 +37,7 @@ MegaimperialGallons=Mgal (imp.) Megaliters=Ml MegausGallons=Mgal (U.S.) MetricCups=metric cup +MetricTablespoons=tablespoon,tbsp,tbsp.,T,T.,Tsp,Tsp. MetricTeaspoons=tsp,t,ts,tspn,t.,ts.,tsp.,tspn.,teaspoon Microliters=µl Milliliters=ml diff --git a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs index 84dbccfb05..eae5768dfc 100644 --- a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs @@ -130,6 +130,12 @@ public enum VolumeUnit /// https://en.wikipedia.org/wiki/Cup_(unit)#Metric_cup MetricCup = 38, + /// + /// An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons + /// + /// https://en.wikipedia.org/wiki/Tablespoon#International_metric + MetricTablespoon = 63, + /// /// The metric teaspoon as a unit of culinary measure is 5 ml (0.18 imp fl oz; 0.17 US fl oz),[17] equal to 5 cm3, 1⁄3 UK/Canadian metric tablespoon, or 1⁄4 Australian metric tablespoon. /// From 0edfca3b12c1fe8afe691dca56fe9fafc838c916 Mon Sep 17 00:00:00 2001 From: Craig Russell Date: Wed, 30 Jul 2025 21:40:57 -0400 Subject: [PATCH 2/4] Fix of some abbrievations --- Common/UnitDefinitions/Volume.json | 4 +- .../GeneratedCode/Units/VolumeUnit.g.cs | 2 +- .../TestsBase/VolumeTestsBase.g.cs | 102 +++++++++--------- .../GeneratedCode/Resources/Volume.restext | 2 +- UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs | 2 +- 5 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index a858b42158..a1ba368f16 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -350,14 +350,14 @@ { "SingularName": "MetricTablespoon", "PluralName": "MetricTablespoons", - "XmlDocSummary": "An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons", + "XmlDocSummary": "An international metric tablespoon is exactly equal to 15 mL. It is the equivalence of 1⁠ 1/2 metric dessert spoons or metric teaspoons", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Tablespoon#International_metric", "FromUnitToBaseFunc": "{x} * 1.5e-5", "FromBaseToUnitFunc": "{x} / 1.5e-5", "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "tablespoon", "tbsp", "tbsp.", "T", "T.", "Tsp", "Tsp." ] + "Abbreviations": [ "tablespoon", "tbsp", "tbsp.", "tblsp", "tblsp." ] } ] }, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs index eae5768dfc..1a8767f7db 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/VolumeUnit.g.cs @@ -131,7 +131,7 @@ public enum VolumeUnit MetricCup = 38, /// - /// An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons + /// An international metric tablespoon is exactly equal to 15 mL. It is the equivalence of 1⁠ 1/2 metric dessert spoons or metric teaspoons /// /// https://en.wikipedia.org/wiki/Tablespoon#International_metric MetricTablespoon = 63, diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index 0f34c75e6d..ad5bbc8186 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -1400,28 +1400,14 @@ public void Parse() try { - var parsed = Volume.Parse("1 T", CultureInfo.GetCultureInfo("en-US")); + var parsed = Volume.Parse("1 tblsp", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } try { - var parsed = Volume.Parse("1 T.", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); - Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Tsp", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); - Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Tsp.", CultureInfo.GetCultureInfo("en-US")); + var parsed = Volume.Parse("1 tblsp.", CultureInfo.GetCultureInfo("en-US")); AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } @@ -2071,6 +2057,30 @@ public void TryParse() Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 tblsp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } + + { + Assert.True(Volume.TryParse("1 tblsp.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTablespoons, MetricTablespoonsTolerance); + Assert.Equal(VolumeUnit.MetricTablespoon, parsed.Unit); + } + + { + Assert.True(Volume.TryParse("1 tsp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + } + + { + Assert.True(Volume.TryParse("1 t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 ts", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); @@ -2083,12 +2093,24 @@ public void TryParse() Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 t.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 ts.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 tsp.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); + Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 tspn.", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); @@ -2251,10 +2273,8 @@ public void TryParse() [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("tbsp", VolumeUnit.MetricTablespoon)] [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("T", VolumeUnit.MetricTablespoon)] - [InlineData("T.", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2332,10 +2352,8 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUni [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("tbsp", VolumeUnit.MetricTablespoon)] [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("T", VolumeUnit.MetricTablespoon)] - [InlineData("T.", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2413,10 +2431,8 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2529,10 +2545,8 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2654,10 +2668,8 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("tbsp", VolumeUnit.MetricTablespoon)] [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("T", VolumeUnit.MetricTablespoon)] - [InlineData("T.", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2735,10 +2747,8 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, Volume [InlineData("tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("tbsp", VolumeUnit.MetricTablespoon)] [InlineData("tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("T", VolumeUnit.MetricTablespoon)] - [InlineData("T.", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2816,10 +2826,8 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2932,10 +2940,8 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("en-US", "tablespoon", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tbsp.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "T.", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp", VolumeUnit.MetricTablespoon)] - [InlineData("en-US", "Tsp.", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp", VolumeUnit.MetricTablespoon)] + [InlineData("en-US", "tblsp.", VolumeUnit.MetricTablespoon)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] diff --git a/UnitsNet/GeneratedCode/Resources/Volume.restext b/UnitsNet/GeneratedCode/Resources/Volume.restext index d3781d1a31..5e5bc9e419 100644 --- a/UnitsNet/GeneratedCode/Resources/Volume.restext +++ b/UnitsNet/GeneratedCode/Resources/Volume.restext @@ -37,7 +37,7 @@ MegaimperialGallons=Mgal (imp.) Megaliters=Ml MegausGallons=Mgal (U.S.) MetricCups=metric cup -MetricTablespoons=tablespoon,tbsp,tbsp.,T,T.,Tsp,Tsp. +MetricTablespoons=tablespoon,tbsp,tbsp.,tblsp,tblsp. MetricTeaspoons=tsp,t,ts,tspn,t.,ts.,tsp.,tspn.,teaspoon Microliters=µl Milliliters=ml diff --git a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs index eae5768dfc..1a8767f7db 100644 --- a/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs @@ -131,7 +131,7 @@ public enum VolumeUnit MetricCup = 38, /// - /// An international metric tablespoon is exactly equal to 15 mL.[6] It is the equivalence of 1⁠, 1/2 metric dessert spoons or metric teaspoons + /// An international metric tablespoon is exactly equal to 15 mL. It is the equivalence of 1⁠ 1/2 metric dessert spoons or metric teaspoons /// /// https://en.wikipedia.org/wiki/Tablespoon#International_metric MetricTablespoon = 63, From 957b599d6de2059e1f0672249b1ef8a1652925df Mon Sep 17 00:00:00 2001 From: Craig Russell Date: Wed, 30 Jul 2025 21:56:07 -0400 Subject: [PATCH 3/4] run tests --- UnitsNet.Tests/CustomCode/VolumeTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/VolumeTests.cs b/UnitsNet.Tests/CustomCode/VolumeTests.cs index 857958df8e..0df729bde5 100644 --- a/UnitsNet.Tests/CustomCode/VolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeTests.cs @@ -78,6 +78,8 @@ public class VolumeTests : VolumeTestsBase protected override double UkTablespoonsInOneCubicMeter => 66666.6666667; + protected override double MetricTablespoonsInOneCubicMeter => 66666.6666667; + protected override double UsBeerBarrelsInOneCubicMeter => 8.5216790723083; protected override double UsGallonsInOneCubicMeter => 264.17217; From f3c8aae31a86b527b5f6c3cad9f071b556c9c898 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 10 Aug 2025 21:12:14 +0200 Subject: [PATCH 4/4] Minor xmldoc fix --- Common/UnitDefinitions/Volume.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index a1ba368f16..b744737e5d 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -350,7 +350,7 @@ { "SingularName": "MetricTablespoon", "PluralName": "MetricTablespoons", - "XmlDocSummary": "An international metric tablespoon is exactly equal to 15 mL. It is the equivalence of 1⁠ 1/2 metric dessert spoons or metric teaspoons", + "XmlDocSummary": "An international metric tablespoon is exactly equal to 15 mL. It is the equivalence of 1⁠ 1/2 metric dessert spoons or 3 metric teaspoons.", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Tablespoon#International_metric", "FromUnitToBaseFunc": "{x} * 1.5e-5", "FromBaseToUnitFunc": "{x} / 1.5e-5",