diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 51bdba1be5..a018868c31 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using CodeGen.JsonTypes; @@ -82,6 +83,16 @@ internal class UnitTestBaseClassGenerator : GeneratorBase /// private readonly Dictionary>> _ambiguousAbbreviationsForCulture; + /// + /// A dictionary that maps culture names to their respective dictionaries of units and their default abbreviations. + /// + /// + /// This field is used to store the default abbreviation for each unit in a specific culture. + /// The outer dictionary key represents the culture name (e.g., "en-US"), while the inner dictionary maps a + /// to its default abbreviation. + /// + private readonly Dictionary> _defaultAbbreviationsForCulture; + /// /// The default or fallback culture for unit localizations. /// @@ -107,7 +118,8 @@ public UnitTestBaseClassGenerator(Quantity quantity) _otherOrBaseUnit = quantity.Units.Where(u => u != _baseUnit).DefaultIfEmpty(_baseUnit).First(); _otherOrBaseUnitFullName = $"{_unitEnumName}.{_otherOrBaseUnit.SingularName}"; _isDimensionless = quantity.BaseDimensions is { L: 0, M: 0, T: 0, I: 0, Θ: 0, N: 0, J: 0 }; - + + _defaultAbbreviationsForCulture = new Dictionary>(); var abbreviationsForCulture = new Dictionary>>(); foreach (Unit unit in quantity.Units) { @@ -118,6 +130,11 @@ public UnitTestBaseClassGenerator(Quantity quantity) foreach (Localization localization in unit.Localization) { + if (localization.Abbreviations.Length == 0) + { + continue; + } + if (!abbreviationsForCulture.TryGetValue(localization.Culture, out Dictionary>? localizationsForCulture)) { abbreviationsForCulture[localization.Culture] = localizationsForCulture = new Dictionary>(); @@ -134,6 +151,13 @@ public UnitTestBaseClassGenerator(Quantity quantity) localizationsForCulture[abbreviation] = [unit]; } } + + if (!_defaultAbbreviationsForCulture.TryGetValue(localization.Culture, out Dictionary? defaultLocalizationsForCulture)) + { + _defaultAbbreviationsForCulture[localization.Culture] = defaultLocalizationsForCulture = new Dictionary(); + } + + defaultLocalizationsForCulture.Add(unit, localization.Abbreviations[0]); } } @@ -543,56 +567,104 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() "); } + Writer.WL(@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + var culture = CultureInfo.GetCultureInfo(cultureName); + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{4.2m.ToString(culture)} {abbreviation}"", {GetUnitFullName(unit)}, 4.2)]"); + } + } + Writer.WL($@" + public void Parse(string culture, string quantityString, {_unitEnumName} expectedUnit, double expectedValue) + {{ + using var _ = new CultureScope(culture); + var parsed = {_quantity.Name}.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + }} +"); - [Fact] - public void Parse() - {{"); - foreach (var unit in _quantity.Units.Where(u => string.IsNullOrEmpty(u.ObsoleteText))) - foreach (var localization in unit.Localization) - foreach (var abbreviation in localization.Abbreviations) + // we only generate these for a few of the quantities + if (_ambiguousAbbreviationsForCulture.Count != 0) { + Writer.WL(@" + [Theory]"); + foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) + { + foreach (KeyValuePair> ambiguousPair in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""1 {ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] "); + } + } + Writer.WL($@" - try - {{ - var parsed = {_quantity.Name}.Parse(""1 {abbreviation}"", CultureInfo.GetCultureInfo(""{localization.Culture}"")); - AssertEx.EqualTolerance(1, parsed.{unit.PluralName}, {unit.PluralName}Tolerance); - Assert.Equal({GetUnitFullName(unit)}, parsed.Unit); - }} catch (AmbiguousUnitParseException) {{ /* Some units have the same abbreviations */ }} + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) + {{ + Assert.Throws(() => {_quantity.Name}.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + }} "); + } // ambiguousAbbreviations + + + Writer.WL(@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + var culture = CultureInfo.GetCultureInfo(cultureName); + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{4.2m.ToString(culture)} {abbreviation}"", {GetUnitFullName(unit)}, 4.2)]"); + } } + Writer.WL($@" + public void TryParse(string culture, string quantityString, {_unitEnumName} expectedUnit, double expectedValue) + {{ + using var _ = new CultureScope(culture); + Assert.True({_quantity.Name}.TryParse(quantityString, out {_quantity.Name} parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); }} +"); - [Fact] - public void TryParse() - {{"); - foreach (var unit in _quantity.Units.Where(u => string.IsNullOrEmpty(u.ObsoleteText))) - foreach (var localization in unit.Localization) - foreach (var abbreviation in localization.Abbreviations) + // we only generate these for a few of the quantities + if (_ambiguousAbbreviationsForCulture.Count != 0) { - // Skip units with ambiguous abbreviations, since there is no exception to describe this is why TryParse failed. - if (IsAmbiguousAbbreviation(localization, abbreviation)) continue; + Writer.WL(@" + [Theory]"); + foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) + { + foreach (KeyValuePair> ambiguousPair in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""1 {ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] "); + } + } Writer.WL($@" - {{ - Assert.True({_quantity.Name}.TryParse(""1 {abbreviation}"", CultureInfo.GetCultureInfo(""{localization.Culture}""), out var parsed)); - AssertEx.EqualTolerance(1, parsed.{unit.PluralName}, {unit.PluralName}Tolerance); - Assert.Equal({GetUnitFullName(unit)}, parsed.Unit); - }} -"); - } - Writer.WL($@" + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + {{ + Assert.False({_quantity.Name}.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); }} "); + } // ambiguousAbbreviations - Writer.WL($@" + + Writer.WL(@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) { Writer.WL($@" [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } + Writer.WL($@" public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -603,13 +675,14 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unitEnu }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) { Writer.WL($@" [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } + Writer.WL($@" public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -620,7 +693,7 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) { @@ -630,6 +703,7 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); } } + Writer.WL($@" public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -639,7 +713,7 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, {_ }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) { @@ -649,6 +723,7 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, {_ [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); } } + Writer.WL($@" public void ParseUnit_WithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -660,7 +735,7 @@ public void ParseUnit_WithCulture(string culture, string abbreviation, {_unitEnu // we only generate these for a few of the quantities if (_ambiguousAbbreviationsForCulture.Count != 0) { - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) { @@ -670,6 +745,7 @@ public void ParseUnit_WithCulture(string culture, string abbreviation, {_unitEnu [InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}]"); } } + Writer.WL($@" public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) {{ @@ -678,13 +754,14 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati "); } // ambiguousAbbreviations - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) { Writer.WL($@" [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } + Writer.WL($@" public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -695,13 +772,14 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unit }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) { Writer.WL($@" [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } + Writer.WL($@" public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -712,7 +790,7 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) { @@ -722,6 +800,7 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); } } + Writer.WL($@" public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -731,7 +810,7 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, }} "); - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) { @@ -741,6 +820,7 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); } } + Writer.WL($@" public void TryParseUnit_WithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ @@ -752,7 +832,7 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, {_unit // we only generate these for a few of the quantities if (_ambiguousAbbreviationsForCulture.Count != 0) { - Writer.WL($@" + Writer.WL(@" [Theory]"); foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) { @@ -762,6 +842,7 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, {_unit [InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}]"); } } + Writer.WL($@" public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) {{ @@ -770,6 +851,39 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi "); } // ambiguousAbbreviations + Writer.WL(@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _defaultAbbreviationsForCulture) + { + foreach ((Unit unit, var abbreviation) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", {GetUnitFullName(unit)}, ""{abbreviation}"")]"); + } + } + + Writer.WL($@" + public void GetAbbreviationForCulture(string culture, {_unitEnumName} unit, string expectedAbbreviation) + {{ + var defaultAbbreviation = {_quantity.Name}.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }} +"); + Writer.WL($@" + [Fact] + public void GetAbbreviationWithDefaultCulture() + {{ + Assert.All({_quantity.Name}.Units, unit => + {{ + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = {_quantity.Name}.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }}); + }} +"); + Writer.WL($@" [Theory] [MemberData(nameof(UnitTypes))] @@ -1182,12 +1296,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) }}"); return Writer.ToString(); } - - private bool IsAmbiguousAbbreviation(Localization localization, string abbreviation) - { - return _quantity.Units.Count(u => - u.Localization.SingleOrDefault(l => l.Culture == localization.Culture) is { } otherUnitLocalization && - otherUnitLocalization.Abbreviations.Contains(abbreviation, StringComparer.OrdinalIgnoreCase)) > 1; - } } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs index 415b554bba..5812aeed6e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs @@ -366,384 +366,90 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray, 4.2)] + [InlineData("en-US", "4.2 dGy", AbsorbedDoseOfIonizingRadiationUnit.Decigray, 4.2)] + [InlineData("en-US", "4.2 fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, 4.2)] + [InlineData("en-US", "4.2 GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, 4.2)] + [InlineData("en-US", "4.2 Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray, 4.2)] + [InlineData("en-US", "4.2 kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, 4.2)] + [InlineData("en-US", "4.2 krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, 4.2)] + [InlineData("en-US", "4.2 MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray, 4.2)] + [InlineData("en-US", "4.2 Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad, 4.2)] + [InlineData("en-US", "4.2 µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray, 4.2)] + [InlineData("en-US", "4.2 mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray, 4.2)] + [InlineData("en-US", "4.2 mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad, 4.2)] + [InlineData("en-US", "4.2 nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, 4.2)] + [InlineData("en-US", "4.2 PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray, 4.2)] + [InlineData("en-US", "4.2 pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray, 4.2)] + [InlineData("en-US", "4.2 rad", AbsorbedDoseOfIonizingRadiationUnit.Rad, 4.2)] + [InlineData("en-US", "4.2 TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray, 4.2)] + [InlineData("ru-RU", "4,2 сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray, 4.2)] + [InlineData("ru-RU", "4,2 дГр", AbsorbedDoseOfIonizingRadiationUnit.Decigray, 4.2)] + [InlineData("ru-RU", "4,2 фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, 4.2)] + [InlineData("ru-RU", "4,2 ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, 4.2)] + [InlineData("ru-RU", "4,2 Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray, 4.2)] + [InlineData("ru-RU", "4,2 кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, 4.2)] + [InlineData("ru-RU", "4,2 крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, 4.2)] + [InlineData("ru-RU", "4,2 МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray, 4.2)] + [InlineData("ru-RU", "4,2 Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad, 4.2)] + [InlineData("ru-RU", "4,2 мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray, 4.2)] + [InlineData("ru-RU", "4,2 мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray, 4.2)] + [InlineData("ru-RU", "4,2 мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad, 4.2)] + [InlineData("ru-RU", "4,2 нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, 4.2)] + [InlineData("ru-RU", "4,2 ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray, 4.2)] + [InlineData("ru-RU", "4,2 пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray, 4.2)] + [InlineData("ru-RU", "4,2 рад", AbsorbedDoseOfIonizingRadiationUnit.Rad, 4.2)] + [InlineData("ru-RU", "4,2 ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray, 4.2)] + public void Parse(string culture, string quantityString, AbsorbedDoseOfIonizingRadiationUnit expectedUnit, double expectedValue) { - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 cGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centigrays, CentigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 сГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centigrays, CentigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 dGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decigrays, DecigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Decigray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 дГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decigrays, DecigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Decigray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 fGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtograys, FemtograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 фГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Femtograys, FemtograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 GGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigagrays, GigagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 ГГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigagrays, GigagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 Gy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Grays, GraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 Гр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Grays, GraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 kGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilograys, KilograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 кГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilograys, KilograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 krad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilorads, KiloradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 крад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilorads, KiloradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 MGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megagrays, MegagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 МГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megagrays, MegagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 Mrad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megarads, MegaradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 Мрад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megarads, MegaradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 µGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micrograys, MicrograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 мкГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Micrograys, MicrograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 mGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milligrays, MilligraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Milligray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 мГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milligrays, MilligraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Milligray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 mrad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millirads, MilliradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Millirad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 мрад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millirads, MilliradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Millirad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 nGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanograys, NanograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 нГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanograys, NanograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 PGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petagrays, PetagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Petagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 ПГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Petagrays, PetagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Petagray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 pGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picograys, PicograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Picogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 пГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picograys, PicograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Picogray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Rads, RadsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 рад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Rads, RadsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 TGy", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teragrays, TeragraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AbsorbedDoseOfIonizingRadiation.Parse("1 ТГр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Teragrays, TeragraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = AbsorbedDoseOfIonizingRadiation.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray, 4.2)] + [InlineData("en-US", "4.2 dGy", AbsorbedDoseOfIonizingRadiationUnit.Decigray, 4.2)] + [InlineData("en-US", "4.2 fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, 4.2)] + [InlineData("en-US", "4.2 GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, 4.2)] + [InlineData("en-US", "4.2 Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray, 4.2)] + [InlineData("en-US", "4.2 kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, 4.2)] + [InlineData("en-US", "4.2 krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, 4.2)] + [InlineData("en-US", "4.2 MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray, 4.2)] + [InlineData("en-US", "4.2 Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad, 4.2)] + [InlineData("en-US", "4.2 µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray, 4.2)] + [InlineData("en-US", "4.2 mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray, 4.2)] + [InlineData("en-US", "4.2 mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad, 4.2)] + [InlineData("en-US", "4.2 nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, 4.2)] + [InlineData("en-US", "4.2 PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray, 4.2)] + [InlineData("en-US", "4.2 pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray, 4.2)] + [InlineData("en-US", "4.2 rad", AbsorbedDoseOfIonizingRadiationUnit.Rad, 4.2)] + [InlineData("en-US", "4.2 TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray, 4.2)] + [InlineData("ru-RU", "4,2 сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray, 4.2)] + [InlineData("ru-RU", "4,2 дГр", AbsorbedDoseOfIonizingRadiationUnit.Decigray, 4.2)] + [InlineData("ru-RU", "4,2 фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, 4.2)] + [InlineData("ru-RU", "4,2 ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, 4.2)] + [InlineData("ru-RU", "4,2 Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray, 4.2)] + [InlineData("ru-RU", "4,2 кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, 4.2)] + [InlineData("ru-RU", "4,2 крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, 4.2)] + [InlineData("ru-RU", "4,2 МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray, 4.2)] + [InlineData("ru-RU", "4,2 Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad, 4.2)] + [InlineData("ru-RU", "4,2 мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray, 4.2)] + [InlineData("ru-RU", "4,2 мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray, 4.2)] + [InlineData("ru-RU", "4,2 мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad, 4.2)] + [InlineData("ru-RU", "4,2 нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, 4.2)] + [InlineData("ru-RU", "4,2 ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray, 4.2)] + [InlineData("ru-RU", "4,2 пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray, 4.2)] + [InlineData("ru-RU", "4,2 рад", AbsorbedDoseOfIonizingRadiationUnit.Rad, 4.2)] + [InlineData("ru-RU", "4,2 ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray, 4.2)] + public void TryParse(string culture, string quantityString, AbsorbedDoseOfIonizingRadiationUnit expectedUnit, double expectedValue) { - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 cGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centigrays, CentigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 сГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centigrays, CentigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 dGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decigrays, DecigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Decigray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 дГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decigrays, DecigraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Decigray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 fGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtograys, FemtograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 фГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtograys, FemtograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 GGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigagrays, GigagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 ГГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigagrays, GigagraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 Gy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grays, GraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 Гр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grays, GraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 kGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilograys, KilograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 кГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilograys, KilograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 krad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilorads, KiloradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 крад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilorads, KiloradsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 µGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrograys, MicrograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 мкГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrograys, MicrograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 nGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanograys, NanograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 нГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanograys, NanograysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Rads, RadsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 рад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Rads, RadsTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 TGy", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teragrays, TeragraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsed.Unit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse("1 ТГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teragrays, TeragraysTolerance); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(AbsorbedDoseOfIonizingRadiation.TryParse(quantityString, out AbsorbedDoseOfIonizingRadiation parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1016,6 +722,60 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Absorb Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Centigray, "cGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Decigray, "dGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, "fGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, "GGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Gray, "Gy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, "kGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, "krad")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Megagray, "MGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Megarad, "Mrad")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Microgray, "µGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Milligray, "mGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Millirad, "mrad")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, "nGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Petagray, "PGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Picogray, "pGy")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Rad, "rad")] + [InlineData("en-US", AbsorbedDoseOfIonizingRadiationUnit.Teragray, "TGy")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Centigray, "сГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Decigray, "дГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Femtogray, "фГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Gigagray, "ГГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Gray, "Гр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Kilogray, "кГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Kilorad, "крад")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Megagray, "МГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Megarad, "Мрад")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Microgray, "мкГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Milligray, "мГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Millirad, "мрад")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Nanogray, "нГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Petagray, "ПГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Picogray, "пГр")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Rad, "рад")] + [InlineData("ru-RU", AbsorbedDoseOfIonizingRadiationUnit.Teragray, "ТГр")] + public void GetAbbreviationForCulture(string culture, AbsorbedDoseOfIonizingRadiationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = AbsorbedDoseOfIonizingRadiation.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(AbsorbedDoseOfIonizingRadiation.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = AbsorbedDoseOfIonizingRadiation.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AbsorbedDoseOfIonizingRadiationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index c2b7b0da17..170023da22 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -348,378 +348,78 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm/s²", AccelerationUnit.CentimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 dm/s²", AccelerationUnit.DecimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 ft/s²", AccelerationUnit.FootPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 in/s²", AccelerationUnit.InchPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 km/s²", AccelerationUnit.KilometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 kn/h", AccelerationUnit.KnotPerHour, 4.2)] + [InlineData("en-US", "4.2 kn/min", AccelerationUnit.KnotPerMinute, 4.2)] + [InlineData("en-US", "4.2 kn/s", AccelerationUnit.KnotPerSecond, 4.2)] + [InlineData("en-US", "4.2 m/s²", AccelerationUnit.MeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 µm/s²", AccelerationUnit.MicrometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 mm/s²", AccelerationUnit.MillimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 mg", AccelerationUnit.MillistandardGravity, 4.2)] + [InlineData("en-US", "4.2 nm/s²", AccelerationUnit.NanometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 g", AccelerationUnit.StandardGravity, 4.2)] + [InlineData("ru-RU", "4,2 см/с²", AccelerationUnit.CentimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 дм/с²", AccelerationUnit.DecimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 фут/с²", AccelerationUnit.FootPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 дюйм/с²", AccelerationUnit.InchPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 км/с²", AccelerationUnit.KilometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 узел/час", AccelerationUnit.KnotPerHour, 4.2)] + [InlineData("ru-RU", "4,2 узел/мин", AccelerationUnit.KnotPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 узел/с", AccelerationUnit.KnotPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 м/с²", AccelerationUnit.MeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с²", AccelerationUnit.MicrometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мм/с²", AccelerationUnit.MillimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мg", AccelerationUnit.MillistandardGravity, 4.2)] + [InlineData("ru-RU", "4,2 нм/с²", AccelerationUnit.NanometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 g", AccelerationUnit.StandardGravity, 4.2)] + public void Parse(string culture, string quantityString, AccelerationUnit expectedUnit, double expectedValue) { - try - { - var parsed = Acceleration.Parse("1 cm/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 см/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 dm/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 дм/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 ft/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 фут/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 in/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 дюйм/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 km/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 км/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 kn/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KnotsPerHour, KnotsPerHourTolerance); - Assert.Equal(AccelerationUnit.KnotPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 узел/час", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KnotsPerHour, KnotsPerHourTolerance); - Assert.Equal(AccelerationUnit.KnotPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 kn/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KnotsPerMinute, KnotsPerMinuteTolerance); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 узел/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KnotsPerMinute, KnotsPerMinuteTolerance); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 kn/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KnotsPerSecond, KnotsPerSecondTolerance); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 узел/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KnotsPerSecond, KnotsPerSecondTolerance); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 m/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 м/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 µm/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 мкм/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 mm/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 мм/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 mg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillistandardGravity, MillistandardGravityTolerance); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 мg", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillistandardGravity, MillistandardGravityTolerance); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 nm/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 нм/с²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardGravity, StandardGravityTolerance); - Assert.Equal(AccelerationUnit.StandardGravity, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Acceleration.Parse("1 g", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.StandardGravity, StandardGravityTolerance); - Assert.Equal(AccelerationUnit.StandardGravity, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Acceleration.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm/s²", AccelerationUnit.CentimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 dm/s²", AccelerationUnit.DecimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 ft/s²", AccelerationUnit.FootPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 in/s²", AccelerationUnit.InchPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 km/s²", AccelerationUnit.KilometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 kn/h", AccelerationUnit.KnotPerHour, 4.2)] + [InlineData("en-US", "4.2 kn/min", AccelerationUnit.KnotPerMinute, 4.2)] + [InlineData("en-US", "4.2 kn/s", AccelerationUnit.KnotPerSecond, 4.2)] + [InlineData("en-US", "4.2 m/s²", AccelerationUnit.MeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 µm/s²", AccelerationUnit.MicrometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 mm/s²", AccelerationUnit.MillimeterPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 mg", AccelerationUnit.MillistandardGravity, 4.2)] + [InlineData("en-US", "4.2 nm/s²", AccelerationUnit.NanometerPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 g", AccelerationUnit.StandardGravity, 4.2)] + [InlineData("ru-RU", "4,2 см/с²", AccelerationUnit.CentimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 дм/с²", AccelerationUnit.DecimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 фут/с²", AccelerationUnit.FootPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 дюйм/с²", AccelerationUnit.InchPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 км/с²", AccelerationUnit.KilometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 узел/час", AccelerationUnit.KnotPerHour, 4.2)] + [InlineData("ru-RU", "4,2 узел/мин", AccelerationUnit.KnotPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 узел/с", AccelerationUnit.KnotPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 м/с²", AccelerationUnit.MeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с²", AccelerationUnit.MicrometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мм/с²", AccelerationUnit.MillimeterPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 мg", AccelerationUnit.MillistandardGravity, 4.2)] + [InlineData("ru-RU", "4,2 нм/с²", AccelerationUnit.NanometerPerSecondSquared, 4.2)] + [InlineData("ru-RU", "4,2 g", AccelerationUnit.StandardGravity, 4.2)] + public void TryParse(string culture, string quantityString, AccelerationUnit expectedUnit, double expectedValue) { - { - Assert.True(Acceleration.TryParse("1 cm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 см/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 dm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 дм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 ft/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 фут/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 in/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 дюйм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 km/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 км/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 kn/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerHour, KnotsPerHourTolerance); - Assert.Equal(AccelerationUnit.KnotPerHour, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 узел/час", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerHour, KnotsPerHourTolerance); - Assert.Equal(AccelerationUnit.KnotPerHour, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 kn/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerMinute, KnotsPerMinuteTolerance); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 узел/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerMinute, KnotsPerMinuteTolerance); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 kn/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerSecond, KnotsPerSecondTolerance); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 узел/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KnotsPerSecond, KnotsPerSecondTolerance); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 m/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 м/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 µm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 мкм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 mm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 мм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 mg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillistandardGravity, MillistandardGravityTolerance); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 мg", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillistandardGravity, MillistandardGravityTolerance); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 nm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 нм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardGravity, StandardGravityTolerance); - Assert.Equal(AccelerationUnit.StandardGravity, parsed.Unit); - } - - { - Assert.True(Acceleration.TryParse("1 g", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardGravity, StandardGravityTolerance); - Assert.Equal(AccelerationUnit.StandardGravity, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Acceleration.TryParse(quantityString, out Acceleration parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -956,6 +656,54 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Accele Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AccelerationUnit.CentimeterPerSecondSquared, "cm/s²")] + [InlineData("en-US", AccelerationUnit.DecimeterPerSecondSquared, "dm/s²")] + [InlineData("en-US", AccelerationUnit.FootPerSecondSquared, "ft/s²")] + [InlineData("en-US", AccelerationUnit.InchPerSecondSquared, "in/s²")] + [InlineData("en-US", AccelerationUnit.KilometerPerSecondSquared, "km/s²")] + [InlineData("en-US", AccelerationUnit.KnotPerHour, "kn/h")] + [InlineData("en-US", AccelerationUnit.KnotPerMinute, "kn/min")] + [InlineData("en-US", AccelerationUnit.KnotPerSecond, "kn/s")] + [InlineData("en-US", AccelerationUnit.MeterPerSecondSquared, "m/s²")] + [InlineData("en-US", AccelerationUnit.MicrometerPerSecondSquared, "µm/s²")] + [InlineData("en-US", AccelerationUnit.MillimeterPerSecondSquared, "mm/s²")] + [InlineData("en-US", AccelerationUnit.MillistandardGravity, "mg")] + [InlineData("en-US", AccelerationUnit.NanometerPerSecondSquared, "nm/s²")] + [InlineData("en-US", AccelerationUnit.StandardGravity, "g")] + [InlineData("ru-RU", AccelerationUnit.CentimeterPerSecondSquared, "см/с²")] + [InlineData("ru-RU", AccelerationUnit.DecimeterPerSecondSquared, "дм/с²")] + [InlineData("ru-RU", AccelerationUnit.FootPerSecondSquared, "фут/с²")] + [InlineData("ru-RU", AccelerationUnit.InchPerSecondSquared, "дюйм/с²")] + [InlineData("ru-RU", AccelerationUnit.KilometerPerSecondSquared, "км/с²")] + [InlineData("ru-RU", AccelerationUnit.KnotPerHour, "узел/час")] + [InlineData("ru-RU", AccelerationUnit.KnotPerMinute, "узел/мин")] + [InlineData("ru-RU", AccelerationUnit.KnotPerSecond, "узел/с")] + [InlineData("ru-RU", AccelerationUnit.MeterPerSecondSquared, "м/с²")] + [InlineData("ru-RU", AccelerationUnit.MicrometerPerSecondSquared, "мкм/с²")] + [InlineData("ru-RU", AccelerationUnit.MillimeterPerSecondSquared, "мм/с²")] + [InlineData("ru-RU", AccelerationUnit.MillistandardGravity, "мg")] + [InlineData("ru-RU", AccelerationUnit.NanometerPerSecondSquared, "нм/с²")] + [InlineData("ru-RU", AccelerationUnit.StandardGravity, "g")] + public void GetAbbreviationForCulture(string culture, AccelerationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Acceleration.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Acceleration.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Acceleration.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AccelerationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index 10c6ce403e..29ad68479f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -366,223 +366,56 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cmol", AmountOfSubstanceUnit.Centimole, 4.2)] + [InlineData("en-US", "4.2 clbmol", AmountOfSubstanceUnit.CentipoundMole, 4.2)] + [InlineData("en-US", "4.2 dmol", AmountOfSubstanceUnit.Decimole, 4.2)] + [InlineData("en-US", "4.2 dlbmol", AmountOfSubstanceUnit.DecipoundMole, 4.2)] + [InlineData("en-US", "4.2 fmol", AmountOfSubstanceUnit.Femtomole, 4.2)] + [InlineData("en-US", "4.2 kmol", AmountOfSubstanceUnit.Kilomole, 4.2)] + [InlineData("en-US", "4.2 klbmol", AmountOfSubstanceUnit.KilopoundMole, 4.2)] + [InlineData("en-US", "4.2 Mmol", AmountOfSubstanceUnit.Megamole, 4.2)] + [InlineData("en-US", "4.2 µmol", AmountOfSubstanceUnit.Micromole, 4.2)] + [InlineData("en-US", "4.2 µlbmol", AmountOfSubstanceUnit.MicropoundMole, 4.2)] + [InlineData("en-US", "4.2 mmol", AmountOfSubstanceUnit.Millimole, 4.2)] + [InlineData("en-US", "4.2 mlbmol", AmountOfSubstanceUnit.MillipoundMole, 4.2)] + [InlineData("en-US", "4.2 mol", AmountOfSubstanceUnit.Mole, 4.2)] + [InlineData("en-US", "4.2 nmol", AmountOfSubstanceUnit.Nanomole, 4.2)] + [InlineData("en-US", "4.2 nlbmol", AmountOfSubstanceUnit.NanopoundMole, 4.2)] + [InlineData("en-US", "4.2 pmol", AmountOfSubstanceUnit.Picomole, 4.2)] + [InlineData("en-US", "4.2 lbmol", AmountOfSubstanceUnit.PoundMole, 4.2)] + public void Parse(string culture, string quantityString, AmountOfSubstanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = AmountOfSubstance.Parse("1 cmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centimoles, CentimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Centimole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 clbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentipoundMoles, CentipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 dmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decimoles, DecimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Decimole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 dlbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecipoundMoles, DecipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 fmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtomoles, FemtomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Femtomole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 kmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilomoles, KilomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Kilomole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 klbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundMoles, KilopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 Mmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megamoles, MegamolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Megamole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 µmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micromoles, MicromolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Micromole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 µlbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicropoundMoles, MicropoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 mmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millimoles, MillimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Millimole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 mlbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillipoundMoles, MillipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Moles, MolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Mole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 nmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanomoles, NanomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Nanomole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 nlbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanopoundMoles, NanopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 pmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picomoles, PicomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Picomole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmountOfSubstance.Parse("1 lbmol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundMoles, PoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.PoundMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = AmountOfSubstance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cmol", AmountOfSubstanceUnit.Centimole, 4.2)] + [InlineData("en-US", "4.2 clbmol", AmountOfSubstanceUnit.CentipoundMole, 4.2)] + [InlineData("en-US", "4.2 dmol", AmountOfSubstanceUnit.Decimole, 4.2)] + [InlineData("en-US", "4.2 dlbmol", AmountOfSubstanceUnit.DecipoundMole, 4.2)] + [InlineData("en-US", "4.2 fmol", AmountOfSubstanceUnit.Femtomole, 4.2)] + [InlineData("en-US", "4.2 kmol", AmountOfSubstanceUnit.Kilomole, 4.2)] + [InlineData("en-US", "4.2 klbmol", AmountOfSubstanceUnit.KilopoundMole, 4.2)] + [InlineData("en-US", "4.2 Mmol", AmountOfSubstanceUnit.Megamole, 4.2)] + [InlineData("en-US", "4.2 µmol", AmountOfSubstanceUnit.Micromole, 4.2)] + [InlineData("en-US", "4.2 µlbmol", AmountOfSubstanceUnit.MicropoundMole, 4.2)] + [InlineData("en-US", "4.2 mmol", AmountOfSubstanceUnit.Millimole, 4.2)] + [InlineData("en-US", "4.2 mlbmol", AmountOfSubstanceUnit.MillipoundMole, 4.2)] + [InlineData("en-US", "4.2 mol", AmountOfSubstanceUnit.Mole, 4.2)] + [InlineData("en-US", "4.2 nmol", AmountOfSubstanceUnit.Nanomole, 4.2)] + [InlineData("en-US", "4.2 nlbmol", AmountOfSubstanceUnit.NanopoundMole, 4.2)] + [InlineData("en-US", "4.2 pmol", AmountOfSubstanceUnit.Picomole, 4.2)] + [InlineData("en-US", "4.2 lbmol", AmountOfSubstanceUnit.PoundMole, 4.2)] + public void TryParse(string culture, string quantityString, AmountOfSubstanceUnit expectedUnit, double expectedValue) { - { - Assert.True(AmountOfSubstance.TryParse("1 cmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centimoles, CentimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Centimole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 clbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentipoundMoles, CentipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 dmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decimoles, DecimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Decimole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 dlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecipoundMoles, DecipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 fmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtomoles, FemtomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Femtomole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 kmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilomoles, KilomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Kilomole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 klbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundMoles, KilopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 µmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micromoles, MicromolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Micromole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 µlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicropoundMoles, MicropoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 mlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillipoundMoles, MillipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Moles, MolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Mole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 nmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanomoles, NanomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Nanomole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 nlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanopoundMoles, NanopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 pmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picomoles, PicomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Picomole, parsed.Unit); - } - - { - Assert.True(AmountOfSubstance.TryParse("1 lbmol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundMoles, PoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.PoundMole, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(AmountOfSubstance.TryParse(quantityString, out AmountOfSubstance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -787,6 +620,43 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Amount Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AmountOfSubstanceUnit.Centimole, "cmol")] + [InlineData("en-US", AmountOfSubstanceUnit.CentipoundMole, "clbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Decimole, "dmol")] + [InlineData("en-US", AmountOfSubstanceUnit.DecipoundMole, "dlbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Femtomole, "fmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Kilomole, "kmol")] + [InlineData("en-US", AmountOfSubstanceUnit.KilopoundMole, "klbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Megamole, "Mmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Micromole, "µmol")] + [InlineData("en-US", AmountOfSubstanceUnit.MicropoundMole, "µlbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Millimole, "mmol")] + [InlineData("en-US", AmountOfSubstanceUnit.MillipoundMole, "mlbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Mole, "mol")] + [InlineData("en-US", AmountOfSubstanceUnit.Nanomole, "nmol")] + [InlineData("en-US", AmountOfSubstanceUnit.NanopoundMole, "nlbmol")] + [InlineData("en-US", AmountOfSubstanceUnit.Picomole, "pmol")] + [InlineData("en-US", AmountOfSubstanceUnit.PoundMole, "lbmol")] + public void GetAbbreviationForCulture(string culture, AmountOfSubstanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = AmountOfSubstance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(AmountOfSubstance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = AmountOfSubstance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AmountOfSubstanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index 9803546b40..3d547a9011 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -228,66 +228,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 dBµV", AmplitudeRatioUnit.DecibelMicrovolt, 4.2)] + [InlineData("en-US", "4.2 dBmV", AmplitudeRatioUnit.DecibelMillivolt, 4.2)] + [InlineData("en-US", "4.2 dBu", AmplitudeRatioUnit.DecibelUnloaded, 4.2)] + [InlineData("en-US", "4.2 dBV", AmplitudeRatioUnit.DecibelVolt, 4.2)] + public void Parse(string culture, string quantityString, AmplitudeRatioUnit expectedUnit, double expectedValue) { - try - { - var parsed = AmplitudeRatio.Parse("1 dBµV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelMicrovolts, DecibelMicrovoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMicrovolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmplitudeRatio.Parse("1 dBmV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelMillivolts, DecibelMillivoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMillivolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmplitudeRatio.Parse("1 dBu", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelsUnloaded, DecibelsUnloadedTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelUnloaded, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AmplitudeRatio.Parse("1 dBV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelVolts, DecibelVoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = AmplitudeRatio.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 dBµV", AmplitudeRatioUnit.DecibelMicrovolt, 4.2)] + [InlineData("en-US", "4.2 dBmV", AmplitudeRatioUnit.DecibelMillivolt, 4.2)] + [InlineData("en-US", "4.2 dBu", AmplitudeRatioUnit.DecibelUnloaded, 4.2)] + [InlineData("en-US", "4.2 dBV", AmplitudeRatioUnit.DecibelVolt, 4.2)] + public void TryParse(string culture, string quantityString, AmplitudeRatioUnit expectedUnit, double expectedValue) { - { - Assert.True(AmplitudeRatio.TryParse("1 dBµV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelMicrovolts, DecibelMicrovoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMicrovolt, parsed.Unit); - } - - { - Assert.True(AmplitudeRatio.TryParse("1 dBmV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelMillivolts, DecibelMillivoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMillivolt, parsed.Unit); - } - - { - Assert.True(AmplitudeRatio.TryParse("1 dBu", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelsUnloaded, DecibelsUnloadedTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelUnloaded, parsed.Unit); - } - - { - Assert.True(AmplitudeRatio.TryParse("1 dBV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelVolts, DecibelVoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelVolt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(AmplitudeRatio.TryParse(quantityString, out AmplitudeRatio parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -388,6 +352,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Amplit Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AmplitudeRatioUnit.DecibelMicrovolt, "dBµV")] + [InlineData("en-US", AmplitudeRatioUnit.DecibelMillivolt, "dBmV")] + [InlineData("en-US", AmplitudeRatioUnit.DecibelUnloaded, "dBu")] + [InlineData("en-US", AmplitudeRatioUnit.DecibelVolt, "dBV")] + public void GetAbbreviationForCulture(string culture, AmplitudeRatioUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = AmplitudeRatio.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(AmplitudeRatio.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = AmplitudeRatio.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AmplitudeRatioUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index c651a0e12a..16102c6acd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -294,495 +294,96 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 '", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 arcmin", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 amin", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 min", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 ″", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 arcsec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 asec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 sec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 crad", AngleUnit.Centiradian, 4.2)] + [InlineData("en-US", "4.2 drad", AngleUnit.Deciradian, 4.2)] + [InlineData("en-US", "4.2 °", AngleUnit.Degree, 4.2)] + [InlineData("en-US", "4.2 deg", AngleUnit.Degree, 4.2)] + [InlineData("en-US", "4.2 g", AngleUnit.Gradian, 4.2)] + [InlineData("en-US", "4.2 µ°", AngleUnit.Microdegree, 4.2)] + [InlineData("en-US", "4.2 µdeg", AngleUnit.Microdegree, 4.2)] + [InlineData("en-US", "4.2 µrad", AngleUnit.Microradian, 4.2)] + [InlineData("en-US", "4.2 m°", AngleUnit.Millidegree, 4.2)] + [InlineData("en-US", "4.2 mdeg", AngleUnit.Millidegree, 4.2)] + [InlineData("en-US", "4.2 mrad", AngleUnit.Milliradian, 4.2)] + [InlineData("en-US", "4.2 n°", AngleUnit.Nanodegree, 4.2)] + [InlineData("en-US", "4.2 ndeg", AngleUnit.Nanodegree, 4.2)] + [InlineData("en-US", "4.2 nrad", AngleUnit.Nanoradian, 4.2)] + [InlineData("en-US", "4.2 mil", AngleUnit.NatoMil, 4.2)] + [InlineData("en-US", "4.2 rad", AngleUnit.Radian, 4.2)] + [InlineData("en-US", "4.2 r", AngleUnit.Revolution, 4.2)] + [InlineData("ru-RU", "4,2 срад", AngleUnit.Centiradian, 4.2)] + [InlineData("ru-RU", "4,2 драд", AngleUnit.Deciradian, 4.2)] + [InlineData("ru-RU", "4,2 °", AngleUnit.Degree, 4.2)] + [InlineData("ru-RU", "4,2 g", AngleUnit.Gradian, 4.2)] + [InlineData("ru-RU", "4,2 мк°", AngleUnit.Microdegree, 4.2)] + [InlineData("ru-RU", "4,2 мкрад", AngleUnit.Microradian, 4.2)] + [InlineData("ru-RU", "4,2 м°", AngleUnit.Millidegree, 4.2)] + [InlineData("ru-RU", "4,2 мрад", AngleUnit.Milliradian, 4.2)] + [InlineData("ru-RU", "4,2 н°", AngleUnit.Nanodegree, 4.2)] + [InlineData("ru-RU", "4,2 нрад", AngleUnit.Nanoradian, 4.2)] + [InlineData("ru-RU", "4,2 рад", AngleUnit.Radian, 4.2)] + [InlineData("ru-RU", "4,2 r", AngleUnit.Revolution, 4.2)] + public void Parse(string culture, string quantityString, AngleUnit expectedUnit, double expectedValue) { - try - { - var parsed = Angle.Parse("1 '", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 arcmin", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 amin", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 ″", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 arcsec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 asec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 sec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 crad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centiradians, CentiradiansTolerance); - Assert.Equal(AngleUnit.Centiradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 срад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centiradians, CentiradiansTolerance); - Assert.Equal(AngleUnit.Centiradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 drad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Deciradians, DeciradiansTolerance); - Assert.Equal(AngleUnit.Deciradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 драд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Deciradians, DeciradiansTolerance); - Assert.Equal(AngleUnit.Deciradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 °", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 °", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gradians, GradiansTolerance); - Assert.Equal(AngleUnit.Gradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 g", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gradians, GradiansTolerance); - Assert.Equal(AngleUnit.Gradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 µ°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 µdeg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 мк°", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 µrad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microradians, MicroradiansTolerance); - Assert.Equal(AngleUnit.Microradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 мкрад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microradians, MicroradiansTolerance); - Assert.Equal(AngleUnit.Microradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 m°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 mdeg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 м°", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 mrad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliradians, MilliradiansTolerance); - Assert.Equal(AngleUnit.Milliradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 мрад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milliradians, MilliradiansTolerance); - Assert.Equal(AngleUnit.Milliradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 n°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 ndeg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 н°", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 nrad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoradians, NanoradiansTolerance); - Assert.Equal(AngleUnit.Nanoradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 нрад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanoradians, NanoradiansTolerance); - Assert.Equal(AngleUnit.Nanoradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 mil", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NatoMils, NatoMilsTolerance); - Assert.Equal(AngleUnit.NatoMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Radians, RadiansTolerance); - Assert.Equal(AngleUnit.Radian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 рад", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Radians, RadiansTolerance); - Assert.Equal(AngleUnit.Radian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 r", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Revolutions, RevolutionsTolerance); - Assert.Equal(AngleUnit.Revolution, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Angle.Parse("1 r", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Revolutions, RevolutionsTolerance); - Assert.Equal(AngleUnit.Revolution, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Angle.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 '", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 arcmin", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 amin", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 min", AngleUnit.Arcminute, 4.2)] + [InlineData("en-US", "4.2 ″", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 arcsec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 asec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 sec", AngleUnit.Arcsecond, 4.2)] + [InlineData("en-US", "4.2 crad", AngleUnit.Centiradian, 4.2)] + [InlineData("en-US", "4.2 drad", AngleUnit.Deciradian, 4.2)] + [InlineData("en-US", "4.2 °", AngleUnit.Degree, 4.2)] + [InlineData("en-US", "4.2 deg", AngleUnit.Degree, 4.2)] + [InlineData("en-US", "4.2 g", AngleUnit.Gradian, 4.2)] + [InlineData("en-US", "4.2 µ°", AngleUnit.Microdegree, 4.2)] + [InlineData("en-US", "4.2 µdeg", AngleUnit.Microdegree, 4.2)] + [InlineData("en-US", "4.2 µrad", AngleUnit.Microradian, 4.2)] + [InlineData("en-US", "4.2 m°", AngleUnit.Millidegree, 4.2)] + [InlineData("en-US", "4.2 mdeg", AngleUnit.Millidegree, 4.2)] + [InlineData("en-US", "4.2 mrad", AngleUnit.Milliradian, 4.2)] + [InlineData("en-US", "4.2 n°", AngleUnit.Nanodegree, 4.2)] + [InlineData("en-US", "4.2 ndeg", AngleUnit.Nanodegree, 4.2)] + [InlineData("en-US", "4.2 nrad", AngleUnit.Nanoradian, 4.2)] + [InlineData("en-US", "4.2 mil", AngleUnit.NatoMil, 4.2)] + [InlineData("en-US", "4.2 rad", AngleUnit.Radian, 4.2)] + [InlineData("en-US", "4.2 r", AngleUnit.Revolution, 4.2)] + [InlineData("ru-RU", "4,2 срад", AngleUnit.Centiradian, 4.2)] + [InlineData("ru-RU", "4,2 драд", AngleUnit.Deciradian, 4.2)] + [InlineData("ru-RU", "4,2 °", AngleUnit.Degree, 4.2)] + [InlineData("ru-RU", "4,2 g", AngleUnit.Gradian, 4.2)] + [InlineData("ru-RU", "4,2 мк°", AngleUnit.Microdegree, 4.2)] + [InlineData("ru-RU", "4,2 мкрад", AngleUnit.Microradian, 4.2)] + [InlineData("ru-RU", "4,2 м°", AngleUnit.Millidegree, 4.2)] + [InlineData("ru-RU", "4,2 мрад", AngleUnit.Milliradian, 4.2)] + [InlineData("ru-RU", "4,2 н°", AngleUnit.Nanodegree, 4.2)] + [InlineData("ru-RU", "4,2 нрад", AngleUnit.Nanoradian, 4.2)] + [InlineData("ru-RU", "4,2 рад", AngleUnit.Radian, 4.2)] + [InlineData("ru-RU", "4,2 r", AngleUnit.Revolution, 4.2)] + public void TryParse(string culture, string quantityString, AngleUnit expectedUnit, double expectedValue) { - { - Assert.True(Angle.TryParse("1 '", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 arcmin", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 amin", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcminutes, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 ″", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 arcsec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 asec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 sec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Arcseconds, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 crad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centiradians, CentiradiansTolerance); - Assert.Equal(AngleUnit.Centiradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 срад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centiradians, CentiradiansTolerance); - Assert.Equal(AngleUnit.Centiradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 drad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciradians, DeciradiansTolerance); - Assert.Equal(AngleUnit.Deciradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 драд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciradians, DeciradiansTolerance); - Assert.Equal(AngleUnit.Deciradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 °", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 °", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Degrees, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gradians, GradiansTolerance); - Assert.Equal(AngleUnit.Gradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 g", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gradians, GradiansTolerance); - Assert.Equal(AngleUnit.Gradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 µ°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 µdeg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 мк°", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microdegrees, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 µrad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microradians, MicroradiansTolerance); - Assert.Equal(AngleUnit.Microradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 мкрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microradians, MicroradiansTolerance); - Assert.Equal(AngleUnit.Microradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 m°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 mdeg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 м°", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millidegrees, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 mrad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliradians, MilliradiansTolerance); - Assert.Equal(AngleUnit.Milliradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 мрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliradians, MilliradiansTolerance); - Assert.Equal(AngleUnit.Milliradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 n°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 ndeg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 н°", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanodegrees, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 nrad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoradians, NanoradiansTolerance); - Assert.Equal(AngleUnit.Nanoradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 нрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoradians, NanoradiansTolerance); - Assert.Equal(AngleUnit.Nanoradian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 mil", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NatoMils, NatoMilsTolerance); - Assert.Equal(AngleUnit.NatoMil, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Radians, RadiansTolerance); - Assert.Equal(AngleUnit.Radian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 рад", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Radians, RadiansTolerance); - Assert.Equal(AngleUnit.Radian, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 r", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Revolutions, RevolutionsTolerance); - Assert.Equal(AngleUnit.Revolution, parsed.Unit); - } - - { - Assert.True(Angle.TryParse("1 r", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Revolutions, RevolutionsTolerance); - Assert.Equal(AngleUnit.Revolution, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Angle.TryParse(quantityString, out Angle parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1099,6 +700,53 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, AngleU Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AngleUnit.Arcminute, "'")] + [InlineData("en-US", AngleUnit.Arcsecond, "″")] + [InlineData("en-US", AngleUnit.Centiradian, "crad")] + [InlineData("en-US", AngleUnit.Deciradian, "drad")] + [InlineData("en-US", AngleUnit.Degree, "°")] + [InlineData("en-US", AngleUnit.Gradian, "g")] + [InlineData("en-US", AngleUnit.Microdegree, "µ°")] + [InlineData("en-US", AngleUnit.Microradian, "µrad")] + [InlineData("en-US", AngleUnit.Millidegree, "m°")] + [InlineData("en-US", AngleUnit.Milliradian, "mrad")] + [InlineData("en-US", AngleUnit.Nanodegree, "n°")] + [InlineData("en-US", AngleUnit.Nanoradian, "nrad")] + [InlineData("en-US", AngleUnit.NatoMil, "mil")] + [InlineData("en-US", AngleUnit.Radian, "rad")] + [InlineData("en-US", AngleUnit.Revolution, "r")] + [InlineData("ru-RU", AngleUnit.Centiradian, "срад")] + [InlineData("ru-RU", AngleUnit.Deciradian, "драд")] + [InlineData("ru-RU", AngleUnit.Degree, "°")] + [InlineData("ru-RU", AngleUnit.Gradian, "g")] + [InlineData("ru-RU", AngleUnit.Microdegree, "мк°")] + [InlineData("ru-RU", AngleUnit.Microradian, "мкрад")] + [InlineData("ru-RU", AngleUnit.Millidegree, "м°")] + [InlineData("ru-RU", AngleUnit.Milliradian, "мрад")] + [InlineData("ru-RU", AngleUnit.Nanodegree, "н°")] + [InlineData("ru-RU", AngleUnit.Nanoradian, "нрад")] + [InlineData("ru-RU", AngleUnit.Radian, "рад")] + [InlineData("ru-RU", AngleUnit.Revolution, "r")] + public void GetAbbreviationForCulture(string culture, AngleUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Angle.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Angle.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Angle.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AngleUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index ca6f11a492..57d8b84b59 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -282,66 +282,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g/m²", AreaDensityUnit.GramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 gsm", AreaDensityUnit.GramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg/m²", AreaDensityUnit.KilogramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mg/m²", AreaDensityUnit.MilligramPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, AreaDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = AreaDensity.Parse("1 g/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSquareMeter, GramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaDensity.Parse("1 gsm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSquareMeter, GramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaDensity.Parse("1 kg/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaDensity.Parse("1 mg/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSquareMeter, MilligramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.MilligramPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = AreaDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g/m²", AreaDensityUnit.GramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 gsm", AreaDensityUnit.GramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg/m²", AreaDensityUnit.KilogramPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mg/m²", AreaDensityUnit.MilligramPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, AreaDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(AreaDensity.TryParse("1 g/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSquareMeter, GramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsed.Unit); - } - - { - Assert.True(AreaDensity.TryParse("1 gsm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSquareMeter, GramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsed.Unit); - } - - { - Assert.True(AreaDensity.TryParse("1 kg/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, parsed.Unit); - } - - { - Assert.True(AreaDensity.TryParse("1 mg/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSquareMeter, MilligramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.MilligramPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(AreaDensity.TryParse(quantityString, out AreaDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -442,6 +406,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, AreaDe Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AreaDensityUnit.GramPerSquareMeter, "g/m²")] + [InlineData("en-US", AreaDensityUnit.KilogramPerSquareMeter, "kg/m²")] + [InlineData("en-US", AreaDensityUnit.MilligramPerSquareMeter, "mg/m²")] + public void GetAbbreviationForCulture(string culture, AreaDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = AreaDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(AreaDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = AreaDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AreaDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 3ff73437bb..ec1b503d62 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -300,92 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth, 4.2)] + [InlineData("en-US", "4.2 in⁴", AreaMomentOfInertiaUnit.InchToTheFourth, 4.2)] + [InlineData("en-US", "4.2 m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth, 4.2)] + public void Parse(string culture, string quantityString, AreaMomentOfInertiaUnit expectedUnit, double expectedValue) { - try - { - var parsed = AreaMomentOfInertia.Parse("1 cm⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersToTheFourth, CentimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaMomentOfInertia.Parse("1 dm⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersToTheFourth, DecimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaMomentOfInertia.Parse("1 ft⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetToTheFourth, FeetToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaMomentOfInertia.Parse("1 in⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesToTheFourth, InchesToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaMomentOfInertia.Parse("1 m⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersToTheFourth, MetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = AreaMomentOfInertia.Parse("1 mm⁴", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersToTheFourth, MillimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = AreaMomentOfInertia.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth, 4.2)] + [InlineData("en-US", "4.2 in⁴", AreaMomentOfInertiaUnit.InchToTheFourth, 4.2)] + [InlineData("en-US", "4.2 m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth, 4.2)] + [InlineData("en-US", "4.2 mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth, 4.2)] + public void TryParse(string culture, string quantityString, AreaMomentOfInertiaUnit expectedUnit, double expectedValue) { - { - Assert.True(AreaMomentOfInertia.TryParse("1 cm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersToTheFourth, CentimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsed.Unit); - } - - { - Assert.True(AreaMomentOfInertia.TryParse("1 dm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersToTheFourth, DecimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsed.Unit); - } - - { - Assert.True(AreaMomentOfInertia.TryParse("1 ft⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetToTheFourth, FeetToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsed.Unit); - } - - { - Assert.True(AreaMomentOfInertia.TryParse("1 in⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesToTheFourth, InchesToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsed.Unit); - } - - { - Assert.True(AreaMomentOfInertia.TryParse("1 m⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersToTheFourth, MetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsed.Unit); - } - - { - Assert.True(AreaMomentOfInertia.TryParse("1 mm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersToTheFourth, MillimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(AreaMomentOfInertia.TryParse(quantityString, out AreaMomentOfInertia parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -502,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, AreaMo Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", AreaMomentOfInertiaUnit.CentimeterToTheFourth, "cm⁴")] + [InlineData("en-US", AreaMomentOfInertiaUnit.DecimeterToTheFourth, "dm⁴")] + [InlineData("en-US", AreaMomentOfInertiaUnit.FootToTheFourth, "ft⁴")] + [InlineData("en-US", AreaMomentOfInertiaUnit.InchToTheFourth, "in⁴")] + [InlineData("en-US", AreaMomentOfInertiaUnit.MeterToTheFourth, "m⁴")] + [InlineData("en-US", AreaMomentOfInertiaUnit.MillimeterToTheFourth, "mm⁴")] + public void GetAbbreviationForCulture(string culture, AreaMomentOfInertiaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = AreaMomentOfInertia.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(AreaMomentOfInertia.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = AreaMomentOfInertia.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AreaMomentOfInertiaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index bc14f6d0e6..b90794afb7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -348,535 +348,114 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ac", AreaUnit.Acre, 4.2)] + [InlineData("en-US", "4.2 ha", AreaUnit.Hectare, 4.2)] + [InlineData("en-US", "4.2 cm²", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm²", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft²", AreaUnit.SquareFoot, 4.2)] + [InlineData("en-US", "4.2 in²", AreaUnit.SquareInch, 4.2)] + [InlineData("en-US", "4.2 km²", AreaUnit.SquareKilometer, 4.2)] + [InlineData("en-US", "4.2 m²", AreaUnit.SquareMeter, 4.2)] + [InlineData("en-US", "4.2 µm²", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi²", AreaUnit.SquareMile, 4.2)] + [InlineData("en-US", "4.2 mm²", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 nmi²", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("en-US", "4.2 yd²", AreaUnit.SquareYard, 4.2)] + [InlineData("en-US", "4.2 ft² (US)", AreaUnit.UsSurveySquareFoot, 4.2)] + [InlineData("ru-RU", "4,2 акр", AreaUnit.Acre, 4.2)] + [InlineData("ru-RU", "4,2 га", AreaUnit.Hectare, 4.2)] + [InlineData("ru-RU", "4,2 см²", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дм²", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 фут²", AreaUnit.SquareFoot, 4.2)] + [InlineData("ru-RU", "4,2 дюйм²", AreaUnit.SquareInch, 4.2)] + [InlineData("ru-RU", "4,2 км²", AreaUnit.SquareKilometer, 4.2)] + [InlineData("ru-RU", "4,2 м²", AreaUnit.SquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкм²", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля²", AreaUnit.SquareMile, 4.2)] + [InlineData("ru-RU", "4,2 мм²", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 морск.миля²", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("ru-RU", "4,2 ярд²", AreaUnit.SquareYard, 4.2)] + [InlineData("ru-RU", "4,2 фут² (US)", AreaUnit.UsSurveySquareFoot, 4.2)] + [InlineData("zh-CN", "4.2 平方厘米", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方分米", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方英尺", AreaUnit.SquareFoot, 4.2)] + [InlineData("zh-CN", "4.2 平方英寸", AreaUnit.SquareInch, 4.2)] + [InlineData("zh-CN", "4.2 平方公里", AreaUnit.SquareKilometer, 4.2)] + [InlineData("zh-CN", "4.2 平方米", AreaUnit.SquareMeter, 4.2)] + [InlineData("zh-CN", "4.2 平方微米", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("zh-CN", "4.2 平方英里", AreaUnit.SquareMile, 4.2)] + [InlineData("zh-CN", "4.2 平方毫米", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方海里", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("zh-CN", "4.2 平方码", AreaUnit.SquareYard, 4.2)] + public void Parse(string culture, string quantityString, AreaUnit expectedUnit, double expectedValue) { - try - { - var parsed = Area.Parse("1 ac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Acres, AcresTolerance); - Assert.Equal(AreaUnit.Acre, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 акр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Acres, AcresTolerance); - Assert.Equal(AreaUnit.Acre, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 英亩", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Acres, AcresTolerance); - Assert.Equal(AreaUnit.Acre, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 ha", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hectares, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 га", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hectares, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 英亩", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Hectares, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方厘米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方分米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 фут²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方英尺", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 дюйм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方英寸", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 km²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 км²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方公里", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 µm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方微米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 mi²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 миля²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方英里", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方毫米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 nmi²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 морск.миля²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方海里", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 yd²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 ярд²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 平方码", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 ft² (US)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsSurveySquareFeet, UsSurveySquareFeetTolerance); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Area.Parse("1 фут² (US)", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.UsSurveySquareFeet, UsSurveySquareFeetTolerance); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Area.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("zh-CN", "1 英亩")] // [Acre, Hectare] + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) { - { - Assert.True(Area.TryParse("1 ac", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Acres, AcresTolerance); - Assert.Equal(AreaUnit.Acre, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 акр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Acres, AcresTolerance); - Assert.Equal(AreaUnit.Acre, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 ha", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectares, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 га", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectares, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方厘米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方分米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareDecimeters, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 фут²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareFeet, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 дюйм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareInches, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 km²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 км²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方公里", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareKilometers, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 µm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方微米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMicrometers, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 mi²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 миля²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方英里", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMiles, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方毫米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMillimeters, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 nmi²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 морск.миля²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方海里", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareNauticalMiles, SquareNauticalMilesTolerance); - Assert.Equal(AreaUnit.SquareNauticalMile, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 yd²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 ярд²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 平方码", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareYards, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, parsed.Unit); - } - - { - Assert.True(Area.TryParse("1 ft² (US)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveySquareFeet, UsSurveySquareFeetTolerance); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsed.Unit); - } + Assert.Throws(() => Area.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Area.TryParse("1 фут² (US)", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveySquareFeet, UsSurveySquareFeetTolerance); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 ac", AreaUnit.Acre, 4.2)] + [InlineData("en-US", "4.2 ha", AreaUnit.Hectare, 4.2)] + [InlineData("en-US", "4.2 cm²", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm²", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft²", AreaUnit.SquareFoot, 4.2)] + [InlineData("en-US", "4.2 in²", AreaUnit.SquareInch, 4.2)] + [InlineData("en-US", "4.2 km²", AreaUnit.SquareKilometer, 4.2)] + [InlineData("en-US", "4.2 m²", AreaUnit.SquareMeter, 4.2)] + [InlineData("en-US", "4.2 µm²", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi²", AreaUnit.SquareMile, 4.2)] + [InlineData("en-US", "4.2 mm²", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 nmi²", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("en-US", "4.2 yd²", AreaUnit.SquareYard, 4.2)] + [InlineData("en-US", "4.2 ft² (US)", AreaUnit.UsSurveySquareFoot, 4.2)] + [InlineData("ru-RU", "4,2 акр", AreaUnit.Acre, 4.2)] + [InlineData("ru-RU", "4,2 га", AreaUnit.Hectare, 4.2)] + [InlineData("ru-RU", "4,2 см²", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дм²", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 фут²", AreaUnit.SquareFoot, 4.2)] + [InlineData("ru-RU", "4,2 дюйм²", AreaUnit.SquareInch, 4.2)] + [InlineData("ru-RU", "4,2 км²", AreaUnit.SquareKilometer, 4.2)] + [InlineData("ru-RU", "4,2 м²", AreaUnit.SquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкм²", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля²", AreaUnit.SquareMile, 4.2)] + [InlineData("ru-RU", "4,2 мм²", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 морск.миля²", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("ru-RU", "4,2 ярд²", AreaUnit.SquareYard, 4.2)] + [InlineData("ru-RU", "4,2 фут² (US)", AreaUnit.UsSurveySquareFoot, 4.2)] + [InlineData("zh-CN", "4.2 平方厘米", AreaUnit.SquareCentimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方分米", AreaUnit.SquareDecimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方英尺", AreaUnit.SquareFoot, 4.2)] + [InlineData("zh-CN", "4.2 平方英寸", AreaUnit.SquareInch, 4.2)] + [InlineData("zh-CN", "4.2 平方公里", AreaUnit.SquareKilometer, 4.2)] + [InlineData("zh-CN", "4.2 平方米", AreaUnit.SquareMeter, 4.2)] + [InlineData("zh-CN", "4.2 平方微米", AreaUnit.SquareMicrometer, 4.2)] + [InlineData("zh-CN", "4.2 平方英里", AreaUnit.SquareMile, 4.2)] + [InlineData("zh-CN", "4.2 平方毫米", AreaUnit.SquareMillimeter, 4.2)] + [InlineData("zh-CN", "4.2 平方海里", AreaUnit.SquareNauticalMile, 4.2)] + [InlineData("zh-CN", "4.2 平方码", AreaUnit.SquareYard, 4.2)] + public void TryParse(string culture, string quantityString, AreaUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(Area.TryParse(quantityString, out Area parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("zh-CN", "1 英亩")] // [Acre, Hectare] + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.False(Area.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] @@ -1171,6 +750,67 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi Assert.False(Area.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } + [Theory] + [InlineData("en-US", AreaUnit.Acre, "ac")] + [InlineData("en-US", AreaUnit.Hectare, "ha")] + [InlineData("en-US", AreaUnit.SquareCentimeter, "cm²")] + [InlineData("en-US", AreaUnit.SquareDecimeter, "dm²")] + [InlineData("en-US", AreaUnit.SquareFoot, "ft²")] + [InlineData("en-US", AreaUnit.SquareInch, "in²")] + [InlineData("en-US", AreaUnit.SquareKilometer, "km²")] + [InlineData("en-US", AreaUnit.SquareMeter, "m²")] + [InlineData("en-US", AreaUnit.SquareMicrometer, "µm²")] + [InlineData("en-US", AreaUnit.SquareMile, "mi²")] + [InlineData("en-US", AreaUnit.SquareMillimeter, "mm²")] + [InlineData("en-US", AreaUnit.SquareNauticalMile, "nmi²")] + [InlineData("en-US", AreaUnit.SquareYard, "yd²")] + [InlineData("en-US", AreaUnit.UsSurveySquareFoot, "ft² (US)")] + [InlineData("ru-RU", AreaUnit.Acre, "акр")] + [InlineData("ru-RU", AreaUnit.Hectare, "га")] + [InlineData("ru-RU", AreaUnit.SquareCentimeter, "см²")] + [InlineData("ru-RU", AreaUnit.SquareDecimeter, "дм²")] + [InlineData("ru-RU", AreaUnit.SquareFoot, "фут²")] + [InlineData("ru-RU", AreaUnit.SquareInch, "дюйм²")] + [InlineData("ru-RU", AreaUnit.SquareKilometer, "км²")] + [InlineData("ru-RU", AreaUnit.SquareMeter, "м²")] + [InlineData("ru-RU", AreaUnit.SquareMicrometer, "мкм²")] + [InlineData("ru-RU", AreaUnit.SquareMile, "миля²")] + [InlineData("ru-RU", AreaUnit.SquareMillimeter, "мм²")] + [InlineData("ru-RU", AreaUnit.SquareNauticalMile, "морск.миля²")] + [InlineData("ru-RU", AreaUnit.SquareYard, "ярд²")] + [InlineData("ru-RU", AreaUnit.UsSurveySquareFoot, "фут² (US)")] + [InlineData("zh-CN", AreaUnit.Acre, "英亩")] + [InlineData("zh-CN", AreaUnit.Hectare, "英亩")] + [InlineData("zh-CN", AreaUnit.SquareCentimeter, "平方厘米")] + [InlineData("zh-CN", AreaUnit.SquareDecimeter, "平方分米")] + [InlineData("zh-CN", AreaUnit.SquareFoot, "平方英尺")] + [InlineData("zh-CN", AreaUnit.SquareInch, "平方英寸")] + [InlineData("zh-CN", AreaUnit.SquareKilometer, "平方公里")] + [InlineData("zh-CN", AreaUnit.SquareMeter, "平方米")] + [InlineData("zh-CN", AreaUnit.SquareMicrometer, "平方微米")] + [InlineData("zh-CN", AreaUnit.SquareMile, "平方英里")] + [InlineData("zh-CN", AreaUnit.SquareMillimeter, "平方毫米")] + [InlineData("zh-CN", AreaUnit.SquareNauticalMile, "平方海里")] + [InlineData("zh-CN", AreaUnit.SquareYard, "平方码")] + public void GetAbbreviationForCulture(string culture, AreaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Area.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Area.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Area.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(AreaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 18a8837bb5..95edf1c3d4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -498,690 +498,126 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 bit/s", BitRateUnit.BitPerSecond, 4.2)] + [InlineData("en-US", "4.2 bps", BitRateUnit.BitPerSecond, 4.2)] + [InlineData("en-US", "4.2 B/s", BitRateUnit.BytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Ebit/s", BitRateUnit.ExabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Ebps", BitRateUnit.ExabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 EB/s", BitRateUnit.ExabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Eo/s", BitRateUnit.ExaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Eibit/s", BitRateUnit.ExbibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Eibps", BitRateUnit.ExbibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 EiB/s", BitRateUnit.ExbibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Eio/s", BitRateUnit.ExbioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gibit/s", BitRateUnit.GibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gibps", BitRateUnit.GibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 GiB/s", BitRateUnit.GibibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Gio/s", BitRateUnit.GibioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gbit/s", BitRateUnit.GigabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gbps", BitRateUnit.GigabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 GB/s", BitRateUnit.GigabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Go/s", BitRateUnit.GigaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Kibit/s", BitRateUnit.KibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Kibps", BitRateUnit.KibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 KiB/s", BitRateUnit.KibibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Kio/s", BitRateUnit.KibioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 kbit/s", BitRateUnit.KilobitPerSecond, 4.2)] + [InlineData("en-US", "4.2 kbps", BitRateUnit.KilobitPerSecond, 4.2)] + [InlineData("en-US", "4.2 kB/s", BitRateUnit.KilobytePerSecond, 4.2)] + [InlineData("en-US", "4.2 ko/s", BitRateUnit.KilooctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mibit/s", BitRateUnit.MebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mibps", BitRateUnit.MebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 MiB/s", BitRateUnit.MebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Mio/s", BitRateUnit.MebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mbit/s", BitRateUnit.MegabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mbps", BitRateUnit.MegabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 MB/s", BitRateUnit.MegabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Mo/s", BitRateUnit.MegaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 o/s", BitRateUnit.OctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pibit/s", BitRateUnit.PebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pibps", BitRateUnit.PebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 PiB/s", BitRateUnit.PebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Pio/s", BitRateUnit.PebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pbit/s", BitRateUnit.PetabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pbps", BitRateUnit.PetabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 PB/s", BitRateUnit.PetabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Po/s", BitRateUnit.PetaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tibit/s", BitRateUnit.TebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tibps", BitRateUnit.TebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 TiB/s", BitRateUnit.TebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Tio/s", BitRateUnit.TebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tbit/s", BitRateUnit.TerabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tbps", BitRateUnit.TerabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 TB/s", BitRateUnit.TerabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 To/s", BitRateUnit.TeraoctetPerSecond, 4.2)] + public void Parse(string culture, string quantityString, BitRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = BitRate.Parse("1 bit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BitsPerSecond, BitsPerSecondTolerance); - Assert.Equal(BitRateUnit.BitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 bps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BitsPerSecond, BitsPerSecondTolerance); - Assert.Equal(BitRateUnit.BitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 B/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BytesPerSecond, BytesPerSecondTolerance); - Assert.Equal(BitRateUnit.BytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Ebit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExabitsPerSecond, ExabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Ebps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExabitsPerSecond, ExabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 EB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExabytesPerSecond, ExabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Eo/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExaoctetsPerSecond, ExaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExaoctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Eibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExbibitsPerSecond, ExbibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Eibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExbibitsPerSecond, ExbibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 EiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExbibytesPerSecond, ExbibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Eio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ExbioctetsPerSecond, ExbioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Gibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GibibitsPerSecond, GibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Gibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GibibitsPerSecond, GibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 GiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GibibytesPerSecond, GibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Gio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GibioctetsPerSecond, GibioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Gbit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigabitsPerSecond, GigabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Gbps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigabitsPerSecond, GigabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 GB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigabytesPerSecond, GigabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Go/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigaoctetsPerSecond, GigaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigaoctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Kibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KibibitsPerSecond, KibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Kibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KibibitsPerSecond, KibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 KiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KibibytesPerSecond, KibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Kio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KibioctetsPerSecond, KibioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 kbit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobitsPerSecond, KilobitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 kbps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobitsPerSecond, KilobitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 kB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobytesPerSecond, KilobytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 ko/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilooctetsPerSecond, KilooctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilooctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MebibitsPerSecond, MebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MebibitsPerSecond, MebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 MiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MebibytesPerSecond, MebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MebioctetsPerSecond, MebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mbit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabitsPerSecond, MegabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mbps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabitsPerSecond, MegabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 MB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabytesPerSecond, MegabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Mo/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaoctetsPerSecond, MegaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegaoctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 o/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OctetsPerSecond, OctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.OctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Pibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PebibitsPerSecond, PebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Pibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PebibitsPerSecond, PebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 PiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PebibytesPerSecond, PebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Pio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PebioctetsPerSecond, PebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Pbit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetabitsPerSecond, PetabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Pbps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetabitsPerSecond, PetabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 PB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetabytesPerSecond, PetabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Po/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetaoctetsPerSecond, PetaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetaoctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Tibit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TebibitsPerSecond, TebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Tibps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TebibitsPerSecond, TebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 TiB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TebibytesPerSecond, TebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Tio/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TebioctetsPerSecond, TebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebioctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Tbit/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerabitsPerSecond, TerabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 Tbps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerabitsPerSecond, TerabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 TB/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerabytesPerSecond, TerabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabytePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BitRate.Parse("1 To/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TeraoctetsPerSecond, TeraoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.TeraoctetPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = BitRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 bit/s", BitRateUnit.BitPerSecond, 4.2)] + [InlineData("en-US", "4.2 bps", BitRateUnit.BitPerSecond, 4.2)] + [InlineData("en-US", "4.2 B/s", BitRateUnit.BytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Ebit/s", BitRateUnit.ExabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Ebps", BitRateUnit.ExabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 EB/s", BitRateUnit.ExabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Eo/s", BitRateUnit.ExaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Eibit/s", BitRateUnit.ExbibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Eibps", BitRateUnit.ExbibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 EiB/s", BitRateUnit.ExbibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Eio/s", BitRateUnit.ExbioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gibit/s", BitRateUnit.GibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gibps", BitRateUnit.GibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 GiB/s", BitRateUnit.GibibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Gio/s", BitRateUnit.GibioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gbit/s", BitRateUnit.GigabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Gbps", BitRateUnit.GigabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 GB/s", BitRateUnit.GigabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Go/s", BitRateUnit.GigaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Kibit/s", BitRateUnit.KibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Kibps", BitRateUnit.KibibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 KiB/s", BitRateUnit.KibibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Kio/s", BitRateUnit.KibioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 kbit/s", BitRateUnit.KilobitPerSecond, 4.2)] + [InlineData("en-US", "4.2 kbps", BitRateUnit.KilobitPerSecond, 4.2)] + [InlineData("en-US", "4.2 kB/s", BitRateUnit.KilobytePerSecond, 4.2)] + [InlineData("en-US", "4.2 ko/s", BitRateUnit.KilooctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mibit/s", BitRateUnit.MebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mibps", BitRateUnit.MebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 MiB/s", BitRateUnit.MebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Mio/s", BitRateUnit.MebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mbit/s", BitRateUnit.MegabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mbps", BitRateUnit.MegabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 MB/s", BitRateUnit.MegabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Mo/s", BitRateUnit.MegaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 o/s", BitRateUnit.OctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pibit/s", BitRateUnit.PebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pibps", BitRateUnit.PebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 PiB/s", BitRateUnit.PebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Pio/s", BitRateUnit.PebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pbit/s", BitRateUnit.PetabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pbps", BitRateUnit.PetabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 PB/s", BitRateUnit.PetabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Po/s", BitRateUnit.PetaoctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tibit/s", BitRateUnit.TebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tibps", BitRateUnit.TebibitPerSecond, 4.2)] + [InlineData("en-US", "4.2 TiB/s", BitRateUnit.TebibytePerSecond, 4.2)] + [InlineData("en-US", "4.2 Tio/s", BitRateUnit.TebioctetPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tbit/s", BitRateUnit.TerabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 Tbps", BitRateUnit.TerabitPerSecond, 4.2)] + [InlineData("en-US", "4.2 TB/s", BitRateUnit.TerabytePerSecond, 4.2)] + [InlineData("en-US", "4.2 To/s", BitRateUnit.TeraoctetPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, BitRateUnit expectedUnit, double expectedValue) { - { - Assert.True(BitRate.TryParse("1 bit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BitsPerSecond, BitsPerSecondTolerance); - Assert.Equal(BitRateUnit.BitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 bps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BitsPerSecond, BitsPerSecondTolerance); - Assert.Equal(BitRateUnit.BitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 B/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BytesPerSecond, BytesPerSecondTolerance); - Assert.Equal(BitRateUnit.BytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Ebit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExabitsPerSecond, ExabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Ebps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExabitsPerSecond, ExabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 EB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExabytesPerSecond, ExabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Eo/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExaoctetsPerSecond, ExaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExaoctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Eibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExbibitsPerSecond, ExbibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Eibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExbibitsPerSecond, ExbibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 EiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExbibytesPerSecond, ExbibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Eio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ExbioctetsPerSecond, ExbioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Gibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GibibitsPerSecond, GibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Gibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GibibitsPerSecond, GibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 GiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GibibytesPerSecond, GibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Gio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GibioctetsPerSecond, GibioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Gbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigabitsPerSecond, GigabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Gbps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigabitsPerSecond, GigabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 GB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigabytesPerSecond, GigabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Go/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigaoctetsPerSecond, GigaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigaoctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Kibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KibibitsPerSecond, KibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Kibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KibibitsPerSecond, KibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 KiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KibibytesPerSecond, KibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Kio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KibioctetsPerSecond, KibioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 kbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobitsPerSecond, KilobitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 kbps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobitsPerSecond, KilobitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 kB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobytesPerSecond, KilobytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 ko/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilooctetsPerSecond, KilooctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilooctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MebibitsPerSecond, MebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MebibitsPerSecond, MebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 MiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MebibytesPerSecond, MebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MebioctetsPerSecond, MebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabitsPerSecond, MegabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mbps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabitsPerSecond, MegabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 MB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabytesPerSecond, MegabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Mo/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaoctetsPerSecond, MegaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegaoctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 o/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OctetsPerSecond, OctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.OctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Pibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PebibitsPerSecond, PebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Pibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PebibitsPerSecond, PebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 PiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PebibytesPerSecond, PebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Pio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PebioctetsPerSecond, PebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Pbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetabitsPerSecond, PetabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Pbps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetabitsPerSecond, PetabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 PB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetabytesPerSecond, PetabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Po/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetaoctetsPerSecond, PetaoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetaoctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Tibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TebibitsPerSecond, TebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Tibps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TebibitsPerSecond, TebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 TiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TebibytesPerSecond, TebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Tio/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TebioctetsPerSecond, TebioctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebioctetPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Tbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerabitsPerSecond, TerabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 Tbps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerabitsPerSecond, TerabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 TB/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerabytesPerSecond, TerabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabytePerSecond, parsed.Unit); - } - - { - Assert.True(BitRate.TryParse("1 To/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TeraoctetsPerSecond, TeraoctetsPerSecondTolerance); - Assert.Equal(BitRateUnit.TeraoctetPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(BitRate.TryParse(quantityString, out BitRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1666,6 +1102,65 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, BitRat Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", BitRateUnit.BitPerSecond, "bit/s")] + [InlineData("en-US", BitRateUnit.BytePerSecond, "B/s")] + [InlineData("en-US", BitRateUnit.ExabitPerSecond, "Ebit/s")] + [InlineData("en-US", BitRateUnit.ExabytePerSecond, "EB/s")] + [InlineData("en-US", BitRateUnit.ExaoctetPerSecond, "Eo/s")] + [InlineData("en-US", BitRateUnit.ExbibitPerSecond, "Eibit/s")] + [InlineData("en-US", BitRateUnit.ExbibytePerSecond, "EiB/s")] + [InlineData("en-US", BitRateUnit.ExbioctetPerSecond, "Eio/s")] + [InlineData("en-US", BitRateUnit.GibibitPerSecond, "Gibit/s")] + [InlineData("en-US", BitRateUnit.GibibytePerSecond, "GiB/s")] + [InlineData("en-US", BitRateUnit.GibioctetPerSecond, "Gio/s")] + [InlineData("en-US", BitRateUnit.GigabitPerSecond, "Gbit/s")] + [InlineData("en-US", BitRateUnit.GigabytePerSecond, "GB/s")] + [InlineData("en-US", BitRateUnit.GigaoctetPerSecond, "Go/s")] + [InlineData("en-US", BitRateUnit.KibibitPerSecond, "Kibit/s")] + [InlineData("en-US", BitRateUnit.KibibytePerSecond, "KiB/s")] + [InlineData("en-US", BitRateUnit.KibioctetPerSecond, "Kio/s")] + [InlineData("en-US", BitRateUnit.KilobitPerSecond, "kbit/s")] + [InlineData("en-US", BitRateUnit.KilobytePerSecond, "kB/s")] + [InlineData("en-US", BitRateUnit.KilooctetPerSecond, "ko/s")] + [InlineData("en-US", BitRateUnit.MebibitPerSecond, "Mibit/s")] + [InlineData("en-US", BitRateUnit.MebibytePerSecond, "MiB/s")] + [InlineData("en-US", BitRateUnit.MebioctetPerSecond, "Mio/s")] + [InlineData("en-US", BitRateUnit.MegabitPerSecond, "Mbit/s")] + [InlineData("en-US", BitRateUnit.MegabytePerSecond, "MB/s")] + [InlineData("en-US", BitRateUnit.MegaoctetPerSecond, "Mo/s")] + [InlineData("en-US", BitRateUnit.OctetPerSecond, "o/s")] + [InlineData("en-US", BitRateUnit.PebibitPerSecond, "Pibit/s")] + [InlineData("en-US", BitRateUnit.PebibytePerSecond, "PiB/s")] + [InlineData("en-US", BitRateUnit.PebioctetPerSecond, "Pio/s")] + [InlineData("en-US", BitRateUnit.PetabitPerSecond, "Pbit/s")] + [InlineData("en-US", BitRateUnit.PetabytePerSecond, "PB/s")] + [InlineData("en-US", BitRateUnit.PetaoctetPerSecond, "Po/s")] + [InlineData("en-US", BitRateUnit.TebibitPerSecond, "Tibit/s")] + [InlineData("en-US", BitRateUnit.TebibytePerSecond, "TiB/s")] + [InlineData("en-US", BitRateUnit.TebioctetPerSecond, "Tio/s")] + [InlineData("en-US", BitRateUnit.TerabitPerSecond, "Tbit/s")] + [InlineData("en-US", BitRateUnit.TerabytePerSecond, "TB/s")] + [InlineData("en-US", BitRateUnit.TeraoctetPerSecond, "To/s")] + public void GetAbbreviationForCulture(string culture, BitRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = BitRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(BitRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = BitRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(BitRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 062711daa6..68bb544ba4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, 4.2)] + [InlineData("en-US", "4.2 kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 4.2)] + [InlineData("en-US", "4.2 lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, 4.2)] + public void Parse(string culture, string quantityString, BrakeSpecificFuelConsumptionUnit expectedUnit, double expectedValue) { - try - { - var parsed = BrakeSpecificFuelConsumption.Parse("1 g/kWh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerKiloWattHour, GramsPerKiloWattHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BrakeSpecificFuelConsumption.Parse("1 kg/J", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerJoule, KilogramsPerJouleTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = BrakeSpecificFuelConsumption.Parse("1 lb/hph", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerMechanicalHorsepowerHour, PoundsPerMechanicalHorsepowerHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = BrakeSpecificFuelConsumption.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, 4.2)] + [InlineData("en-US", "4.2 kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 4.2)] + [InlineData("en-US", "4.2 lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, 4.2)] + public void TryParse(string culture, string quantityString, BrakeSpecificFuelConsumptionUnit expectedUnit, double expectedValue) { - { - Assert.True(BrakeSpecificFuelConsumption.TryParse("1 g/kWh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerKiloWattHour, GramsPerKiloWattHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, parsed.Unit); - } - - { - Assert.True(BrakeSpecificFuelConsumption.TryParse("1 kg/J", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerJoule, KilogramsPerJouleTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, parsed.Unit); - } - - { - Assert.True(BrakeSpecificFuelConsumption.TryParse("1 lb/hph", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerMechanicalHorsepowerHour, PoundsPerMechanicalHorsepowerHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(BrakeSpecificFuelConsumption.TryParse(quantityString, out BrakeSpecificFuelConsumption parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, BrakeS Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, "g/kWh")] + [InlineData("en-US", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, "kg/J")] + [InlineData("en-US", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, "lb/hph")] + public void GetAbbreviationForCulture(string culture, BrakeSpecificFuelConsumptionUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = BrakeSpecificFuelConsumption.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(BrakeSpecificFuelConsumption.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = BrakeSpecificFuelConsumption.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(BrakeSpecificFuelConsumptionUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 985baaa4ae..964c28b46e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -300,92 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 °C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 °F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin, 4.2)] + [InlineData("en-US", "4.2 ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin, 4.2)] + public void Parse(string culture, string quantityString, CoefficientOfThermalExpansionUnit expectedUnit, double expectedValue) { - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 °C⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PerDegreeCelsius, PerDegreeCelsiusTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 °F⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PerDegreeFahrenheit, PerDegreeFahrenheitTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 K⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PerKelvin, PerKelvinTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 ppm/°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PpmPerDegreeCelsius, PpmPerDegreeCelsiusTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 ppm/°F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PpmPerDegreeFahrenheit, PpmPerDegreeFahrenheitTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = CoefficientOfThermalExpansion.Parse("1 ppm/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PpmPerKelvin, PpmPerKelvinTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = CoefficientOfThermalExpansion.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 °C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 °F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin, 4.2)] + [InlineData("en-US", "4.2 ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin, 4.2)] + public void TryParse(string culture, string quantityString, CoefficientOfThermalExpansionUnit expectedUnit, double expectedValue) { - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 °C⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PerDegreeCelsius, PerDegreeCelsiusTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, parsed.Unit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 °F⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PerDegreeFahrenheit, PerDegreeFahrenheitTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, parsed.Unit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 K⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PerKelvin, PerKelvinTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerKelvin, parsed.Unit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 ppm/°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PpmPerDegreeCelsius, PpmPerDegreeCelsiusTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, parsed.Unit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 ppm/°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PpmPerDegreeFahrenheit, PpmPerDegreeFahrenheitTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, parsed.Unit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParse("1 ppm/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PpmPerKelvin, PpmPerKelvinTolerance); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(CoefficientOfThermalExpansion.TryParse(quantityString, out CoefficientOfThermalExpansion parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -502,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Coeffi Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PerDegreeCelsius, "°C⁻¹")] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, "°F⁻¹")] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PerKelvin, "K⁻¹")] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, "ppm/°C")] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, "ppm/°F")] + [InlineData("en-US", CoefficientOfThermalExpansionUnit.PpmPerKelvin, "ppm/K")] + public void GetAbbreviationForCulture(string culture, CoefficientOfThermalExpansionUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = CoefficientOfThermalExpansion.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(CoefficientOfThermalExpansion.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = CoefficientOfThermalExpansion.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(CoefficientOfThermalExpansionUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index 2699d32a58..808d9e594e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -306,196 +306,50 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 atm⁻¹", CompressibilityUnit.InverseAtmosphere, 4.2)] + [InlineData("en-US", "4.2 1/atm", CompressibilityUnit.InverseAtmosphere, 4.2)] + [InlineData("en-US", "4.2 bar⁻¹", CompressibilityUnit.InverseBar, 4.2)] + [InlineData("en-US", "4.2 1/bar", CompressibilityUnit.InverseBar, 4.2)] + [InlineData("en-US", "4.2 kPa⁻¹", CompressibilityUnit.InverseKilopascal, 4.2)] + [InlineData("en-US", "4.2 1/kPa", CompressibilityUnit.InverseKilopascal, 4.2)] + [InlineData("en-US", "4.2 MPa⁻¹", CompressibilityUnit.InverseMegapascal, 4.2)] + [InlineData("en-US", "4.2 1/MPa", CompressibilityUnit.InverseMegapascal, 4.2)] + [InlineData("en-US", "4.2 mbar⁻¹", CompressibilityUnit.InverseMillibar, 4.2)] + [InlineData("en-US", "4.2 1/mbar", CompressibilityUnit.InverseMillibar, 4.2)] + [InlineData("en-US", "4.2 Pa⁻¹", CompressibilityUnit.InversePascal, 4.2)] + [InlineData("en-US", "4.2 1/Pa", CompressibilityUnit.InversePascal, 4.2)] + [InlineData("en-US", "4.2 psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 1/psi", CompressibilityUnit.InversePoundForcePerSquareInch, 4.2)] + public void Parse(string culture, string quantityString, CompressibilityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Compressibility.Parse("1 atm⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseAtmospheres, InverseAtmospheresTolerance); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/atm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseAtmospheres, InverseAtmospheresTolerance); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 bar⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseBars, InverseBarsTolerance); - Assert.Equal(CompressibilityUnit.InverseBar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/bar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseBars, InverseBarsTolerance); - Assert.Equal(CompressibilityUnit.InverseBar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 kPa⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseKilopascals, InverseKilopascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/kPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseKilopascals, InverseKilopascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 MPa⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMegapascals, InverseMegapascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/MPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMegapascals, InverseMegapascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 mbar⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMillibars, InverseMillibarsTolerance); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/mbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMillibars, InverseMillibarsTolerance); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 Pa⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InversePascals, InversePascalsTolerance); - Assert.Equal(CompressibilityUnit.InversePascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/Pa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InversePascals, InversePascalsTolerance); - Assert.Equal(CompressibilityUnit.InversePascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 psi⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Compressibility.Parse("1 1/psi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Compressibility.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 atm⁻¹", CompressibilityUnit.InverseAtmosphere, 4.2)] + [InlineData("en-US", "4.2 1/atm", CompressibilityUnit.InverseAtmosphere, 4.2)] + [InlineData("en-US", "4.2 bar⁻¹", CompressibilityUnit.InverseBar, 4.2)] + [InlineData("en-US", "4.2 1/bar", CompressibilityUnit.InverseBar, 4.2)] + [InlineData("en-US", "4.2 kPa⁻¹", CompressibilityUnit.InverseKilopascal, 4.2)] + [InlineData("en-US", "4.2 1/kPa", CompressibilityUnit.InverseKilopascal, 4.2)] + [InlineData("en-US", "4.2 MPa⁻¹", CompressibilityUnit.InverseMegapascal, 4.2)] + [InlineData("en-US", "4.2 1/MPa", CompressibilityUnit.InverseMegapascal, 4.2)] + [InlineData("en-US", "4.2 mbar⁻¹", CompressibilityUnit.InverseMillibar, 4.2)] + [InlineData("en-US", "4.2 1/mbar", CompressibilityUnit.InverseMillibar, 4.2)] + [InlineData("en-US", "4.2 Pa⁻¹", CompressibilityUnit.InversePascal, 4.2)] + [InlineData("en-US", "4.2 1/Pa", CompressibilityUnit.InversePascal, 4.2)] + [InlineData("en-US", "4.2 psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 1/psi", CompressibilityUnit.InversePoundForcePerSquareInch, 4.2)] + public void TryParse(string culture, string quantityString, CompressibilityUnit expectedUnit, double expectedValue) { - { - Assert.True(Compressibility.TryParse("1 atm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseAtmospheres, InverseAtmospheresTolerance); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/atm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseAtmospheres, InverseAtmospheresTolerance); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 bar⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseBars, InverseBarsTolerance); - Assert.Equal(CompressibilityUnit.InverseBar, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/bar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseBars, InverseBarsTolerance); - Assert.Equal(CompressibilityUnit.InverseBar, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 kPa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseKilopascals, InverseKilopascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/kPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseKilopascals, InverseKilopascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 MPa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMegapascals, InverseMegapascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/MPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMegapascals, InverseMegapascalsTolerance); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 mbar⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMillibars, InverseMillibarsTolerance); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/mbar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMillibars, InverseMillibarsTolerance); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 Pa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InversePascals, InversePascalsTolerance); - Assert.Equal(CompressibilityUnit.InversePascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/Pa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InversePascals, InversePascalsTolerance); - Assert.Equal(CompressibilityUnit.InversePascal, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 psi⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Compressibility.TryParse("1 1/psi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Compressibility.TryParse(quantityString, out Compressibility parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -676,6 +530,33 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Compre Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", CompressibilityUnit.InverseAtmosphere, "atm⁻¹")] + [InlineData("en-US", CompressibilityUnit.InverseBar, "bar⁻¹")] + [InlineData("en-US", CompressibilityUnit.InverseKilopascal, "kPa⁻¹")] + [InlineData("en-US", CompressibilityUnit.InverseMegapascal, "MPa⁻¹")] + [InlineData("en-US", CompressibilityUnit.InverseMillibar, "mbar⁻¹")] + [InlineData("en-US", CompressibilityUnit.InversePascal, "Pa⁻¹")] + [InlineData("en-US", CompressibilityUnit.InversePoundForcePerSquareInch, "psi⁻¹")] + public void GetAbbreviationForCulture(string culture, CompressibilityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Compressibility.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Compressibility.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Compressibility.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(CompressibilityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index cc6b11ecb4..2a7cc9de73 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -600,872 +600,154 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg/dl", DensityUnit.CentigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 cg/l", DensityUnit.CentigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 cg/ml", DensityUnit.CentigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dg/dl", DensityUnit.DecigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 dg/l", DensityUnit.DecigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 dg/ml", DensityUnit.DecigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 fg/dl", DensityUnit.FemtogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 fg/l", DensityUnit.FemtogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 fg/ml", DensityUnit.FemtogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 g/cm³", DensityUnit.GramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/ft³", DensityUnit.GramPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 g/in³", DensityUnit.GramPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 g/m³", DensityUnit.GramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm³", DensityUnit.GramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 g/dl", DensityUnit.GramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 g/l", DensityUnit.GramPerLiter, 4.2)] + [InlineData("en-US", "4.2 g/ml", DensityUnit.GramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 kg/cm³", DensityUnit.KilogramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/m³", DensityUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm³", DensityUnit.KilogramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/l", DensityUnit.KilogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 kip/ft³", DensityUnit.KilopoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kip/in³", DensityUnit.KilopoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 kip/yd³", DensityUnit.KilopoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 µg/m³", DensityUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µg/dl", DensityUnit.MicrogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 µg/l", DensityUnit.MicrogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 µg/ml", DensityUnit.MicrogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mg/m³", DensityUnit.MilligramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mg/dl", DensityUnit.MilligramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 mg/l", DensityUnit.MilligramPerLiter, 4.2)] + [InlineData("en-US", "4.2 mg/ml", DensityUnit.MilligramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ng/dl", DensityUnit.NanogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 ng/l", DensityUnit.NanogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 ng/ml", DensityUnit.NanogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 pg/dl", DensityUnit.PicogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 pg/l", DensityUnit.PicogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 pg/ml", DensityUnit.PicogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 lb/cm³", DensityUnit.PoundPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 lbm/cm³", DensityUnit.PoundPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 lb/ft³", DensityUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lbm/ft³", DensityUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in³", DensityUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 lbm/in³", DensityUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 lb/m³", DensityUnit.PoundPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 lbm/m³", DensityUnit.PoundPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 lb/mm³", DensityUnit.PoundPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbm/mm³", DensityUnit.PoundPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb/yd³", DensityUnit.PoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 lbm/yd³", DensityUnit.PoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 ppg (imp.)", DensityUnit.PoundPerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 ppg (U.S.)", DensityUnit.PoundPerUSGallon, 4.2)] + [InlineData("en-US", "4.2 slug/cm³", DensityUnit.SlugPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 slug/ft³", DensityUnit.SlugPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 slug/in³", DensityUnit.SlugPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 slug/m³", DensityUnit.SlugPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 slug/mm³", DensityUnit.SlugPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 t/cm³", DensityUnit.TonnePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 t/ft³", DensityUnit.TonnePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 t/in³", DensityUnit.TonnePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 t/m³", DensityUnit.TonnePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 t/mm³", DensityUnit.TonnePerCubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 г/м³", DensityUnit.GramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 кг/м³", DensityUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкг/м³", DensityUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мг/м³", DensityUnit.MilligramPerCubicMeter, 4.2)] + public void Parse(string culture, string quantityString, DensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Density.Parse("1 cg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDeciliter, CentigramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.CentigramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 cg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerLiter, CentigramsPerLiterTolerance); - Assert.Equal(DensityUnit.CentigramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 cg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.CentigramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 dg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDeciliter, DecigramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.DecigramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 dg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerLiter, DecigramsPerLiterTolerance); - Assert.Equal(DensityUnit.DecigramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 dg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.DecigramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 fg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerDeciliter, FemtogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.FemtogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 fg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerLiter, FemtogramsPerLiterTolerance); - Assert.Equal(DensityUnit.FemtogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 fg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerMilliliter, FemtogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.FemtogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicFoot, GramsPerCubicFootTolerance); - Assert.Equal(DensityUnit.GramPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicInch, GramsPerCubicInchTolerance); - Assert.Equal(DensityUnit.GramPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 г/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerDeciliter, GramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.GramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerLiter, GramsPerLiterTolerance); - Assert.Equal(DensityUnit.GramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 g/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMilliliter, GramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.GramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kg/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 кг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kg/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerLiter, KilogramsPerLiterTolerance); - Assert.Equal(DensityUnit.KilogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kip/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kip/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 kip/yd³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicYard, KilopoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 µg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 мкг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 µg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDeciliter, MicrogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.MicrogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 µg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerLiter, MicrogramsPerLiterTolerance); - Assert.Equal(DensityUnit.MicrogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 µg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MicrogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 mg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 мг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 mg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerDeciliter, MilligramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.MilligramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 mg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerLiter, MilligramsPerLiterTolerance); - Assert.Equal(DensityUnit.MilligramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 mg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MilligramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 ng/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDeciliter, NanogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.NanogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 ng/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerLiter, NanogramsPerLiterTolerance); - Assert.Equal(DensityUnit.NanogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 ng/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.NanogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 pg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerDeciliter, PicogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.PicogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 pg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerLiter, PicogramsPerLiterTolerance); - Assert.Equal(DensityUnit.PicogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 pg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.PicogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicCentimeter, PoundsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicCentimeter, PoundsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMeter, PoundsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMeter, PoundsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMillimeter, PoundsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMillimeter, PoundsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lb/yd³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicYard, PoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 lbm/yd³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicYard, PoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 ppg (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - Assert.Equal(DensityUnit.PoundPerImperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 ppg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerUSGallon, PoundsPerUSGallonTolerance); - Assert.Equal(DensityUnit.PoundPerUSGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 slug/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicCentimeter, SlugsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 slug/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - Assert.Equal(DensityUnit.SlugPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 slug/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicInch, SlugsPerCubicInchTolerance); - Assert.Equal(DensityUnit.SlugPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 slug/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicMeter, SlugsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 slug/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicMillimeter, SlugsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 t/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 t/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicFoot, TonnesPerCubicFootTolerance); - Assert.Equal(DensityUnit.TonnePerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 t/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicInch, TonnesPerCubicInchTolerance); - Assert.Equal(DensityUnit.TonnePerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 t/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Density.Parse("1 t/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Density.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cg/dl", DensityUnit.CentigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 cg/l", DensityUnit.CentigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 cg/ml", DensityUnit.CentigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dg/dl", DensityUnit.DecigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 dg/l", DensityUnit.DecigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 dg/ml", DensityUnit.DecigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 fg/dl", DensityUnit.FemtogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 fg/l", DensityUnit.FemtogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 fg/ml", DensityUnit.FemtogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 g/cm³", DensityUnit.GramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/ft³", DensityUnit.GramPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 g/in³", DensityUnit.GramPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 g/m³", DensityUnit.GramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm³", DensityUnit.GramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 g/dl", DensityUnit.GramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 g/l", DensityUnit.GramPerLiter, 4.2)] + [InlineData("en-US", "4.2 g/ml", DensityUnit.GramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 kg/cm³", DensityUnit.KilogramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/m³", DensityUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm³", DensityUnit.KilogramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/l", DensityUnit.KilogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 kip/ft³", DensityUnit.KilopoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kip/in³", DensityUnit.KilopoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 kip/yd³", DensityUnit.KilopoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 µg/m³", DensityUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µg/dl", DensityUnit.MicrogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 µg/l", DensityUnit.MicrogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 µg/ml", DensityUnit.MicrogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mg/m³", DensityUnit.MilligramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mg/dl", DensityUnit.MilligramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 mg/l", DensityUnit.MilligramPerLiter, 4.2)] + [InlineData("en-US", "4.2 mg/ml", DensityUnit.MilligramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ng/dl", DensityUnit.NanogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 ng/l", DensityUnit.NanogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 ng/ml", DensityUnit.NanogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 pg/dl", DensityUnit.PicogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 pg/l", DensityUnit.PicogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 pg/ml", DensityUnit.PicogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 lb/cm³", DensityUnit.PoundPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 lbm/cm³", DensityUnit.PoundPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 lb/ft³", DensityUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lbm/ft³", DensityUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in³", DensityUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 lbm/in³", DensityUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 lb/m³", DensityUnit.PoundPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 lbm/m³", DensityUnit.PoundPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 lb/mm³", DensityUnit.PoundPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbm/mm³", DensityUnit.PoundPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb/yd³", DensityUnit.PoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 lbm/yd³", DensityUnit.PoundPerCubicYard, 4.2)] + [InlineData("en-US", "4.2 ppg (imp.)", DensityUnit.PoundPerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 ppg (U.S.)", DensityUnit.PoundPerUSGallon, 4.2)] + [InlineData("en-US", "4.2 slug/cm³", DensityUnit.SlugPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 slug/ft³", DensityUnit.SlugPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 slug/in³", DensityUnit.SlugPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 slug/m³", DensityUnit.SlugPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 slug/mm³", DensityUnit.SlugPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 t/cm³", DensityUnit.TonnePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 t/ft³", DensityUnit.TonnePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 t/in³", DensityUnit.TonnePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 t/m³", DensityUnit.TonnePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 t/mm³", DensityUnit.TonnePerCubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 г/м³", DensityUnit.GramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 кг/м³", DensityUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкг/м³", DensityUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мг/м³", DensityUnit.MilligramPerCubicMeter, 4.2)] + public void TryParse(string culture, string quantityString, DensityUnit expectedUnit, double expectedValue) { - { - Assert.True(Density.TryParse("1 cg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDeciliter, CentigramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.CentigramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 cg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerLiter, CentigramsPerLiterTolerance); - Assert.Equal(DensityUnit.CentigramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 cg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.CentigramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 dg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDeciliter, DecigramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.DecigramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 dg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerLiter, DecigramsPerLiterTolerance); - Assert.Equal(DensityUnit.DecigramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 dg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.DecigramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 fg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerDeciliter, FemtogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.FemtogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 fg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerLiter, FemtogramsPerLiterTolerance); - Assert.Equal(DensityUnit.FemtogramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 fg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtogramsPerMilliliter, FemtogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.FemtogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicFoot, GramsPerCubicFootTolerance); - Assert.Equal(DensityUnit.GramPerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicInch, GramsPerCubicInchTolerance); - Assert.Equal(DensityUnit.GramPerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 г/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerDeciliter, GramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.GramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerLiter, GramsPerLiterTolerance); - Assert.Equal(DensityUnit.GramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 g/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMilliliter, GramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.GramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kg/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 кг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kg/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerLiter, KilogramsPerLiterTolerance); - Assert.Equal(DensityUnit.KilogramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kip/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kip/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 kip/yd³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicYard, KilopoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicYard, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 µg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 мкг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 µg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDeciliter, MicrogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.MicrogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 µg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerLiter, MicrogramsPerLiterTolerance); - Assert.Equal(DensityUnit.MicrogramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 µg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MicrogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 mg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 мг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 mg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerDeciliter, MilligramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.MilligramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 mg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerLiter, MilligramsPerLiterTolerance); - Assert.Equal(DensityUnit.MilligramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 mg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MilligramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 ng/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDeciliter, NanogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.NanogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 ng/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerLiter, NanogramsPerLiterTolerance); - Assert.Equal(DensityUnit.NanogramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 ng/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.NanogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 pg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerDeciliter, PicogramsPerDeciliterTolerance); - Assert.Equal(DensityUnit.PicogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 pg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerLiter, PicogramsPerLiterTolerance); - Assert.Equal(DensityUnit.PicogramPerLiter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 pg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.PicogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicCentimeter, PoundsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicCentimeter, PoundsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMeter, PoundsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMeter, PoundsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMillimeter, PoundsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicMillimeter, PoundsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lb/yd³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicYard, PoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 lbm/yd³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicYard, PoundsPerCubicYardTolerance); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 ppg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - Assert.Equal(DensityUnit.PoundPerImperialGallon, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 ppg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerUSGallon, PoundsPerUSGallonTolerance); - Assert.Equal(DensityUnit.PoundPerUSGallon, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 slug/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicCentimeter, SlugsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 slug/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - Assert.Equal(DensityUnit.SlugPerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 slug/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicInch, SlugsPerCubicInchTolerance); - Assert.Equal(DensityUnit.SlugPerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 slug/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicMeter, SlugsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 slug/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicMillimeter, SlugsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.SlugPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 t/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 t/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicFoot, TonnesPerCubicFootTolerance); - Assert.Equal(DensityUnit.TonnePerCubicFoot, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 t/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicInch, TonnesPerCubicInchTolerance); - Assert.Equal(DensityUnit.TonnePerCubicInch, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 t/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMeter, parsed.Unit); - } - - { - Assert.True(Density.TryParse("1 t/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Density.TryParse(quantityString, out Density parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -2046,6 +1328,86 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Densit Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", DensityUnit.CentigramPerDeciliter, "cg/dl")] + [InlineData("en-US", DensityUnit.CentigramPerLiter, "cg/l")] + [InlineData("en-US", DensityUnit.CentigramPerMilliliter, "cg/ml")] + [InlineData("en-US", DensityUnit.DecigramPerDeciliter, "dg/dl")] + [InlineData("en-US", DensityUnit.DecigramPerLiter, "dg/l")] + [InlineData("en-US", DensityUnit.DecigramPerMilliliter, "dg/ml")] + [InlineData("en-US", DensityUnit.FemtogramPerDeciliter, "fg/dl")] + [InlineData("en-US", DensityUnit.FemtogramPerLiter, "fg/l")] + [InlineData("en-US", DensityUnit.FemtogramPerMilliliter, "fg/ml")] + [InlineData("en-US", DensityUnit.GramPerCubicCentimeter, "g/cm³")] + [InlineData("en-US", DensityUnit.GramPerCubicFoot, "g/ft³")] + [InlineData("en-US", DensityUnit.GramPerCubicInch, "g/in³")] + [InlineData("en-US", DensityUnit.GramPerCubicMeter, "g/m³")] + [InlineData("en-US", DensityUnit.GramPerCubicMillimeter, "g/mm³")] + [InlineData("en-US", DensityUnit.GramPerDeciliter, "g/dl")] + [InlineData("en-US", DensityUnit.GramPerLiter, "g/l")] + [InlineData("en-US", DensityUnit.GramPerMilliliter, "g/ml")] + [InlineData("en-US", DensityUnit.KilogramPerCubicCentimeter, "kg/cm³")] + [InlineData("en-US", DensityUnit.KilogramPerCubicMeter, "kg/m³")] + [InlineData("en-US", DensityUnit.KilogramPerCubicMillimeter, "kg/mm³")] + [InlineData("en-US", DensityUnit.KilogramPerLiter, "kg/l")] + [InlineData("en-US", DensityUnit.KilopoundPerCubicFoot, "kip/ft³")] + [InlineData("en-US", DensityUnit.KilopoundPerCubicInch, "kip/in³")] + [InlineData("en-US", DensityUnit.KilopoundPerCubicYard, "kip/yd³")] + [InlineData("en-US", DensityUnit.MicrogramPerCubicMeter, "µg/m³")] + [InlineData("en-US", DensityUnit.MicrogramPerDeciliter, "µg/dl")] + [InlineData("en-US", DensityUnit.MicrogramPerLiter, "µg/l")] + [InlineData("en-US", DensityUnit.MicrogramPerMilliliter, "µg/ml")] + [InlineData("en-US", DensityUnit.MilligramPerCubicMeter, "mg/m³")] + [InlineData("en-US", DensityUnit.MilligramPerDeciliter, "mg/dl")] + [InlineData("en-US", DensityUnit.MilligramPerLiter, "mg/l")] + [InlineData("en-US", DensityUnit.MilligramPerMilliliter, "mg/ml")] + [InlineData("en-US", DensityUnit.NanogramPerDeciliter, "ng/dl")] + [InlineData("en-US", DensityUnit.NanogramPerLiter, "ng/l")] + [InlineData("en-US", DensityUnit.NanogramPerMilliliter, "ng/ml")] + [InlineData("en-US", DensityUnit.PicogramPerDeciliter, "pg/dl")] + [InlineData("en-US", DensityUnit.PicogramPerLiter, "pg/l")] + [InlineData("en-US", DensityUnit.PicogramPerMilliliter, "pg/ml")] + [InlineData("en-US", DensityUnit.PoundPerCubicCentimeter, "lb/cm³")] + [InlineData("en-US", DensityUnit.PoundPerCubicFoot, "lb/ft³")] + [InlineData("en-US", DensityUnit.PoundPerCubicInch, "lb/in³")] + [InlineData("en-US", DensityUnit.PoundPerCubicMeter, "lb/m³")] + [InlineData("en-US", DensityUnit.PoundPerCubicMillimeter, "lb/mm³")] + [InlineData("en-US", DensityUnit.PoundPerCubicYard, "lb/yd³")] + [InlineData("en-US", DensityUnit.PoundPerImperialGallon, "ppg (imp.)")] + [InlineData("en-US", DensityUnit.PoundPerUSGallon, "ppg (U.S.)")] + [InlineData("en-US", DensityUnit.SlugPerCubicCentimeter, "slug/cm³")] + [InlineData("en-US", DensityUnit.SlugPerCubicFoot, "slug/ft³")] + [InlineData("en-US", DensityUnit.SlugPerCubicInch, "slug/in³")] + [InlineData("en-US", DensityUnit.SlugPerCubicMeter, "slug/m³")] + [InlineData("en-US", DensityUnit.SlugPerCubicMillimeter, "slug/mm³")] + [InlineData("en-US", DensityUnit.TonnePerCubicCentimeter, "t/cm³")] + [InlineData("en-US", DensityUnit.TonnePerCubicFoot, "t/ft³")] + [InlineData("en-US", DensityUnit.TonnePerCubicInch, "t/in³")] + [InlineData("en-US", DensityUnit.TonnePerCubicMeter, "t/m³")] + [InlineData("en-US", DensityUnit.TonnePerCubicMillimeter, "t/mm³")] + [InlineData("ru-RU", DensityUnit.GramPerCubicMeter, "г/м³")] + [InlineData("ru-RU", DensityUnit.KilogramPerCubicMeter, "кг/м³")] + [InlineData("ru-RU", DensityUnit.MicrogramPerCubicMeter, "мкг/м³")] + [InlineData("ru-RU", DensityUnit.MilligramPerCubicMeter, "мг/м³")] + public void GetAbbreviationForCulture(string culture, DensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Density.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Density.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Density.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(DensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs index fc32c6cc91..82d646aded 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs @@ -414,664 +414,122 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cGy·cm²", DoseAreaProductUnit.CentigraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 cGy·dm²", DoseAreaProductUnit.CentigraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 cGy·m²", DoseAreaProductUnit.CentigraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 cGy·μm²", DoseAreaProductUnit.CentigraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 cGy·mm²", DoseAreaProductUnit.CentigraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·cm²", DoseAreaProductUnit.DecigraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·dm²", DoseAreaProductUnit.DecigraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·m²", DoseAreaProductUnit.DecigraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 dGy·μm²", DoseAreaProductUnit.DecigraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 dGy·mm²", DoseAreaProductUnit.DecigraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·cm²", DoseAreaProductUnit.GraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·dm²", DoseAreaProductUnit.GraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·m²", DoseAreaProductUnit.GraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 Gy·μm²", DoseAreaProductUnit.GraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 Gy·mm²", DoseAreaProductUnit.GraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·cm²", DoseAreaProductUnit.MicrograySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·dm²", DoseAreaProductUnit.MicrograySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·m²", DoseAreaProductUnit.MicrograySquareMeter, 4.2)] + [InlineData("en-US", "4.2 µGy·μm²", DoseAreaProductUnit.MicrograySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 µGy·mm²", DoseAreaProductUnit.MicrograySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·cm²", DoseAreaProductUnit.MilligraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·dm²", DoseAreaProductUnit.MilligraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·m²", DoseAreaProductUnit.MilligraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 mGy·μm²", DoseAreaProductUnit.MilligraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mGy·mm²", DoseAreaProductUnit.MilligraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·см²", DoseAreaProductUnit.CentigraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·дм²", DoseAreaProductUnit.CentigraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·м²", DoseAreaProductUnit.CentigraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·мкм²", DoseAreaProductUnit.CentigraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 сГр·мм²", DoseAreaProductUnit.CentigraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·см²", DoseAreaProductUnit.DecigraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·дм²", DoseAreaProductUnit.DecigraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·м²", DoseAreaProductUnit.DecigraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·мкм²", DoseAreaProductUnit.DecigraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 дГр·мм²", DoseAreaProductUnit.DecigraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·см²", DoseAreaProductUnit.GraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·дм²", DoseAreaProductUnit.GraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·м²", DoseAreaProductUnit.GraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·мкм²", DoseAreaProductUnit.GraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 Гр·мм²", DoseAreaProductUnit.GraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·см²", DoseAreaProductUnit.MicrograySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·дм²", DoseAreaProductUnit.MicrograySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·м²", DoseAreaProductUnit.MicrograySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·мкм²", DoseAreaProductUnit.MicrograySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·мм²", DoseAreaProductUnit.MicrograySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·см²", DoseAreaProductUnit.MilligraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·дм²", DoseAreaProductUnit.MilligraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·м²", DoseAreaProductUnit.MilligraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·мкм²", DoseAreaProductUnit.MilligraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 мГр·мм²", DoseAreaProductUnit.MilligraySquareMillimeter, 4.2)] + public void Parse(string culture, string quantityString, DoseAreaProductUnit expectedUnit, double expectedValue) { - try - { - var parsed = DoseAreaProduct.Parse("1 cGy·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareCentimeters, CentigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 сГр·см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareCentimeters, CentigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 cGy·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareDecimeters, CentigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 сГр·дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareDecimeters, CentigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 cGy·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMeters, CentigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 сГр·м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMeters, CentigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 cGy·μm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMicrometers, CentigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 сГр·мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMicrometers, CentigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 cGy·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMillimeters, CentigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 сГр·мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMillimeters, CentigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 dGy·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareCentimeters, DecigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 дГр·см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareCentimeters, DecigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 dGy·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareDecimeters, DecigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 дГр·дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareDecimeters, DecigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 dGy·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMeters, DecigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 дГр·м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMeters, DecigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 dGy·μm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMicrometers, DecigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 дГр·мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMicrometers, DecigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 dGy·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMillimeters, DecigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 дГр·мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMillimeters, DecigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Gy·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GraySquareCentimeters, GraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Гр·см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GraySquareCentimeters, GraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Gy·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GraySquareDecimeters, GraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Гр·дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GraySquareDecimeters, GraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Gy·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GraySquareMeters, GraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Гр·м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GraySquareMeters, GraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Gy·μm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GraySquareMicrometers, GraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Гр·мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GraySquareMicrometers, GraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Gy·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GraySquareMillimeters, GraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 Гр·мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GraySquareMillimeters, GraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 µGy·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareCentimeters, MicrograySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мкГр·см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareCentimeters, MicrograySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 µGy·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareDecimeters, MicrograySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мкГр·дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareDecimeters, MicrograySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 µGy·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMeters, MicrograySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мкГр·м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMeters, MicrograySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 µGy·μm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMicrometers, MicrograySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мкГр·мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMicrometers, MicrograySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 µGy·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMillimeters, MicrograySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мкГр·мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMillimeters, MicrograySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 mGy·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareCentimeters, MilligraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мГр·см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareCentimeters, MilligraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 mGy·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareDecimeters, MilligraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мГр·дм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareDecimeters, MilligraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 mGy·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMeters, MilligraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мГр·м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMeters, MilligraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 mGy·μm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMicrometers, MilligraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мГр·мкм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMicrometers, MilligraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 mGy·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMillimeters, MilligraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DoseAreaProduct.Parse("1 мГр·мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMillimeters, MilligraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = DoseAreaProduct.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cGy·cm²", DoseAreaProductUnit.CentigraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 cGy·dm²", DoseAreaProductUnit.CentigraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 cGy·m²", DoseAreaProductUnit.CentigraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 cGy·μm²", DoseAreaProductUnit.CentigraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 cGy·mm²", DoseAreaProductUnit.CentigraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·cm²", DoseAreaProductUnit.DecigraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·dm²", DoseAreaProductUnit.DecigraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 dGy·m²", DoseAreaProductUnit.DecigraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 dGy·μm²", DoseAreaProductUnit.DecigraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 dGy·mm²", DoseAreaProductUnit.DecigraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·cm²", DoseAreaProductUnit.GraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·dm²", DoseAreaProductUnit.GraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 Gy·m²", DoseAreaProductUnit.GraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 Gy·μm²", DoseAreaProductUnit.GraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 Gy·mm²", DoseAreaProductUnit.GraySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·cm²", DoseAreaProductUnit.MicrograySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·dm²", DoseAreaProductUnit.MicrograySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 µGy·m²", DoseAreaProductUnit.MicrograySquareMeter, 4.2)] + [InlineData("en-US", "4.2 µGy·μm²", DoseAreaProductUnit.MicrograySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 µGy·mm²", DoseAreaProductUnit.MicrograySquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·cm²", DoseAreaProductUnit.MilligraySquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·dm²", DoseAreaProductUnit.MilligraySquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 mGy·m²", DoseAreaProductUnit.MilligraySquareMeter, 4.2)] + [InlineData("en-US", "4.2 mGy·μm²", DoseAreaProductUnit.MilligraySquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mGy·mm²", DoseAreaProductUnit.MilligraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·см²", DoseAreaProductUnit.CentigraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·дм²", DoseAreaProductUnit.CentigraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·м²", DoseAreaProductUnit.CentigraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 сГр·мкм²", DoseAreaProductUnit.CentigraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 сГр·мм²", DoseAreaProductUnit.CentigraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·см²", DoseAreaProductUnit.DecigraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·дм²", DoseAreaProductUnit.DecigraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·м²", DoseAreaProductUnit.DecigraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 дГр·мкм²", DoseAreaProductUnit.DecigraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 дГр·мм²", DoseAreaProductUnit.DecigraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·см²", DoseAreaProductUnit.GraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·дм²", DoseAreaProductUnit.GraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·м²", DoseAreaProductUnit.GraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 Гр·мкм²", DoseAreaProductUnit.GraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 Гр·мм²", DoseAreaProductUnit.GraySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·см²", DoseAreaProductUnit.MicrograySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·дм²", DoseAreaProductUnit.MicrograySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·м²", DoseAreaProductUnit.MicrograySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·мкм²", DoseAreaProductUnit.MicrograySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 мкГр·мм²", DoseAreaProductUnit.MicrograySquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·см²", DoseAreaProductUnit.MilligraySquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·дм²", DoseAreaProductUnit.MilligraySquareDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·м²", DoseAreaProductUnit.MilligraySquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 мГр·мкм²", DoseAreaProductUnit.MilligraySquareMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 мГр·мм²", DoseAreaProductUnit.MilligraySquareMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, DoseAreaProductUnit expectedUnit, double expectedValue) { - { - Assert.True(DoseAreaProduct.TryParse("1 cGy·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareCentimeters, CentigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 сГр·см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareCentimeters, CentigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 cGy·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareDecimeters, CentigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 сГр·дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareDecimeters, CentigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 cGy·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMeters, CentigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 сГр·м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMeters, CentigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 cGy·μm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMicrometers, CentigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 сГр·мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMicrometers, CentigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 cGy·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMillimeters, CentigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 сГр·мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigraySquareMillimeters, CentigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.CentigraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 dGy·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareCentimeters, DecigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 дГр·см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareCentimeters, DecigraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 dGy·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareDecimeters, DecigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 дГр·дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareDecimeters, DecigraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 dGy·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMeters, DecigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 дГр·м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMeters, DecigraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 dGy·μm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMicrometers, DecigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 дГр·мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMicrometers, DecigraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 dGy·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMillimeters, DecigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 дГр·мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigraySquareMillimeters, DecigraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.DecigraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Gy·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareCentimeters, GraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Гр·см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareCentimeters, GraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Gy·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareDecimeters, GraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Гр·дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareDecimeters, GraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Gy·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMeters, GraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Гр·м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMeters, GraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Gy·μm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMicrometers, GraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Гр·мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMicrometers, GraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Gy·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMillimeters, GraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 Гр·мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GraySquareMillimeters, GraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.GraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 µGy·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareCentimeters, MicrograySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мкГр·см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareCentimeters, MicrograySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 µGy·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareDecimeters, MicrograySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мкГр·дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareDecimeters, MicrograySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 µGy·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMeters, MicrograySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мкГр·м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMeters, MicrograySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 µGy·μm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMicrometers, MicrograySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мкГр·мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMicrometers, MicrograySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 µGy·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMillimeters, MicrograySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мкГр·мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrograySquareMillimeters, MicrograySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MicrograySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 mGy·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareCentimeters, MilligraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мГр·см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareCentimeters, MilligraySquareCentimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareCentimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 mGy·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareDecimeters, MilligraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мГр·дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareDecimeters, MilligraySquareDecimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareDecimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 mGy·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMeters, MilligraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мГр·м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMeters, MilligraySquareMetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 mGy·μm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMicrometers, MilligraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мГр·мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMicrometers, MilligraySquareMicrometersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMicrometer, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 mGy·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMillimeters, MilligraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMillimeter, parsed.Unit); - } - - { - Assert.True(DoseAreaProduct.TryParse("1 мГр·мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligraySquareMillimeters, MilligraySquareMillimetersTolerance); - Assert.Equal(DoseAreaProductUnit.MilligraySquareMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(DoseAreaProduct.TryParse(quantityString, out DoseAreaProduct parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1440,6 +898,76 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, DoseAr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", DoseAreaProductUnit.CentigraySquareCentimeter, "cGy·cm²")] + [InlineData("en-US", DoseAreaProductUnit.CentigraySquareDecimeter, "cGy·dm²")] + [InlineData("en-US", DoseAreaProductUnit.CentigraySquareMeter, "cGy·m²")] + [InlineData("en-US", DoseAreaProductUnit.CentigraySquareMicrometer, "cGy·μm²")] + [InlineData("en-US", DoseAreaProductUnit.CentigraySquareMillimeter, "cGy·mm²")] + [InlineData("en-US", DoseAreaProductUnit.DecigraySquareCentimeter, "dGy·cm²")] + [InlineData("en-US", DoseAreaProductUnit.DecigraySquareDecimeter, "dGy·dm²")] + [InlineData("en-US", DoseAreaProductUnit.DecigraySquareMeter, "dGy·m²")] + [InlineData("en-US", DoseAreaProductUnit.DecigraySquareMicrometer, "dGy·μm²")] + [InlineData("en-US", DoseAreaProductUnit.DecigraySquareMillimeter, "dGy·mm²")] + [InlineData("en-US", DoseAreaProductUnit.GraySquareCentimeter, "Gy·cm²")] + [InlineData("en-US", DoseAreaProductUnit.GraySquareDecimeter, "Gy·dm²")] + [InlineData("en-US", DoseAreaProductUnit.GraySquareMeter, "Gy·m²")] + [InlineData("en-US", DoseAreaProductUnit.GraySquareMicrometer, "Gy·μm²")] + [InlineData("en-US", DoseAreaProductUnit.GraySquareMillimeter, "Gy·mm²")] + [InlineData("en-US", DoseAreaProductUnit.MicrograySquareCentimeter, "µGy·cm²")] + [InlineData("en-US", DoseAreaProductUnit.MicrograySquareDecimeter, "µGy·dm²")] + [InlineData("en-US", DoseAreaProductUnit.MicrograySquareMeter, "µGy·m²")] + [InlineData("en-US", DoseAreaProductUnit.MicrograySquareMicrometer, "µGy·μm²")] + [InlineData("en-US", DoseAreaProductUnit.MicrograySquareMillimeter, "µGy·mm²")] + [InlineData("en-US", DoseAreaProductUnit.MilligraySquareCentimeter, "mGy·cm²")] + [InlineData("en-US", DoseAreaProductUnit.MilligraySquareDecimeter, "mGy·dm²")] + [InlineData("en-US", DoseAreaProductUnit.MilligraySquareMeter, "mGy·m²")] + [InlineData("en-US", DoseAreaProductUnit.MilligraySquareMicrometer, "mGy·μm²")] + [InlineData("en-US", DoseAreaProductUnit.MilligraySquareMillimeter, "mGy·mm²")] + [InlineData("ru-RU", DoseAreaProductUnit.CentigraySquareCentimeter, "сГр·см²")] + [InlineData("ru-RU", DoseAreaProductUnit.CentigraySquareDecimeter, "сГр·дм²")] + [InlineData("ru-RU", DoseAreaProductUnit.CentigraySquareMeter, "сГр·м²")] + [InlineData("ru-RU", DoseAreaProductUnit.CentigraySquareMicrometer, "сГр·мкм²")] + [InlineData("ru-RU", DoseAreaProductUnit.CentigraySquareMillimeter, "сГр·мм²")] + [InlineData("ru-RU", DoseAreaProductUnit.DecigraySquareCentimeter, "дГр·см²")] + [InlineData("ru-RU", DoseAreaProductUnit.DecigraySquareDecimeter, "дГр·дм²")] + [InlineData("ru-RU", DoseAreaProductUnit.DecigraySquareMeter, "дГр·м²")] + [InlineData("ru-RU", DoseAreaProductUnit.DecigraySquareMicrometer, "дГр·мкм²")] + [InlineData("ru-RU", DoseAreaProductUnit.DecigraySquareMillimeter, "дГр·мм²")] + [InlineData("ru-RU", DoseAreaProductUnit.GraySquareCentimeter, "Гр·см²")] + [InlineData("ru-RU", DoseAreaProductUnit.GraySquareDecimeter, "Гр·дм²")] + [InlineData("ru-RU", DoseAreaProductUnit.GraySquareMeter, "Гр·м²")] + [InlineData("ru-RU", DoseAreaProductUnit.GraySquareMicrometer, "Гр·мкм²")] + [InlineData("ru-RU", DoseAreaProductUnit.GraySquareMillimeter, "Гр·мм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MicrograySquareCentimeter, "мкГр·см²")] + [InlineData("ru-RU", DoseAreaProductUnit.MicrograySquareDecimeter, "мкГр·дм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MicrograySquareMeter, "мкГр·м²")] + [InlineData("ru-RU", DoseAreaProductUnit.MicrograySquareMicrometer, "мкГр·мкм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MicrograySquareMillimeter, "мкГр·мм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MilligraySquareCentimeter, "мГр·см²")] + [InlineData("ru-RU", DoseAreaProductUnit.MilligraySquareDecimeter, "мГр·дм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MilligraySquareMeter, "мГр·м²")] + [InlineData("ru-RU", DoseAreaProductUnit.MilligraySquareMicrometer, "мГр·мкм²")] + [InlineData("ru-RU", DoseAreaProductUnit.MilligraySquareMillimeter, "мГр·мм²")] + public void GetAbbreviationForCulture(string culture, DoseAreaProductUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = DoseAreaProduct.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(DoseAreaProduct.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = DoseAreaProduct.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(DoseAreaProductUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index d25f675f9c..11e4148dba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -342,898 +342,158 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 d", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 day", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 days", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 h", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hr", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hrs", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hour", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hours", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 jyr", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 jyear", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 jyears", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 µs", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsec", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsecs", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsecond", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µseconds", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 ms", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msec", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msecs", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msecond", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 mseconds", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 m", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 min", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 minute", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 minutes", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 mo", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 month", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 months", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 ns", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsec", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsecs", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsecond", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nseconds", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 ps", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psec", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psecs", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psecond", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 pseconds", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 s", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 sec", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 secs", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 second", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 seconds", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 sol", DurationUnit.Sol, 4.2)] + [InlineData("en-US", "4.2 wk", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 week", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 weeks", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 yr", DurationUnit.Year365, 4.2)] + [InlineData("en-US", "4.2 year", DurationUnit.Year365, 4.2)] + [InlineData("en-US", "4.2 years", DurationUnit.Year365, 4.2)] + [InlineData("ru-RU", "4,2 сут", DurationUnit.Day, 4.2)] + [InlineData("ru-RU", "4,2 д", DurationUnit.Day, 4.2)] + [InlineData("ru-RU", "4,2 ч", DurationUnit.Hour, 4.2)] + [InlineData("ru-RU", "4,2 час", DurationUnit.Hour, 4.2)] + [InlineData("ru-RU", "4,2 мксек", DurationUnit.Microsecond, 4.2)] + [InlineData("ru-RU", "4,2 мкс", DurationUnit.Microsecond, 4.2)] + [InlineData("ru-RU", "4,2 мсек", DurationUnit.Millisecond, 4.2)] + [InlineData("ru-RU", "4,2 мс", DurationUnit.Millisecond, 4.2)] + [InlineData("ru-RU", "4,2 мин", DurationUnit.Minute, 4.2)] + [InlineData("ru-RU", "4,2 месяц", DurationUnit.Month30, 4.2)] + [InlineData("ru-RU", "4,2 нсек", DurationUnit.Nanosecond, 4.2)] + [InlineData("ru-RU", "4,2 нс", DurationUnit.Nanosecond, 4.2)] + [InlineData("ru-RU", "4,2 псек", DurationUnit.Picosecond, 4.2)] + [InlineData("ru-RU", "4,2 пс", DurationUnit.Picosecond, 4.2)] + [InlineData("ru-RU", "4,2 сек", DurationUnit.Second, 4.2)] + [InlineData("ru-RU", "4,2 с", DurationUnit.Second, 4.2)] + [InlineData("ru-RU", "4,2 нед", DurationUnit.Week, 4.2)] + [InlineData("ru-RU", "4,2 год", DurationUnit.Year365, 4.2)] + public void Parse(string culture, string quantityString, DurationUnit expectedUnit, double expectedValue) { - try - { - var parsed = Duration.Parse("1 d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 days", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 сут", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 hrs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 hour", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 hours", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 час", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 jyr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 jyear", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 jyears", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 µs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 µsec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 µsecs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 µsecond", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 µseconds", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 мксек", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 мкс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 ms", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 msec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 msecs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 msecond", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 mseconds", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 мсек", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 мс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 minute", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 minutes", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 mo", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 month", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 months", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 месяц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 ns", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 nsec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 nsecs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 nsecond", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 nseconds", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 нсек", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 нс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 ps", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 psec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 psecs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 psecond", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 pseconds", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 псек", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 пс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 sec", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 secs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 second", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 seconds", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 сек", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 sol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Sols, SolsTolerance); - Assert.Equal(DurationUnit.Sol, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 wk", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 week", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 weeks", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 нед", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 yr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 year", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 years", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Duration.Parse("1 год", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Duration.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 d", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 day", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 days", DurationUnit.Day, 4.2)] + [InlineData("en-US", "4.2 h", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hr", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hrs", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hour", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 hours", DurationUnit.Hour, 4.2)] + [InlineData("en-US", "4.2 jyr", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 jyear", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 jyears", DurationUnit.JulianYear, 4.2)] + [InlineData("en-US", "4.2 µs", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsec", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsecs", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µsecond", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 µseconds", DurationUnit.Microsecond, 4.2)] + [InlineData("en-US", "4.2 ms", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msec", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msecs", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 msecond", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 mseconds", DurationUnit.Millisecond, 4.2)] + [InlineData("en-US", "4.2 m", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 min", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 minute", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 minutes", DurationUnit.Minute, 4.2)] + [InlineData("en-US", "4.2 mo", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 month", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 months", DurationUnit.Month30, 4.2)] + [InlineData("en-US", "4.2 ns", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsec", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsecs", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nsecond", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 nseconds", DurationUnit.Nanosecond, 4.2)] + [InlineData("en-US", "4.2 ps", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psec", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psecs", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 psecond", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 pseconds", DurationUnit.Picosecond, 4.2)] + [InlineData("en-US", "4.2 s", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 sec", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 secs", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 second", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 seconds", DurationUnit.Second, 4.2)] + [InlineData("en-US", "4.2 sol", DurationUnit.Sol, 4.2)] + [InlineData("en-US", "4.2 wk", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 week", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 weeks", DurationUnit.Week, 4.2)] + [InlineData("en-US", "4.2 yr", DurationUnit.Year365, 4.2)] + [InlineData("en-US", "4.2 year", DurationUnit.Year365, 4.2)] + [InlineData("en-US", "4.2 years", DurationUnit.Year365, 4.2)] + [InlineData("ru-RU", "4,2 сут", DurationUnit.Day, 4.2)] + [InlineData("ru-RU", "4,2 д", DurationUnit.Day, 4.2)] + [InlineData("ru-RU", "4,2 ч", DurationUnit.Hour, 4.2)] + [InlineData("ru-RU", "4,2 час", DurationUnit.Hour, 4.2)] + [InlineData("ru-RU", "4,2 мксек", DurationUnit.Microsecond, 4.2)] + [InlineData("ru-RU", "4,2 мкс", DurationUnit.Microsecond, 4.2)] + [InlineData("ru-RU", "4,2 мсек", DurationUnit.Millisecond, 4.2)] + [InlineData("ru-RU", "4,2 мс", DurationUnit.Millisecond, 4.2)] + [InlineData("ru-RU", "4,2 мин", DurationUnit.Minute, 4.2)] + [InlineData("ru-RU", "4,2 месяц", DurationUnit.Month30, 4.2)] + [InlineData("ru-RU", "4,2 нсек", DurationUnit.Nanosecond, 4.2)] + [InlineData("ru-RU", "4,2 нс", DurationUnit.Nanosecond, 4.2)] + [InlineData("ru-RU", "4,2 псек", DurationUnit.Picosecond, 4.2)] + [InlineData("ru-RU", "4,2 пс", DurationUnit.Picosecond, 4.2)] + [InlineData("ru-RU", "4,2 сек", DurationUnit.Second, 4.2)] + [InlineData("ru-RU", "4,2 с", DurationUnit.Second, 4.2)] + [InlineData("ru-RU", "4,2 нед", DurationUnit.Week, 4.2)] + [InlineData("ru-RU", "4,2 год", DurationUnit.Year365, 4.2)] + public void TryParse(string culture, string quantityString, DurationUnit expectedUnit, double expectedValue) { - { - Assert.True(Duration.TryParse("1 d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 days", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 сут", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Days, DaysTolerance); - Assert.Equal(DurationUnit.Day, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 hrs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 hour", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 hours", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 час", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hours, HoursTolerance); - Assert.Equal(DurationUnit.Hour, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 jyr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 jyear", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 jyears", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JulianYears, JulianYearsTolerance); - Assert.Equal(DurationUnit.JulianYear, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 µs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 µsec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 µsecs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 µsecond", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 µseconds", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 мксек", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 мкс", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microseconds, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 ms", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 msec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 msecs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 msecond", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 mseconds", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 мсек", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 мс", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliseconds, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 minute", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 minutes", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Minutes, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 mo", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 month", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 months", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 месяц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Months30, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 ns", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 nsec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 nsecs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 nsecond", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 nseconds", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 нсек", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 нс", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoseconds, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 ps", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 psec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 psecs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 psecond", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 pseconds", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 псек", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 пс", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoseconds, PicosecondsTolerance); - Assert.Equal(DurationUnit.Picosecond, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 sec", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 secs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 second", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 seconds", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 сек", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Seconds, SecondsTolerance); - Assert.Equal(DurationUnit.Second, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 sol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Sols, SolsTolerance); - Assert.Equal(DurationUnit.Sol, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 wk", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 week", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 weeks", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 нед", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Weeks, WeeksTolerance); - Assert.Equal(DurationUnit.Week, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 yr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 year", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 years", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } - - { - Assert.True(Duration.TryParse("1 год", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Years365, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Duration.TryParse(quantityString, out Duration parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1774,6 +1034,50 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Durati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", DurationUnit.Day, "d")] + [InlineData("en-US", DurationUnit.Hour, "h")] + [InlineData("en-US", DurationUnit.JulianYear, "jyr")] + [InlineData("en-US", DurationUnit.Microsecond, "µs")] + [InlineData("en-US", DurationUnit.Millisecond, "ms")] + [InlineData("en-US", DurationUnit.Minute, "m")] + [InlineData("en-US", DurationUnit.Month30, "mo")] + [InlineData("en-US", DurationUnit.Nanosecond, "ns")] + [InlineData("en-US", DurationUnit.Picosecond, "ps")] + [InlineData("en-US", DurationUnit.Second, "s")] + [InlineData("en-US", DurationUnit.Sol, "sol")] + [InlineData("en-US", DurationUnit.Week, "wk")] + [InlineData("en-US", DurationUnit.Year365, "yr")] + [InlineData("ru-RU", DurationUnit.Day, "сут")] + [InlineData("ru-RU", DurationUnit.Hour, "ч")] + [InlineData("ru-RU", DurationUnit.Microsecond, "мксек")] + [InlineData("ru-RU", DurationUnit.Millisecond, "мсек")] + [InlineData("ru-RU", DurationUnit.Minute, "мин")] + [InlineData("ru-RU", DurationUnit.Month30, "месяц")] + [InlineData("ru-RU", DurationUnit.Nanosecond, "нсек")] + [InlineData("ru-RU", DurationUnit.Picosecond, "псек")] + [InlineData("ru-RU", DurationUnit.Second, "сек")] + [InlineData("ru-RU", DurationUnit.Week, "нед")] + [InlineData("ru-RU", DurationUnit.Year365, "год")] + public void GetAbbreviationForCulture(string culture, DurationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Duration.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Duration.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Duration.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(DurationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 79a9e592e8..55ad925f47 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -324,183 +324,48 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cP", DynamicViscosityUnit.Centipoise, 4.2)] + [InlineData("en-US", "4.2 µPa·s", DynamicViscosityUnit.MicropascalSecond, 4.2)] + [InlineData("en-US", "4.2 µPaS", DynamicViscosityUnit.MicropascalSecond, 4.2)] + [InlineData("en-US", "4.2 mPa·s", DynamicViscosityUnit.MillipascalSecond, 4.2)] + [InlineData("en-US", "4.2 mPaS", DynamicViscosityUnit.MillipascalSecond, 4.2)] + [InlineData("en-US", "4.2 Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared, 4.2)] + [InlineData("en-US", "4.2 Pa·s", DynamicViscosityUnit.PascalSecond, 4.2)] + [InlineData("en-US", "4.2 PaS", DynamicViscosityUnit.PascalSecond, 4.2)] + [InlineData("en-US", "4.2 P", DynamicViscosityUnit.Poise, 4.2)] + [InlineData("en-US", "4.2 lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond, 4.2)] + [InlineData("en-US", "4.2 reyn", DynamicViscosityUnit.Reyn, 4.2)] + public void Parse(string culture, string quantityString, DynamicViscosityUnit expectedUnit, double expectedValue) { - try - { - var parsed = DynamicViscosity.Parse("1 cP", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centipoise, CentipoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Centipoise, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 µPa·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicropascalSeconds, MicropascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 µPaS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicropascalSeconds, MicropascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 mPa·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillipascalSeconds, MillipascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 mPaS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillipascalSeconds, MillipascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 Ns/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - Assert.Equal(DynamicViscosityUnit.NewtonSecondPerMeterSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 Pa·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSeconds, PascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 PaS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSeconds, PascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 P", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Poise, PoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Poise, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 lbf·s/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForceSecondPerSquareFoot, PoundsForceSecondPerSquareFootTolerance); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 lbf·s/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForceSecondPerSquareInch, PoundsForceSecondPerSquareInchTolerance); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 lb/(ft·s)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerFootSecond, PoundsPerFootSecondTolerance); - Assert.Equal(DynamicViscosityUnit.PoundPerFootSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = DynamicViscosity.Parse("1 reyn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Reyns, ReynsTolerance); - Assert.Equal(DynamicViscosityUnit.Reyn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = DynamicViscosity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cP", DynamicViscosityUnit.Centipoise, 4.2)] + [InlineData("en-US", "4.2 µPa·s", DynamicViscosityUnit.MicropascalSecond, 4.2)] + [InlineData("en-US", "4.2 µPaS", DynamicViscosityUnit.MicropascalSecond, 4.2)] + [InlineData("en-US", "4.2 mPa·s", DynamicViscosityUnit.MillipascalSecond, 4.2)] + [InlineData("en-US", "4.2 mPaS", DynamicViscosityUnit.MillipascalSecond, 4.2)] + [InlineData("en-US", "4.2 Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared, 4.2)] + [InlineData("en-US", "4.2 Pa·s", DynamicViscosityUnit.PascalSecond, 4.2)] + [InlineData("en-US", "4.2 PaS", DynamicViscosityUnit.PascalSecond, 4.2)] + [InlineData("en-US", "4.2 P", DynamicViscosityUnit.Poise, 4.2)] + [InlineData("en-US", "4.2 lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond, 4.2)] + [InlineData("en-US", "4.2 reyn", DynamicViscosityUnit.Reyn, 4.2)] + public void TryParse(string culture, string quantityString, DynamicViscosityUnit expectedUnit, double expectedValue) { - { - Assert.True(DynamicViscosity.TryParse("1 cP", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centipoise, CentipoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Centipoise, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 µPa·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicropascalSeconds, MicropascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 µPaS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicropascalSeconds, MicropascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 mPa·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillipascalSeconds, MillipascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 mPaS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillipascalSeconds, MillipascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 Ns/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - Assert.Equal(DynamicViscosityUnit.NewtonSecondPerMeterSquared, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 Pa·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSeconds, PascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 PaS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSeconds, PascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 P", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Poise, PoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Poise, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 lbf·s/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForceSecondPerSquareFoot, PoundsForceSecondPerSquareFootTolerance); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 lbf·s/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForceSecondPerSquareInch, PoundsForceSecondPerSquareInchTolerance); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareInch, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 lb/(ft·s)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerFootSecond, PoundsPerFootSecondTolerance); - Assert.Equal(DynamicViscosityUnit.PoundPerFootSecond, parsed.Unit); - } - - { - Assert.True(DynamicViscosity.TryParse("1 reyn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Reyns, ReynsTolerance); - Assert.Equal(DynamicViscosityUnit.Reyn, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(DynamicViscosity.TryParse(quantityString, out DynamicViscosity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -673,6 +538,36 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Dynami Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", DynamicViscosityUnit.Centipoise, "cP")] + [InlineData("en-US", DynamicViscosityUnit.MicropascalSecond, "µPa·s")] + [InlineData("en-US", DynamicViscosityUnit.MillipascalSecond, "mPa·s")] + [InlineData("en-US", DynamicViscosityUnit.NewtonSecondPerMeterSquared, "Ns/m²")] + [InlineData("en-US", DynamicViscosityUnit.PascalSecond, "Pa·s")] + [InlineData("en-US", DynamicViscosityUnit.Poise, "P")] + [InlineData("en-US", DynamicViscosityUnit.PoundForceSecondPerSquareFoot, "lbf·s/ft²")] + [InlineData("en-US", DynamicViscosityUnit.PoundForceSecondPerSquareInch, "lbf·s/in²")] + [InlineData("en-US", DynamicViscosityUnit.PoundPerFootSecond, "lb/(ft·s)")] + [InlineData("en-US", DynamicViscosityUnit.Reyn, "reyn")] + public void GetAbbreviationForCulture(string culture, DynamicViscosityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = DynamicViscosity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(DynamicViscosity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = DynamicViscosity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(DynamicViscosityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index 9866fb883d..164a437e33 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -360,198 +360,54 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricAdmittanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricAdmittanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricAdmittanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricAdmittanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricAdmittanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricAdmittanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricAdmittanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricAdmittanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricAdmittanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricAdmittanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricAdmittanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricAdmittanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricAdmittanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricAdmittanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricAdmittanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricAdmittanceUnit.Terasiemens, 4.2)] + public void Parse(string culture, string quantityString, ElectricAdmittanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricAdmittance.Parse("1 G℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 k℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 M℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Megamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Megasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Mho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 µ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Micromho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 m℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Millimho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 n℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Siemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 T℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Teramho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricAdmittance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricAdmittance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricAdmittanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricAdmittanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricAdmittanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricAdmittanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricAdmittanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricAdmittanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricAdmittanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricAdmittanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricAdmittanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricAdmittanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricAdmittanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricAdmittanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricAdmittanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricAdmittanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricAdmittanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricAdmittanceUnit.Terasiemens, 4.2)] + public void TryParse(string culture, string quantityString, ElectricAdmittanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricAdmittance.TryParse("1 G℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 k℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Mho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 µ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Micromho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 n℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 nS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Siemens, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 T℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricAdmittanceUnit.Teramho, parsed.Unit); - } - - { - Assert.True(ElectricAdmittance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricAdmittance.TryParse(quantityString, out ElectricAdmittance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -748,6 +604,42 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricAdmittanceUnit.Gigamho, "G℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Gigasiemens, "GS")] + [InlineData("en-US", ElectricAdmittanceUnit.Kilomho, "k℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Kilosiemens, "kS")] + [InlineData("en-US", ElectricAdmittanceUnit.Megamho, "M℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Megasiemens, "MS")] + [InlineData("en-US", ElectricAdmittanceUnit.Mho, "℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Micromho, "µ℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Microsiemens, "µS")] + [InlineData("en-US", ElectricAdmittanceUnit.Millimho, "m℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Millisiemens, "mS")] + [InlineData("en-US", ElectricAdmittanceUnit.Nanomho, "n℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Nanosiemens, "nS")] + [InlineData("en-US", ElectricAdmittanceUnit.Siemens, "S")] + [InlineData("en-US", ElectricAdmittanceUnit.Teramho, "T℧")] + [InlineData("en-US", ElectricAdmittanceUnit.Terasiemens, "TS")] + public void GetAbbreviationForCulture(string culture, ElectricAdmittanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricAdmittance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricAdmittance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricAdmittance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricAdmittanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs index 8ecd465e82..31bfae52ba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kVAh", ElectricApparentEnergyUnit.KilovoltampereHour, 4.2)] + [InlineData("en-US", "4.2 MVAh", ElectricApparentEnergyUnit.MegavoltampereHour, 4.2)] + [InlineData("en-US", "4.2 VAh", ElectricApparentEnergyUnit.VoltampereHour, 4.2)] + public void Parse(string culture, string quantityString, ElectricApparentEnergyUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricApparentEnergy.Parse("1 kVAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentEnergy.Parse("1 MVAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentEnergy.Parse("1 VAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricApparentEnergy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kVAh", ElectricApparentEnergyUnit.KilovoltampereHour, 4.2)] + [InlineData("en-US", "4.2 MVAh", ElectricApparentEnergyUnit.MegavoltampereHour, 4.2)] + [InlineData("en-US", "4.2 VAh", ElectricApparentEnergyUnit.VoltampereHour, 4.2)] + public void TryParse(string culture, string quantityString, ElectricApparentEnergyUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricApparentEnergy.TryParse("1 kVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsed.Unit); - } - - { - Assert.True(ElectricApparentEnergy.TryParse("1 MVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsed.Unit); - } - - { - Assert.True(ElectricApparentEnergy.TryParse("1 VAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); - Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricApparentEnergy.TryParse(quantityString, out ElectricApparentEnergy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricApparentEnergyUnit.KilovoltampereHour, "kVAh")] + [InlineData("en-US", ElectricApparentEnergyUnit.MegavoltampereHour, "MVAh")] + [InlineData("en-US", ElectricApparentEnergyUnit.VoltampereHour, "VAh")] + public void GetAbbreviationForCulture(string culture, ElectricApparentEnergyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricApparentEnergy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricApparentEnergy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricApparentEnergy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricApparentEnergyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs index 90926c86d7..ad8b8e636e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs @@ -300,80 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GVA", ElectricApparentPowerUnit.Gigavoltampere, 4.2)] + [InlineData("en-US", "4.2 kVA", ElectricApparentPowerUnit.Kilovoltampere, 4.2)] + [InlineData("en-US", "4.2 MVA", ElectricApparentPowerUnit.Megavoltampere, 4.2)] + [InlineData("en-US", "4.2 µVA", ElectricApparentPowerUnit.Microvoltampere, 4.2)] + [InlineData("en-US", "4.2 mVA", ElectricApparentPowerUnit.Millivoltampere, 4.2)] + [InlineData("en-US", "4.2 VA", ElectricApparentPowerUnit.Voltampere, 4.2)] + public void Parse(string culture, string quantityString, ElectricApparentPowerUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricApparentPower.Parse("1 GVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentPower.Parse("1 kVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentPower.Parse("1 MVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megavoltamperes, MegavoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Megavoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentPower.Parse("1 µVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentPower.Parse("1 mVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millivoltamperes, MillivoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Millivoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricApparentPower.Parse("1 VA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricApparentPower.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GVA", ElectricApparentPowerUnit.Gigavoltampere, 4.2)] + [InlineData("en-US", "4.2 kVA", ElectricApparentPowerUnit.Kilovoltampere, 4.2)] + [InlineData("en-US", "4.2 MVA", ElectricApparentPowerUnit.Megavoltampere, 4.2)] + [InlineData("en-US", "4.2 µVA", ElectricApparentPowerUnit.Microvoltampere, 4.2)] + [InlineData("en-US", "4.2 mVA", ElectricApparentPowerUnit.Millivoltampere, 4.2)] + [InlineData("en-US", "4.2 VA", ElectricApparentPowerUnit.Voltampere, 4.2)] + public void TryParse(string culture, string quantityString, ElectricApparentPowerUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricApparentPower.TryParse("1 GVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsed.Unit); - } - - { - Assert.True(ElectricApparentPower.TryParse("1 kVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsed.Unit); - } - - { - Assert.True(ElectricApparentPower.TryParse("1 µVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsed.Unit); - } - - { - Assert.True(ElectricApparentPower.TryParse("1 VA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); - Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricApparentPower.TryParse(quantityString, out ElectricApparentPower parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -490,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricApparentPowerUnit.Gigavoltampere, "GVA")] + [InlineData("en-US", ElectricApparentPowerUnit.Kilovoltampere, "kVA")] + [InlineData("en-US", ElectricApparentPowerUnit.Megavoltampere, "MVA")] + [InlineData("en-US", ElectricApparentPowerUnit.Microvoltampere, "µVA")] + [InlineData("en-US", ElectricApparentPowerUnit.Millivoltampere, "mVA")] + [InlineData("en-US", ElectricApparentPowerUnit.Voltampere, "VA")] + public void GetAbbreviationForCulture(string culture, ElectricApparentPowerUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricApparentPower.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricApparentPower.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricApparentPower.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricApparentPowerUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs index bde487ad02..24d32331dd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs @@ -306,93 +306,36 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 F", ElectricCapacitanceUnit.Farad, 4.2)] + [InlineData("en-US", "4.2 kF", ElectricCapacitanceUnit.Kilofarad, 4.2)] + [InlineData("en-US", "4.2 MF", ElectricCapacitanceUnit.Megafarad, 4.2)] + [InlineData("en-US", "4.2 µF", ElectricCapacitanceUnit.Microfarad, 4.2)] + [InlineData("en-US", "4.2 mF", ElectricCapacitanceUnit.Millifarad, 4.2)] + [InlineData("en-US", "4.2 nF", ElectricCapacitanceUnit.Nanofarad, 4.2)] + [InlineData("en-US", "4.2 pF", ElectricCapacitanceUnit.Picofarad, 4.2)] + public void Parse(string culture, string quantityString, ElectricCapacitanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricCapacitance.Parse("1 F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Farad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 kF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 MF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megafarads, MegafaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Megafarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 µF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 mF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millifarads, MillifaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Millifarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 nF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCapacitance.Parse("1 pF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricCapacitance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 F", ElectricCapacitanceUnit.Farad, 4.2)] + [InlineData("en-US", "4.2 kF", ElectricCapacitanceUnit.Kilofarad, 4.2)] + [InlineData("en-US", "4.2 MF", ElectricCapacitanceUnit.Megafarad, 4.2)] + [InlineData("en-US", "4.2 µF", ElectricCapacitanceUnit.Microfarad, 4.2)] + [InlineData("en-US", "4.2 mF", ElectricCapacitanceUnit.Millifarad, 4.2)] + [InlineData("en-US", "4.2 nF", ElectricCapacitanceUnit.Nanofarad, 4.2)] + [InlineData("en-US", "4.2 pF", ElectricCapacitanceUnit.Picofarad, 4.2)] + public void TryParse(string culture, string quantityString, ElectricCapacitanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricCapacitance.TryParse("1 F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Farad, parsed.Unit); - } - - { - Assert.True(ElectricCapacitance.TryParse("1 kF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsed.Unit); - } - - { - Assert.True(ElectricCapacitance.TryParse("1 µF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsed.Unit); - } - - { - Assert.True(ElectricCapacitance.TryParse("1 nF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsed.Unit); - } - - { - Assert.True(ElectricCapacitance.TryParse("1 pF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); - Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricCapacitance.TryParse(quantityString, out ElectricCapacitance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -517,6 +460,33 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricCapacitanceUnit.Farad, "F")] + [InlineData("en-US", ElectricCapacitanceUnit.Kilofarad, "kF")] + [InlineData("en-US", ElectricCapacitanceUnit.Megafarad, "MF")] + [InlineData("en-US", ElectricCapacitanceUnit.Microfarad, "µF")] + [InlineData("en-US", ElectricCapacitanceUnit.Millifarad, "mF")] + [InlineData("en-US", ElectricCapacitanceUnit.Nanofarad, "nF")] + [InlineData("en-US", ElectricCapacitanceUnit.Picofarad, "pF")] + public void GetAbbreviationForCulture(string culture, ElectricCapacitanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricCapacitance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricCapacitance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricCapacitance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricCapacitanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index 26d30df138..1b0b79dfaf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricChargeDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricChargeDensity.Parse("1 C/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricChargeDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricChargeDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricChargeDensity.TryParse("1 C/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricChargeDensity.TryParse(quantityString, out ElectricChargeDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricChargeDensityUnit.CoulombPerCubicMeter, "C/m³")] + public void GetAbbreviationForCulture(string culture, ElectricChargeDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricChargeDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricChargeDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricChargeDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricChargeDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index 24ff6db846..53b7f2cbc4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -330,173 +330,52 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 A-h", ElectricChargeUnit.AmpereHour, 4.2)] + [InlineData("en-US", "4.2 Ah", ElectricChargeUnit.AmpereHour, 4.2)] + [InlineData("en-US", "4.2 C", ElectricChargeUnit.Coulomb, 4.2)] + [InlineData("en-US", "4.2 kA-h", ElectricChargeUnit.KiloampereHour, 4.2)] + [InlineData("en-US", "4.2 kAh", ElectricChargeUnit.KiloampereHour, 4.2)] + [InlineData("en-US", "4.2 kC", ElectricChargeUnit.Kilocoulomb, 4.2)] + [InlineData("en-US", "4.2 MA-h", ElectricChargeUnit.MegaampereHour, 4.2)] + [InlineData("en-US", "4.2 MAh", ElectricChargeUnit.MegaampereHour, 4.2)] + [InlineData("en-US", "4.2 MC", ElectricChargeUnit.Megacoulomb, 4.2)] + [InlineData("en-US", "4.2 µC", ElectricChargeUnit.Microcoulomb, 4.2)] + [InlineData("en-US", "4.2 mA-h", ElectricChargeUnit.MilliampereHour, 4.2)] + [InlineData("en-US", "4.2 mAh", ElectricChargeUnit.MilliampereHour, 4.2)] + [InlineData("en-US", "4.2 mC", ElectricChargeUnit.Millicoulomb, 4.2)] + [InlineData("en-US", "4.2 nC", ElectricChargeUnit.Nanocoulomb, 4.2)] + [InlineData("en-US", "4.2 pC", ElectricChargeUnit.Picocoulomb, 4.2)] + public void Parse(string culture, string quantityString, ElectricChargeUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricCharge.Parse("1 A-h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmpereHours, AmpereHoursTolerance); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 Ah", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmpereHours, AmpereHoursTolerance); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Coulombs, CoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Coulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 kA-h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloampereHours, KiloampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 kAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloampereHours, KiloampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 kC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilocoulombs, KilocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Kilocoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 MA-h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaampereHours, MegaampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.MegaampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 MAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaampereHours, MegaampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.MegaampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 MC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megacoulombs, MegacoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Megacoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 µC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microcoulombs, MicrocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Microcoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 mA-h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliampereHours, MilliampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.MilliampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 mAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliampereHours, MilliampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.MilliampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 mC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millicoulombs, MillicoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Millicoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 nC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanocoulombs, NanocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Nanocoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCharge.Parse("1 pC", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picocoulombs, PicocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Picocoulomb, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricCharge.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 A-h", ElectricChargeUnit.AmpereHour, 4.2)] + [InlineData("en-US", "4.2 Ah", ElectricChargeUnit.AmpereHour, 4.2)] + [InlineData("en-US", "4.2 C", ElectricChargeUnit.Coulomb, 4.2)] + [InlineData("en-US", "4.2 kA-h", ElectricChargeUnit.KiloampereHour, 4.2)] + [InlineData("en-US", "4.2 kAh", ElectricChargeUnit.KiloampereHour, 4.2)] + [InlineData("en-US", "4.2 kC", ElectricChargeUnit.Kilocoulomb, 4.2)] + [InlineData("en-US", "4.2 MA-h", ElectricChargeUnit.MegaampereHour, 4.2)] + [InlineData("en-US", "4.2 MAh", ElectricChargeUnit.MegaampereHour, 4.2)] + [InlineData("en-US", "4.2 MC", ElectricChargeUnit.Megacoulomb, 4.2)] + [InlineData("en-US", "4.2 µC", ElectricChargeUnit.Microcoulomb, 4.2)] + [InlineData("en-US", "4.2 mA-h", ElectricChargeUnit.MilliampereHour, 4.2)] + [InlineData("en-US", "4.2 mAh", ElectricChargeUnit.MilliampereHour, 4.2)] + [InlineData("en-US", "4.2 mC", ElectricChargeUnit.Millicoulomb, 4.2)] + [InlineData("en-US", "4.2 nC", ElectricChargeUnit.Nanocoulomb, 4.2)] + [InlineData("en-US", "4.2 pC", ElectricChargeUnit.Picocoulomb, 4.2)] + public void TryParse(string culture, string quantityString, ElectricChargeUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricCharge.TryParse("1 A-h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmpereHours, AmpereHoursTolerance); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 Ah", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmpereHours, AmpereHoursTolerance); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Coulombs, CoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Coulomb, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 kA-h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloampereHours, KiloampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 kAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloampereHours, KiloampereHoursTolerance); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 kC", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilocoulombs, KilocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Kilocoulomb, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 µC", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microcoulombs, MicrocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Microcoulomb, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 nC", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanocoulombs, NanocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Nanocoulomb, parsed.Unit); - } - - { - Assert.True(ElectricCharge.TryParse("1 pC", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picocoulombs, PicocoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Picocoulomb, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricCharge.TryParse(quantityString, out ElectricCharge parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -685,6 +564,37 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricChargeUnit.AmpereHour, "A-h")] + [InlineData("en-US", ElectricChargeUnit.Coulomb, "C")] + [InlineData("en-US", ElectricChargeUnit.KiloampereHour, "kA-h")] + [InlineData("en-US", ElectricChargeUnit.Kilocoulomb, "kC")] + [InlineData("en-US", ElectricChargeUnit.MegaampereHour, "MA-h")] + [InlineData("en-US", ElectricChargeUnit.Megacoulomb, "MC")] + [InlineData("en-US", ElectricChargeUnit.Microcoulomb, "µC")] + [InlineData("en-US", ElectricChargeUnit.MilliampereHour, "mA-h")] + [InlineData("en-US", ElectricChargeUnit.Millicoulomb, "mC")] + [InlineData("en-US", ElectricChargeUnit.Nanocoulomb, "nC")] + [InlineData("en-US", ElectricChargeUnit.Picocoulomb, "pC")] + public void GetAbbreviationForCulture(string culture, ElectricChargeUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricCharge.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricCharge.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricCharge.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricChargeUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 626d6e3c2f..b2b870d567 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -360,198 +360,54 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricConductanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricConductanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricConductanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricConductanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricConductanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricConductanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricConductanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricConductanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricConductanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricConductanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricConductanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricConductanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricConductanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricConductanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricConductanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricConductanceUnit.Terasiemens, 4.2)] + public void Parse(string culture, string quantityString, ElectricConductanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricConductance.Parse("1 G℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricConductanceUnit.Gigamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 k℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricConductanceUnit.Kilomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 M℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); - Assert.Equal(ElectricConductanceUnit.Megamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Megasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricConductanceUnit.Mho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 µ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricConductanceUnit.Micromho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Microsiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 m℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); - Assert.Equal(ElectricConductanceUnit.Millimho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Millisiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 n℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricConductanceUnit.Nanomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Nanosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Siemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 T℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricConductanceUnit.Teramho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Terasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricConductance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricConductanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricConductanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricConductanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricConductanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricConductanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricConductanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricConductanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricConductanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricConductanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricConductanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricConductanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricConductanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricConductanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricConductanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricConductanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricConductanceUnit.Terasiemens, 4.2)] + public void TryParse(string culture, string quantityString, ElectricConductanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricConductance.TryParse("1 G℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricConductanceUnit.Gigamho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 k℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricConductanceUnit.Kilomho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricConductanceUnit.Mho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 µ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricConductanceUnit.Micromho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Microsiemens, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 n℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricConductanceUnit.Nanomho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 nS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Nanosiemens, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Siemens, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 T℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricConductanceUnit.Teramho, parsed.Unit); - } - - { - Assert.True(ElectricConductance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Terasiemens, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricConductance.TryParse(quantityString, out ElectricConductance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -748,6 +604,42 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricConductanceUnit.Gigamho, "G℧")] + [InlineData("en-US", ElectricConductanceUnit.Gigasiemens, "GS")] + [InlineData("en-US", ElectricConductanceUnit.Kilomho, "k℧")] + [InlineData("en-US", ElectricConductanceUnit.Kilosiemens, "kS")] + [InlineData("en-US", ElectricConductanceUnit.Megamho, "M℧")] + [InlineData("en-US", ElectricConductanceUnit.Megasiemens, "MS")] + [InlineData("en-US", ElectricConductanceUnit.Mho, "℧")] + [InlineData("en-US", ElectricConductanceUnit.Micromho, "µ℧")] + [InlineData("en-US", ElectricConductanceUnit.Microsiemens, "µS")] + [InlineData("en-US", ElectricConductanceUnit.Millimho, "m℧")] + [InlineData("en-US", ElectricConductanceUnit.Millisiemens, "mS")] + [InlineData("en-US", ElectricConductanceUnit.Nanomho, "n℧")] + [InlineData("en-US", ElectricConductanceUnit.Nanosiemens, "nS")] + [InlineData("en-US", ElectricConductanceUnit.Siemens, "S")] + [InlineData("en-US", ElectricConductanceUnit.Teramho, "T℧")] + [InlineData("en-US", ElectricConductanceUnit.Terasiemens, "TS")] + public void GetAbbreviationForCulture(string culture, ElectricConductanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricConductance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricConductance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricConductance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricConductanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index 9d1f5baac4..65daf47477 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -300,92 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 S/cm", ElectricConductivityUnit.SiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 S/ft", ElectricConductivityUnit.SiemensPerFoot, 4.2)] + [InlineData("en-US", "4.2 S/in", ElectricConductivityUnit.SiemensPerInch, 4.2)] + [InlineData("en-US", "4.2 S/m", ElectricConductivityUnit.SiemensPerMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricConductivityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricConductivity.Parse("1 µS/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrosiemensPerCentimeter, MicrosiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.MicrosiemensPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductivity.Parse("1 mS/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillisiemensPerCentimeter, MillisiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.MillisiemensPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductivity.Parse("1 S/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SiemensPerCentimeter, SiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductivity.Parse("1 S/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SiemensPerFoot, SiemensPerFootTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductivity.Parse("1 S/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SiemensPerInch, SiemensPerInchTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricConductivity.Parse("1 S/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SiemensPerMeter, SiemensPerMeterTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricConductivity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 S/cm", ElectricConductivityUnit.SiemensPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 S/ft", ElectricConductivityUnit.SiemensPerFoot, 4.2)] + [InlineData("en-US", "4.2 S/in", ElectricConductivityUnit.SiemensPerInch, 4.2)] + [InlineData("en-US", "4.2 S/m", ElectricConductivityUnit.SiemensPerMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricConductivityUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricConductivity.TryParse("1 µS/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrosiemensPerCentimeter, MicrosiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.MicrosiemensPerCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricConductivity.TryParse("1 mS/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillisiemensPerCentimeter, MillisiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.MillisiemensPerCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricConductivity.TryParse("1 S/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SiemensPerCentimeter, SiemensPerCentimeterTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricConductivity.TryParse("1 S/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SiemensPerFoot, SiemensPerFootTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerFoot, parsed.Unit); - } - - { - Assert.True(ElectricConductivity.TryParse("1 S/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SiemensPerInch, SiemensPerInchTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerInch, parsed.Unit); - } - - { - Assert.True(ElectricConductivity.TryParse("1 S/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SiemensPerMeter, SiemensPerMeterTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricConductivity.TryParse(quantityString, out ElectricConductivity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -502,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricConductivityUnit.MicrosiemensPerCentimeter, "µS/cm")] + [InlineData("en-US", ElectricConductivityUnit.MillisiemensPerCentimeter, "mS/cm")] + [InlineData("en-US", ElectricConductivityUnit.SiemensPerCentimeter, "S/cm")] + [InlineData("en-US", ElectricConductivityUnit.SiemensPerFoot, "S/ft")] + [InlineData("en-US", ElectricConductivityUnit.SiemensPerInch, "S/in")] + [InlineData("en-US", ElectricConductivityUnit.SiemensPerMeter, "S/m")] + public void GetAbbreviationForCulture(string culture, ElectricConductivityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricConductivity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricConductivity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricConductivity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricConductivityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index 98e7fc9bd2..cbce5e0abb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricCurrentDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricCurrentDensity.Parse("1 A/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareFoot, AmperesPerSquareFootTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentDensity.Parse("1 A/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareInch, AmperesPerSquareInchTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentDensity.Parse("1 A/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricCurrentDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricCurrentDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricCurrentDensity.TryParse("1 A/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareFoot, AmperesPerSquareFootTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareFoot, parsed.Unit); - } - - { - Assert.True(ElectricCurrentDensity.TryParse("1 A/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareInch, AmperesPerSquareInchTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareInch, parsed.Unit); - } - - { - Assert.True(ElectricCurrentDensity.TryParse("1 A/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricCurrentDensity.TryParse(quantityString, out ElectricCurrentDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricCurrentDensityUnit.AmperePerSquareFoot, "A/ft²")] + [InlineData("en-US", ElectricCurrentDensityUnit.AmperePerSquareInch, "A/in²")] + [InlineData("en-US", ElectricCurrentDensityUnit.AmperePerSquareMeter, "A/m²")] + public void GetAbbreviationForCulture(string culture, ElectricCurrentDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricCurrentDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricCurrentDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricCurrentDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricCurrentDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index b1e4626c12..3d036124da 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -306,105 +306,36 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond, 4.2)] + [InlineData("en-US", "4.2 A/min", ElectricCurrentGradientUnit.AmperePerMinute, 4.2)] + [InlineData("en-US", "4.2 A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond, 4.2)] + [InlineData("en-US", "4.2 A/s", ElectricCurrentGradientUnit.AmperePerSecond, 4.2)] + [InlineData("en-US", "4.2 mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute, 4.2)] + [InlineData("en-US", "4.2 mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond, 4.2)] + public void Parse(string culture, string quantityString, ElectricCurrentGradientUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricCurrentGradient.Parse("1 A/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerMicrosecond, AmperesPerMicrosecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 A/ms", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerMillisecond, AmperesPerMillisecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMillisecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 A/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerMinute, AmperesPerMinuteTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 A/ns", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerNanosecond, AmperesPerNanosecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerNanosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 A/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerSecond, AmperesPerSecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 mA/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliamperesPerMinute, MilliamperesPerMinuteTolerance); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrentGradient.Parse("1 mA/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliamperesPerSecond, MilliamperesPerSecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricCurrentGradient.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond, 4.2)] + [InlineData("en-US", "4.2 A/min", ElectricCurrentGradientUnit.AmperePerMinute, 4.2)] + [InlineData("en-US", "4.2 A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond, 4.2)] + [InlineData("en-US", "4.2 A/s", ElectricCurrentGradientUnit.AmperePerSecond, 4.2)] + [InlineData("en-US", "4.2 mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute, 4.2)] + [InlineData("en-US", "4.2 mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond, 4.2)] + public void TryParse(string culture, string quantityString, ElectricCurrentGradientUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricCurrentGradient.TryParse("1 A/μs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerMicrosecond, AmperesPerMicrosecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMicrosecond, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 A/ms", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerMillisecond, AmperesPerMillisecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMillisecond, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 A/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerMinute, AmperesPerMinuteTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMinute, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 A/ns", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerNanosecond, AmperesPerNanosecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerNanosecond, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 A/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerSecond, AmperesPerSecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 mA/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliamperesPerMinute, MilliamperesPerMinuteTolerance); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerMinute, parsed.Unit); - } - - { - Assert.True(ElectricCurrentGradient.TryParse("1 mA/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliamperesPerSecond, MilliamperesPerSecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricCurrentGradient.TryParse(quantityString, out ElectricCurrentGradient parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -529,6 +460,33 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricCurrentGradientUnit.AmperePerMicrosecond, "A/μs")] + [InlineData("en-US", ElectricCurrentGradientUnit.AmperePerMillisecond, "A/ms")] + [InlineData("en-US", ElectricCurrentGradientUnit.AmperePerMinute, "A/min")] + [InlineData("en-US", ElectricCurrentGradientUnit.AmperePerNanosecond, "A/ns")] + [InlineData("en-US", ElectricCurrentGradientUnit.AmperePerSecond, "A/s")] + [InlineData("en-US", ElectricCurrentGradientUnit.MilliamperePerMinute, "mA/min")] + [InlineData("en-US", ElectricCurrentGradientUnit.MilliamperePerSecond, "mA/s")] + public void GetAbbreviationForCulture(string culture, ElectricCurrentGradientUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricCurrentGradient.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricCurrentGradient.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricCurrentGradient.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricCurrentGradientUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index c75a4039dc..da39493c93 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -318,119 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 A", ElectricCurrentUnit.Ampere, 4.2)] + [InlineData("en-US", "4.2 cA", ElectricCurrentUnit.Centiampere, 4.2)] + [InlineData("en-US", "4.2 fA", ElectricCurrentUnit.Femtoampere, 4.2)] + [InlineData("en-US", "4.2 kA", ElectricCurrentUnit.Kiloampere, 4.2)] + [InlineData("en-US", "4.2 MA", ElectricCurrentUnit.Megaampere, 4.2)] + [InlineData("en-US", "4.2 µA", ElectricCurrentUnit.Microampere, 4.2)] + [InlineData("en-US", "4.2 mA", ElectricCurrentUnit.Milliampere, 4.2)] + [InlineData("en-US", "4.2 nA", ElectricCurrentUnit.Nanoampere, 4.2)] + [InlineData("en-US", "4.2 pA", ElectricCurrentUnit.Picoampere, 4.2)] + public void Parse(string culture, string quantityString, ElectricCurrentUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricCurrent.Parse("1 A", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Amperes, AmperesTolerance); - Assert.Equal(ElectricCurrentUnit.Ampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 cA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centiamperes, CentiamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Centiampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 fA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtoamperes, FemtoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Femtoampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 kA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloamperes, KiloamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Kiloampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 MA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaamperes, MegaamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Megaampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 µA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microamperes, MicroamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Microampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 mA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliamperes, MilliamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Milliampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 nA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoamperes, NanoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Nanoampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricCurrent.Parse("1 pA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picoamperes, PicoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Picoampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricCurrent.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 A", ElectricCurrentUnit.Ampere, 4.2)] + [InlineData("en-US", "4.2 cA", ElectricCurrentUnit.Centiampere, 4.2)] + [InlineData("en-US", "4.2 fA", ElectricCurrentUnit.Femtoampere, 4.2)] + [InlineData("en-US", "4.2 kA", ElectricCurrentUnit.Kiloampere, 4.2)] + [InlineData("en-US", "4.2 MA", ElectricCurrentUnit.Megaampere, 4.2)] + [InlineData("en-US", "4.2 µA", ElectricCurrentUnit.Microampere, 4.2)] + [InlineData("en-US", "4.2 mA", ElectricCurrentUnit.Milliampere, 4.2)] + [InlineData("en-US", "4.2 nA", ElectricCurrentUnit.Nanoampere, 4.2)] + [InlineData("en-US", "4.2 pA", ElectricCurrentUnit.Picoampere, 4.2)] + public void TryParse(string culture, string quantityString, ElectricCurrentUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricCurrent.TryParse("1 A", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Amperes, AmperesTolerance); - Assert.Equal(ElectricCurrentUnit.Ampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 cA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centiamperes, CentiamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Centiampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 fA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtoamperes, FemtoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Femtoampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 kA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloamperes, KiloamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Kiloampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 µA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microamperes, MicroamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Microampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 nA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoamperes, NanoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Nanoampere, parsed.Unit); - } - - { - Assert.True(ElectricCurrent.TryParse("1 pA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picoamperes, PicoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Picoampere, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricCurrent.TryParse(quantityString, out ElectricCurrent parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -571,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricCurrentUnit.Ampere, "A")] + [InlineData("en-US", ElectricCurrentUnit.Centiampere, "cA")] + [InlineData("en-US", ElectricCurrentUnit.Femtoampere, "fA")] + [InlineData("en-US", ElectricCurrentUnit.Kiloampere, "kA")] + [InlineData("en-US", ElectricCurrentUnit.Megaampere, "MA")] + [InlineData("en-US", ElectricCurrentUnit.Microampere, "µA")] + [InlineData("en-US", ElectricCurrentUnit.Milliampere, "mA")] + [InlineData("en-US", ElectricCurrentUnit.Nanoampere, "nA")] + [InlineData("en-US", ElectricCurrentUnit.Picoampere, "pA")] + public void GetAbbreviationForCulture(string culture, ElectricCurrentUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricCurrent.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricCurrent.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricCurrent.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricCurrentUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index e98d602dcb..9cfdc86a3a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 V/m", ElectricFieldUnit.VoltPerMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricFieldUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricField.Parse("1 V/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsPerMeter, VoltsPerMeterTolerance); - Assert.Equal(ElectricFieldUnit.VoltPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricField.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 V/m", ElectricFieldUnit.VoltPerMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricFieldUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricField.TryParse("1 V/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsPerMeter, VoltsPerMeterTolerance); - Assert.Equal(ElectricFieldUnit.VoltPerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricField.TryParse(quantityString, out ElectricField parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricFieldUnit.VoltPerMeter, "V/m")] + public void GetAbbreviationForCulture(string culture, ElectricFieldUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricField.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricField.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricField.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricFieldUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs index 478a75d680..7d128e85e0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs @@ -312,106 +312,38 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricImpedanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricImpedanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricImpedanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricImpedanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricImpedanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricImpedanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricImpedanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricImpedanceUnit.Teraohm, 4.2)] + public void Parse(string culture, string quantityString, ElectricImpedanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricImpedance.Parse("1 GΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 kΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 MΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaohms, MegaohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Megaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 µΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Microohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 mΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliohms, MilliohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Milliohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Ohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricImpedance.Parse("1 TΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Teraohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricImpedance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricImpedanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricImpedanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricImpedanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricImpedanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricImpedanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricImpedanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricImpedanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricImpedanceUnit.Teraohm, 4.2)] + public void TryParse(string culture, string quantityString, ElectricImpedanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricImpedance.TryParse("1 GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsed.Unit); - } - - { - Assert.True(ElectricImpedance.TryParse("1 kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsed.Unit); - } - - { - Assert.True(ElectricImpedance.TryParse("1 µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Microohm, parsed.Unit); - } - - { - Assert.True(ElectricImpedance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsed.Unit); - } - - { - Assert.True(ElectricImpedance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Ohm, parsed.Unit); - } - - { - Assert.True(ElectricImpedance.TryParse("1 TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricImpedanceUnit.Teraohm, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricImpedance.TryParse(quantityString, out ElectricImpedance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -544,6 +476,34 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricImpedanceUnit.Gigaohm, "GΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Kiloohm, "kΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Megaohm, "MΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Microohm, "µΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Milliohm, "mΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Nanoohm, "nΩ")] + [InlineData("en-US", ElectricImpedanceUnit.Ohm, "Ω")] + [InlineData("en-US", ElectricImpedanceUnit.Teraohm, "TΩ")] + public void GetAbbreviationForCulture(string culture, ElectricImpedanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricImpedance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricImpedance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricImpedance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricImpedanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index 0afdb21c0a..011ca606d9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -294,79 +294,32 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 H", ElectricInductanceUnit.Henry, 4.2)] + [InlineData("en-US", "4.2 µH", ElectricInductanceUnit.Microhenry, 4.2)] + [InlineData("en-US", "4.2 mH", ElectricInductanceUnit.Millihenry, 4.2)] + [InlineData("en-US", "4.2 nH", ElectricInductanceUnit.Nanohenry, 4.2)] + [InlineData("en-US", "4.2 pH", ElectricInductanceUnit.Picohenry, 4.2)] + public void Parse(string culture, string quantityString, ElectricInductanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricInductance.Parse("1 H", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Henries, HenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Henry, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricInductance.Parse("1 µH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microhenries, MicrohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Microhenry, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricInductance.Parse("1 mH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millihenries, MillihenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Millihenry, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricInductance.Parse("1 nH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanohenries, NanohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Nanohenry, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricInductance.Parse("1 pH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picohenries, PicohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Picohenry, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricInductance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 H", ElectricInductanceUnit.Henry, 4.2)] + [InlineData("en-US", "4.2 µH", ElectricInductanceUnit.Microhenry, 4.2)] + [InlineData("en-US", "4.2 mH", ElectricInductanceUnit.Millihenry, 4.2)] + [InlineData("en-US", "4.2 nH", ElectricInductanceUnit.Nanohenry, 4.2)] + [InlineData("en-US", "4.2 pH", ElectricInductanceUnit.Picohenry, 4.2)] + public void TryParse(string culture, string quantityString, ElectricInductanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricInductance.TryParse("1 H", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Henries, HenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Henry, parsed.Unit); - } - - { - Assert.True(ElectricInductance.TryParse("1 µH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microhenries, MicrohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Microhenry, parsed.Unit); - } - - { - Assert.True(ElectricInductance.TryParse("1 mH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millihenries, MillihenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Millihenry, parsed.Unit); - } - - { - Assert.True(ElectricInductance.TryParse("1 nH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanohenries, NanohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Nanohenry, parsed.Unit); - } - - { - Assert.True(ElectricInductance.TryParse("1 pH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picohenries, PicohenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Picohenry, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricInductance.TryParse(quantityString, out ElectricInductance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -475,6 +428,31 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricInductanceUnit.Henry, "H")] + [InlineData("en-US", ElectricInductanceUnit.Microhenry, "µH")] + [InlineData("en-US", ElectricInductanceUnit.Millihenry, "mH")] + [InlineData("en-US", ElectricInductanceUnit.Nanohenry, "nH")] + [InlineData("en-US", ElectricInductanceUnit.Picohenry, "pH")] + public void GetAbbreviationForCulture(string culture, ElectricInductanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricInductance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricInductance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricInductance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricInductanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 918baa99bd..250eed3f05 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -384,226 +384,62 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour, 4.2)] + [InlineData("en-US", "4.2 kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour, 4.2)] + [InlineData("en-US", "4.2 MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour, 4.2)] + [InlineData("en-US", "4.2 µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour, 4.2)] + [InlineData("en-US", "4.2 mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 V/h", ElectricPotentialChangeRateUnit.VoltPerHour, 4.2)] + [InlineData("en-US", "4.2 V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 V/min", ElectricPotentialChangeRateUnit.VoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 V/s", ElectricPotentialChangeRateUnit.VoltPerSecond, 4.2)] + public void Parse(string culture, string quantityString, ElectricPotentialChangeRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 kV/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerHour, KilovoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 kV/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerMicrosecond, KilovoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 kV/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerMinute, KilovoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 kV/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerSecond, KilovoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 MV/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsPerHour, MegavoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 MV/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsPerMicrosecond, MegavoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 MV/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsPerMinute, MegavoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 MV/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsPerSecond, MegavoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 µV/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerHour, MicrovoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 µV/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerMicrosecond, MicrovoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 µV/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerMinute, MicrovoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 µV/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerSecond, MicrovoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 mV/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsPerHour, MillivoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 mV/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsPerMicrosecond, MillivoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 mV/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsPerMinute, MillivoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 mV/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsPerSecond, MillivoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 V/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsPerHour, VoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 V/μs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsPerMicrosecond, VoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 V/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsPerMinute, VoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialChangeRate.Parse("1 V/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsPerSecond, VoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricPotentialChangeRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour, 4.2)] + [InlineData("en-US", "4.2 kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour, 4.2)] + [InlineData("en-US", "4.2 MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour, 4.2)] + [InlineData("en-US", "4.2 µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour, 4.2)] + [InlineData("en-US", "4.2 mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond, 4.2)] + [InlineData("en-US", "4.2 V/h", ElectricPotentialChangeRateUnit.VoltPerHour, 4.2)] + [InlineData("en-US", "4.2 V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond, 4.2)] + [InlineData("en-US", "4.2 V/min", ElectricPotentialChangeRateUnit.VoltPerMinute, 4.2)] + [InlineData("en-US", "4.2 V/s", ElectricPotentialChangeRateUnit.VoltPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, ElectricPotentialChangeRateUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 kV/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerHour, KilovoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 kV/μs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerMicrosecond, KilovoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 kV/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerMinute, KilovoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 kV/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsPerSecond, KilovoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 µV/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerHour, MicrovoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 µV/μs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerMicrosecond, MicrovoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 µV/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerMinute, MicrovoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 µV/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsPerSecond, MicrovoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 V/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsPerHour, VoltsPerHourTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 V/μs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsPerMicrosecond, VoltsPerMicrosecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 V/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsPerMinute, VoltsPerMinuteTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, parsed.Unit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParse("1 V/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsPerSecond, VoltsPerSecondTolerance); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricPotentialChangeRate.TryParse(quantityString, out ElectricPotentialChangeRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -832,6 +668,46 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricPotentialChangeRateUnit.KilovoltPerHour, "kV/h")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, "kV/μs")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.KilovoltPerMinute, "kV/min")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.KilovoltPerSecond, "kV/s")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MegavoltPerHour, "MV/h")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, "MV/μs")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MegavoltPerMinute, "MV/min")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MegavoltPerSecond, "MV/s")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MicrovoltPerHour, "µV/h")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, "µV/μs")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MicrovoltPerMinute, "µV/min")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MicrovoltPerSecond, "µV/s")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MillivoltPerHour, "mV/h")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, "mV/μs")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MillivoltPerMinute, "mV/min")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.MillivoltPerSecond, "mV/s")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.VoltPerHour, "V/h")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.VoltPerMicrosecond, "V/μs")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.VoltPerMinute, "V/min")] + [InlineData("en-US", ElectricPotentialChangeRateUnit.VoltPerSecond, "V/s")] + public void GetAbbreviationForCulture(string culture, ElectricPotentialChangeRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricPotentialChangeRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricPotentialChangeRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricPotentialChangeRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricPotentialChangeRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index b7fe90bd04..5f6b5970e0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -300,146 +300,46 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kV", ElectricPotentialUnit.Kilovolt, 4.2)] + [InlineData("en-US", "4.2 MV", ElectricPotentialUnit.Megavolt, 4.2)] + [InlineData("en-US", "4.2 µV", ElectricPotentialUnit.Microvolt, 4.2)] + [InlineData("en-US", "4.2 mV", ElectricPotentialUnit.Millivolt, 4.2)] + [InlineData("en-US", "4.2 nV", ElectricPotentialUnit.Nanovolt, 4.2)] + [InlineData("en-US", "4.2 V", ElectricPotentialUnit.Volt, 4.2)] + [InlineData("ru-RU", "4,2 кВ", ElectricPotentialUnit.Kilovolt, 4.2)] + [InlineData("ru-RU", "4,2 МВ", ElectricPotentialUnit.Megavolt, 4.2)] + [InlineData("ru-RU", "4,2 мкВ", ElectricPotentialUnit.Microvolt, 4.2)] + [InlineData("ru-RU", "4,2 мВ", ElectricPotentialUnit.Millivolt, 4.2)] + [InlineData("ru-RU", "4,2 нВ", ElectricPotentialUnit.Nanovolt, 4.2)] + [InlineData("ru-RU", "4,2 В", ElectricPotentialUnit.Volt, 4.2)] + public void Parse(string culture, string quantityString, ElectricPotentialUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricPotential.Parse("1 kV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilovolts, KilovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 кВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilovolts, KilovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 MV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megavolts, MegavoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Megavolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 МВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megavolts, MegavoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Megavolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 µV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microvolts, MicrovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 мкВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microvolts, MicrovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 mV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millivolts, MillivoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Millivolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 мВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millivolts, MillivoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Millivolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 nV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanovolts, NanovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 нВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanovolts, NanovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 V", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Volts, VoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Volt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotential.Parse("1 В", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Volts, VoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Volt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricPotential.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kV", ElectricPotentialUnit.Kilovolt, 4.2)] + [InlineData("en-US", "4.2 MV", ElectricPotentialUnit.Megavolt, 4.2)] + [InlineData("en-US", "4.2 µV", ElectricPotentialUnit.Microvolt, 4.2)] + [InlineData("en-US", "4.2 mV", ElectricPotentialUnit.Millivolt, 4.2)] + [InlineData("en-US", "4.2 nV", ElectricPotentialUnit.Nanovolt, 4.2)] + [InlineData("en-US", "4.2 V", ElectricPotentialUnit.Volt, 4.2)] + [InlineData("ru-RU", "4,2 кВ", ElectricPotentialUnit.Kilovolt, 4.2)] + [InlineData("ru-RU", "4,2 МВ", ElectricPotentialUnit.Megavolt, 4.2)] + [InlineData("ru-RU", "4,2 мкВ", ElectricPotentialUnit.Microvolt, 4.2)] + [InlineData("ru-RU", "4,2 мВ", ElectricPotentialUnit.Millivolt, 4.2)] + [InlineData("ru-RU", "4,2 нВ", ElectricPotentialUnit.Nanovolt, 4.2)] + [InlineData("ru-RU", "4,2 В", ElectricPotentialUnit.Volt, 4.2)] + public void TryParse(string culture, string quantityString, ElectricPotentialUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricPotential.TryParse("1 kV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilovolts, KilovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 кВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilovolts, KilovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 µV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microvolts, MicrovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 мкВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microvolts, MicrovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 nV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanovolts, NanovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 нВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanovolts, NanovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 V", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Volts, VoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Volt, parsed.Unit); - } - - { - Assert.True(ElectricPotential.TryParse("1 В", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Volts, VoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Volt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricPotential.TryParse(quantityString, out ElectricPotential parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -580,6 +480,38 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricPotentialUnit.Kilovolt, "kV")] + [InlineData("en-US", ElectricPotentialUnit.Megavolt, "MV")] + [InlineData("en-US", ElectricPotentialUnit.Microvolt, "µV")] + [InlineData("en-US", ElectricPotentialUnit.Millivolt, "mV")] + [InlineData("en-US", ElectricPotentialUnit.Nanovolt, "nV")] + [InlineData("en-US", ElectricPotentialUnit.Volt, "V")] + [InlineData("ru-RU", ElectricPotentialUnit.Kilovolt, "кВ")] + [InlineData("ru-RU", ElectricPotentialUnit.Megavolt, "МВ")] + [InlineData("ru-RU", ElectricPotentialUnit.Microvolt, "мкВ")] + [InlineData("ru-RU", ElectricPotentialUnit.Millivolt, "мВ")] + [InlineData("ru-RU", ElectricPotentialUnit.Nanovolt, "нВ")] + [InlineData("ru-RU", ElectricPotentialUnit.Volt, "В")] + public void GetAbbreviationForCulture(string culture, ElectricPotentialUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricPotential.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricPotential.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricPotential.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricPotentialUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs index 9efbd23c57..04ab192341 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs @@ -312,106 +312,38 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricReactanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricReactanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricReactanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricReactanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricReactanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricReactanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricReactanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricReactanceUnit.Teraohm, 4.2)] + public void Parse(string culture, string quantityString, ElectricReactanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricReactance.Parse("1 GΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Gigaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 kΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Kiloohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 MΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaohms, MegaohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Megaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 µΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Microohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 mΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliohms, MilliohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Milliohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Nanoohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricReactanceUnit.Ohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactance.Parse("1 TΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Teraohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricReactance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricReactanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricReactanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricReactanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricReactanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricReactanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricReactanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricReactanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricReactanceUnit.Teraohm, 4.2)] + public void TryParse(string culture, string quantityString, ElectricReactanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricReactance.TryParse("1 GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Gigaohm, parsed.Unit); - } - - { - Assert.True(ElectricReactance.TryParse("1 kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Kiloohm, parsed.Unit); - } - - { - Assert.True(ElectricReactance.TryParse("1 µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Microohm, parsed.Unit); - } - - { - Assert.True(ElectricReactance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Nanoohm, parsed.Unit); - } - - { - Assert.True(ElectricReactance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricReactanceUnit.Ohm, parsed.Unit); - } - - { - Assert.True(ElectricReactance.TryParse("1 TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricReactanceUnit.Teraohm, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricReactance.TryParse(quantityString, out ElectricReactance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -544,6 +476,34 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricReactanceUnit.Gigaohm, "GΩ")] + [InlineData("en-US", ElectricReactanceUnit.Kiloohm, "kΩ")] + [InlineData("en-US", ElectricReactanceUnit.Megaohm, "MΩ")] + [InlineData("en-US", ElectricReactanceUnit.Microohm, "µΩ")] + [InlineData("en-US", ElectricReactanceUnit.Milliohm, "mΩ")] + [InlineData("en-US", ElectricReactanceUnit.Nanoohm, "nΩ")] + [InlineData("en-US", ElectricReactanceUnit.Ohm, "Ω")] + [InlineData("en-US", ElectricReactanceUnit.Teraohm, "TΩ")] + public void GetAbbreviationForCulture(string culture, ElectricReactanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricReactance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricReactance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricReactance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricReactanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs index d18a3ca661..c6fdb0c719 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kvarh", ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, 4.2)] + [InlineData("en-US", "4.2 Mvarh", ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, 4.2)] + [InlineData("en-US", "4.2 varh", ElectricReactiveEnergyUnit.VoltampereReactiveHour, 4.2)] + public void Parse(string culture, string quantityString, ElectricReactiveEnergyUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricReactiveEnergy.Parse("1 kvarh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactiveEnergy.Parse("1 Mvarh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactiveEnergy.Parse("1 varh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricReactiveEnergy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kvarh", ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, 4.2)] + [InlineData("en-US", "4.2 Mvarh", ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, 4.2)] + [InlineData("en-US", "4.2 varh", ElectricReactiveEnergyUnit.VoltampereReactiveHour, 4.2)] + public void TryParse(string culture, string quantityString, ElectricReactiveEnergyUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricReactiveEnergy.TryParse("1 kvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); - } - - { - Assert.True(ElectricReactiveEnergy.TryParse("1 Mvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); - } - - { - Assert.True(ElectricReactiveEnergy.TryParse("1 varh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricReactiveEnergy.TryParse(quantityString, out ElectricReactiveEnergy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, "kvarh")] + [InlineData("en-US", ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, "Mvarh")] + [InlineData("en-US", ElectricReactiveEnergyUnit.VoltampereReactiveHour, "varh")] + public void GetAbbreviationForCulture(string culture, ElectricReactiveEnergyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricReactiveEnergy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricReactiveEnergy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricReactiveEnergy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricReactiveEnergyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs index 857c012a0a..74aa008372 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs @@ -288,66 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Gvar", ElectricReactivePowerUnit.GigavoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 kvar", ElectricReactivePowerUnit.KilovoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 Mvar", ElectricReactivePowerUnit.MegavoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 var", ElectricReactivePowerUnit.VoltampereReactive, 4.2)] + public void Parse(string culture, string quantityString, ElectricReactivePowerUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricReactivePower.Parse("1 Gvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactivePower.Parse("1 kvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactivePower.Parse("1 Mvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricReactivePower.Parse("1 var", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricReactivePower.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Gvar", ElectricReactivePowerUnit.GigavoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 kvar", ElectricReactivePowerUnit.KilovoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 Mvar", ElectricReactivePowerUnit.MegavoltampereReactive, 4.2)] + [InlineData("en-US", "4.2 var", ElectricReactivePowerUnit.VoltampereReactive, 4.2)] + public void TryParse(string culture, string quantityString, ElectricReactivePowerUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricReactivePower.TryParse("1 Gvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsed.Unit); - } - - { - Assert.True(ElectricReactivePower.TryParse("1 kvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsed.Unit); - } - - { - Assert.True(ElectricReactivePower.TryParse("1 Mvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsed.Unit); - } - - { - Assert.True(ElectricReactivePower.TryParse("1 var", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); - Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricReactivePower.TryParse(quantityString, out ElectricReactivePower parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -448,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricReactivePowerUnit.GigavoltampereReactive, "Gvar")] + [InlineData("en-US", ElectricReactivePowerUnit.KilovoltampereReactive, "kvar")] + [InlineData("en-US", ElectricReactivePowerUnit.MegavoltampereReactive, "Mvar")] + [InlineData("en-US", ElectricReactivePowerUnit.VoltampereReactive, "var")] + public void GetAbbreviationForCulture(string culture, ElectricReactivePowerUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricReactivePower.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricReactivePower.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricReactivePower.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricReactivePowerUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index d1c3fac3cc..dd7f2fb678 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -312,106 +312,38 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricResistanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricResistanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricResistanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricResistanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricResistanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricResistanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricResistanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricResistanceUnit.Teraohm, 4.2)] + public void Parse(string culture, string quantityString, ElectricResistanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricResistance.Parse("1 GΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Gigaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 kΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Kiloohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 MΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaohms, MegaohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Megaohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 µΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Microohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 mΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliohms, MilliohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Milliohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Nanoohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricResistanceUnit.Ohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistance.Parse("1 TΩ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Teraohm, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricResistance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GΩ", ElectricResistanceUnit.Gigaohm, 4.2)] + [InlineData("en-US", "4.2 kΩ", ElectricResistanceUnit.Kiloohm, 4.2)] + [InlineData("en-US", "4.2 MΩ", ElectricResistanceUnit.Megaohm, 4.2)] + [InlineData("en-US", "4.2 µΩ", ElectricResistanceUnit.Microohm, 4.2)] + [InlineData("en-US", "4.2 mΩ", ElectricResistanceUnit.Milliohm, 4.2)] + [InlineData("en-US", "4.2 nΩ", ElectricResistanceUnit.Nanoohm, 4.2)] + [InlineData("en-US", "4.2 Ω", ElectricResistanceUnit.Ohm, 4.2)] + [InlineData("en-US", "4.2 TΩ", ElectricResistanceUnit.Teraohm, 4.2)] + public void TryParse(string culture, string quantityString, ElectricResistanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricResistance.TryParse("1 GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Gigaohm, parsed.Unit); - } - - { - Assert.True(ElectricResistance.TryParse("1 kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Kiloohm, parsed.Unit); - } - - { - Assert.True(ElectricResistance.TryParse("1 µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Microohm, parsed.Unit); - } - - { - Assert.True(ElectricResistance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Nanoohm, parsed.Unit); - } - - { - Assert.True(ElectricResistance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); - Assert.Equal(ElectricResistanceUnit.Ohm, parsed.Unit); - } - - { - Assert.True(ElectricResistance.TryParse("1 TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Teraohm, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricResistance.TryParse(quantityString, out ElectricResistance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -544,6 +476,34 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricResistanceUnit.Gigaohm, "GΩ")] + [InlineData("en-US", ElectricResistanceUnit.Kiloohm, "kΩ")] + [InlineData("en-US", ElectricResistanceUnit.Megaohm, "MΩ")] + [InlineData("en-US", ElectricResistanceUnit.Microohm, "µΩ")] + [InlineData("en-US", ElectricResistanceUnit.Milliohm, "mΩ")] + [InlineData("en-US", ElectricResistanceUnit.Nanoohm, "nΩ")] + [InlineData("en-US", ElectricResistanceUnit.Ohm, "Ω")] + [InlineData("en-US", ElectricResistanceUnit.Teraohm, "TΩ")] + public void GetAbbreviationForCulture(string culture, ElectricResistanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricResistance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricResistance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricResistance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricResistanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 7006d4064f..49ad4a8526 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -348,172 +348,50 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 kΩ·m", ElectricResistivityUnit.KiloohmMeter, 4.2)] + [InlineData("en-US", "4.2 MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 MΩ·m", ElectricResistivityUnit.MegaohmMeter, 4.2)] + [InlineData("en-US", "4.2 µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 µΩ·m", ElectricResistivityUnit.MicroohmMeter, 4.2)] + [InlineData("en-US", "4.2 mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 mΩ·m", ElectricResistivityUnit.MilliohmMeter, 4.2)] + [InlineData("en-US", "4.2 nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 nΩ·m", ElectricResistivityUnit.NanoohmMeter, 4.2)] + [InlineData("en-US", "4.2 Ω·cm", ElectricResistivityUnit.OhmCentimeter, 4.2)] + [InlineData("en-US", "4.2 Ω·m", ElectricResistivityUnit.OhmMeter, 4.2)] + [InlineData("en-US", "4.2 pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 pΩ·m", ElectricResistivityUnit.PicoohmMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricResistivityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricResistivity.Parse("1 kΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloohmsCentimeter, KiloohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.KiloohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 kΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloohmMeters, KiloohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.KiloohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 MΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaohmsCentimeter, MegaohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.MegaohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 MΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaohmMeters, MegaohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MegaohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 µΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicroohmsCentimeter, MicroohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.MicroohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 µΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicroohmMeters, MicroohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MicroohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 mΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliohmsCentimeter, MilliohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.MilliohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 mΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliohmMeters, MilliohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MilliohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 nΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanoohmsCentimeter, NanoohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.NanoohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 nΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanoohmMeters, NanoohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.NanoohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 Ω·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OhmsCentimeter, OhmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.OhmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 Ω·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OhmMeters, OhmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.OhmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 pΩ·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicoohmsCentimeter, PicoohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.PicoohmCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricResistivity.Parse("1 pΩ·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicoohmMeters, PicoohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.PicoohmMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricResistivity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 kΩ·m", ElectricResistivityUnit.KiloohmMeter, 4.2)] + [InlineData("en-US", "4.2 MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 MΩ·m", ElectricResistivityUnit.MegaohmMeter, 4.2)] + [InlineData("en-US", "4.2 µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 µΩ·m", ElectricResistivityUnit.MicroohmMeter, 4.2)] + [InlineData("en-US", "4.2 mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 mΩ·m", ElectricResistivityUnit.MilliohmMeter, 4.2)] + [InlineData("en-US", "4.2 nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 nΩ·m", ElectricResistivityUnit.NanoohmMeter, 4.2)] + [InlineData("en-US", "4.2 Ω·cm", ElectricResistivityUnit.OhmCentimeter, 4.2)] + [InlineData("en-US", "4.2 Ω·m", ElectricResistivityUnit.OhmMeter, 4.2)] + [InlineData("en-US", "4.2 pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter, 4.2)] + [InlineData("en-US", "4.2 pΩ·m", ElectricResistivityUnit.PicoohmMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricResistivityUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricResistivity.TryParse("1 kΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloohmsCentimeter, KiloohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.KiloohmCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 kΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloohmMeters, KiloohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.KiloohmMeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 µΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicroohmsCentimeter, MicroohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.MicroohmCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 µΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicroohmMeters, MicroohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MicroohmMeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 nΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanoohmsCentimeter, NanoohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.NanoohmCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 nΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanoohmMeters, NanoohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.NanoohmMeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 Ω·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OhmsCentimeter, OhmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.OhmCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 Ω·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OhmMeters, OhmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.OhmMeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 pΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicoohmsCentimeter, PicoohmsCentimeterTolerance); - Assert.Equal(ElectricResistivityUnit.PicoohmCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricResistivity.TryParse("1 pΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicoohmMeters, PicoohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.PicoohmMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricResistivity.TryParse(quantityString, out ElectricResistivity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -694,6 +572,40 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricResistivityUnit.KiloohmCentimeter, "kΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.KiloohmMeter, "kΩ·m")] + [InlineData("en-US", ElectricResistivityUnit.MegaohmCentimeter, "MΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.MegaohmMeter, "MΩ·m")] + [InlineData("en-US", ElectricResistivityUnit.MicroohmCentimeter, "µΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.MicroohmMeter, "µΩ·m")] + [InlineData("en-US", ElectricResistivityUnit.MilliohmCentimeter, "mΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.MilliohmMeter, "mΩ·m")] + [InlineData("en-US", ElectricResistivityUnit.NanoohmCentimeter, "nΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.NanoohmMeter, "nΩ·m")] + [InlineData("en-US", ElectricResistivityUnit.OhmCentimeter, "Ω·cm")] + [InlineData("en-US", ElectricResistivityUnit.OhmMeter, "Ω·m")] + [InlineData("en-US", ElectricResistivityUnit.PicoohmCentimeter, "pΩ·cm")] + [InlineData("en-US", ElectricResistivityUnit.PicoohmMeter, "pΩ·m")] + public void GetAbbreviationForCulture(string culture, ElectricResistivityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricResistivity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricResistivity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricResistivity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricResistivityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 7eca784170..ddd60bf0a5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, ElectricSurfaceChargeDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricSurfaceChargeDensity.Parse("1 C/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareCentimeter, CoulombsPerSquareCentimeterTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSurfaceChargeDensity.Parse("1 C/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareInch, CoulombsPerSquareInchTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSurfaceChargeDensity.Parse("1 C/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareMeter, CoulombsPerSquareMeterTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricSurfaceChargeDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, ElectricSurfaceChargeDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricSurfaceChargeDensity.TryParse("1 C/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareCentimeter, CoulombsPerSquareCentimeterTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(ElectricSurfaceChargeDensity.TryParse("1 C/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareInch, CoulombsPerSquareInchTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, parsed.Unit); - } - - { - Assert.True(ElectricSurfaceChargeDensity.TryParse("1 C/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CoulombsPerSquareMeter, CoulombsPerSquareMeterTolerance); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricSurfaceChargeDensity.TryParse(quantityString, out ElectricSurfaceChargeDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, "C/cm²")] + [InlineData("en-US", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, "C/in²")] + [InlineData("en-US", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, "C/m²")] + public void GetAbbreviationForCulture(string culture, ElectricSurfaceChargeDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricSurfaceChargeDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricSurfaceChargeDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricSurfaceChargeDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricSurfaceChargeDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs index dc5c5de9ec..f89b2edaa4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs @@ -360,198 +360,54 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricSusceptanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricSusceptanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricSusceptanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricSusceptanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricSusceptanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricSusceptanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricSusceptanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricSusceptanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricSusceptanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricSusceptanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricSusceptanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricSusceptanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricSusceptanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricSusceptanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricSusceptanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricSusceptanceUnit.Terasiemens, 4.2)] + public void Parse(string culture, string quantityString, ElectricSusceptanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ElectricSusceptance.Parse("1 G℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 k℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 M℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Megamho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Megasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Mho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 µ℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Micromho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 m℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Millimho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Millisiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 n℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Siemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 T℧", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Teramho, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricSusceptance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ElectricSusceptance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 G℧", ElectricSusceptanceUnit.Gigamho, 4.2)] + [InlineData("en-US", "4.2 GS", ElectricSusceptanceUnit.Gigasiemens, 4.2)] + [InlineData("en-US", "4.2 k℧", ElectricSusceptanceUnit.Kilomho, 4.2)] + [InlineData("en-US", "4.2 kS", ElectricSusceptanceUnit.Kilosiemens, 4.2)] + [InlineData("en-US", "4.2 M℧", ElectricSusceptanceUnit.Megamho, 4.2)] + [InlineData("en-US", "4.2 MS", ElectricSusceptanceUnit.Megasiemens, 4.2)] + [InlineData("en-US", "4.2 ℧", ElectricSusceptanceUnit.Mho, 4.2)] + [InlineData("en-US", "4.2 µ℧", ElectricSusceptanceUnit.Micromho, 4.2)] + [InlineData("en-US", "4.2 µS", ElectricSusceptanceUnit.Microsiemens, 4.2)] + [InlineData("en-US", "4.2 m℧", ElectricSusceptanceUnit.Millimho, 4.2)] + [InlineData("en-US", "4.2 mS", ElectricSusceptanceUnit.Millisiemens, 4.2)] + [InlineData("en-US", "4.2 n℧", ElectricSusceptanceUnit.Nanomho, 4.2)] + [InlineData("en-US", "4.2 nS", ElectricSusceptanceUnit.Nanosiemens, 4.2)] + [InlineData("en-US", "4.2 S", ElectricSusceptanceUnit.Siemens, 4.2)] + [InlineData("en-US", "4.2 T℧", ElectricSusceptanceUnit.Teramho, 4.2)] + [InlineData("en-US", "4.2 TS", ElectricSusceptanceUnit.Terasiemens, 4.2)] + public void TryParse(string culture, string quantityString, ElectricSusceptanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ElectricSusceptance.TryParse("1 G℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 k℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Mho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 µ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Micromho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 n℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 nS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Siemens, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 T℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); - Assert.Equal(ElectricSusceptanceUnit.Teramho, parsed.Unit); - } - - { - Assert.True(ElectricSusceptance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); - Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ElectricSusceptance.TryParse(quantityString, out ElectricSusceptance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -748,6 +604,42 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Electr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ElectricSusceptanceUnit.Gigamho, "G℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Gigasiemens, "GS")] + [InlineData("en-US", ElectricSusceptanceUnit.Kilomho, "k℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Kilosiemens, "kS")] + [InlineData("en-US", ElectricSusceptanceUnit.Megamho, "M℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Megasiemens, "MS")] + [InlineData("en-US", ElectricSusceptanceUnit.Mho, "℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Micromho, "µ℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Microsiemens, "µS")] + [InlineData("en-US", ElectricSusceptanceUnit.Millimho, "m℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Millisiemens, "mS")] + [InlineData("en-US", ElectricSusceptanceUnit.Nanomho, "n℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Nanosiemens, "nS")] + [InlineData("en-US", ElectricSusceptanceUnit.Siemens, "S")] + [InlineData("en-US", ElectricSusceptanceUnit.Teramho, "T℧")] + [InlineData("en-US", ElectricSusceptanceUnit.Terasiemens, "TS")] + public void GetAbbreviationForCulture(string culture, ElectricSusceptanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ElectricSusceptance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ElectricSusceptance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ElectricSusceptance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ElectricSusceptanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index 6407fa0bf2..7b354de737 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -336,170 +336,46 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 J/m³", EnergyDensityUnit.JoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter, 4.2)] + public void Parse(string culture, string quantityString, EnergyDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = EnergyDensity.Parse("1 GJ/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigajoulesPerCubicMeter, GigajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.GigajoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 GWh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerCubicMeter, GigawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.GigawattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 J/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeter, JoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.JoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 kJ/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeter, KilojoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.KilojoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 kWh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerCubicMeter, KilowattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.KilowattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 MJ/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeter, MegajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.MegajoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 MWh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerCubicMeter, MegawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.MegawattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 PJ/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetajoulesPerCubicMeter, PetajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.PetajoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 PWh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PetawattHoursPerCubicMeter, PetawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.PetawattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 TJ/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerajoulesPerCubicMeter, TerajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.TerajoulePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 TWh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattHoursPerCubicMeter, TerawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.TerawattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyDensity.Parse("1 Wh/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattHoursPerCubicMeter, WattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.WattHourPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = EnergyDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 J/m³", EnergyDensityUnit.JoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter, 4.2)] + public void TryParse(string culture, string quantityString, EnergyDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(EnergyDensity.TryParse("1 GJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigajoulesPerCubicMeter, GigajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.GigajoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 GWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerCubicMeter, GigawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.GigawattHourPerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 J/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeter, JoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.JoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 kJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeter, KilojoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.KilojoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 kWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerCubicMeter, KilowattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.KilowattHourPerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 MJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeter, MegajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.MegajoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 MWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerCubicMeter, MegawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.MegawattHourPerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 PJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetajoulesPerCubicMeter, PetajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.PetajoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 PWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PetawattHoursPerCubicMeter, PetawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.PetawattHourPerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 TJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerajoulesPerCubicMeter, TerajoulesPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.TerajoulePerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 TWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattHoursPerCubicMeter, TerawattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.TerawattHourPerCubicMeter, parsed.Unit); - } - - { - Assert.True(EnergyDensity.TryParse("1 Wh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHoursPerCubicMeter, WattHoursPerCubicMeterTolerance); - Assert.Equal(EnergyDensityUnit.WattHourPerCubicMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(EnergyDensity.TryParse(quantityString, out EnergyDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -664,6 +540,38 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Energy Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", EnergyDensityUnit.GigajoulePerCubicMeter, "GJ/m³")] + [InlineData("en-US", EnergyDensityUnit.GigawattHourPerCubicMeter, "GWh/m³")] + [InlineData("en-US", EnergyDensityUnit.JoulePerCubicMeter, "J/m³")] + [InlineData("en-US", EnergyDensityUnit.KilojoulePerCubicMeter, "kJ/m³")] + [InlineData("en-US", EnergyDensityUnit.KilowattHourPerCubicMeter, "kWh/m³")] + [InlineData("en-US", EnergyDensityUnit.MegajoulePerCubicMeter, "MJ/m³")] + [InlineData("en-US", EnergyDensityUnit.MegawattHourPerCubicMeter, "MWh/m³")] + [InlineData("en-US", EnergyDensityUnit.PetajoulePerCubicMeter, "PJ/m³")] + [InlineData("en-US", EnergyDensityUnit.PetawattHourPerCubicMeter, "PWh/m³")] + [InlineData("en-US", EnergyDensityUnit.TerajoulePerCubicMeter, "TJ/m³")] + [InlineData("en-US", EnergyDensityUnit.TerawattHourPerCubicMeter, "TWh/m³")] + [InlineData("en-US", EnergyDensityUnit.WattHourPerCubicMeter, "Wh/m³")] + public void GetAbbreviationForCulture(string culture, EnergyDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = EnergyDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(EnergyDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = EnergyDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(EnergyDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index 3f35fbca3f..a3542e93ad 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -504,795 +504,144 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 BTU", EnergyUnit.BritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 cal", EnergyUnit.Calorie, 4.2)] + [InlineData("en-US", "4.2 Dth (E.C.)", EnergyUnit.DecathermEc, 4.2)] + [InlineData("en-US", "4.2 Dth (imp.)", EnergyUnit.DecathermImperial, 4.2)] + [InlineData("en-US", "4.2 Dth (U.S.)", EnergyUnit.DecathermUs, 4.2)] + [InlineData("en-US", "4.2 eV", EnergyUnit.ElectronVolt, 4.2)] + [InlineData("en-US", "4.2 erg", EnergyUnit.Erg, 4.2)] + [InlineData("en-US", "4.2 ft·lb", EnergyUnit.FootPound, 4.2)] + [InlineData("en-US", "4.2 GBTU", EnergyUnit.GigabritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 GeV", EnergyUnit.GigaelectronVolt, 4.2)] + [InlineData("en-US", "4.2 GJ", EnergyUnit.Gigajoule, 4.2)] + [InlineData("en-US", "4.2 GWd", EnergyUnit.GigawattDay, 4.2)] + [InlineData("en-US", "4.2 GWh", EnergyUnit.GigawattHour, 4.2)] + [InlineData("en-US", "4.2 hp·h", EnergyUnit.HorsepowerHour, 4.2)] + [InlineData("en-US", "4.2 J", EnergyUnit.Joule, 4.2)] + [InlineData("en-US", "4.2 kBTU", EnergyUnit.KilobritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 kcal", EnergyUnit.Kilocalorie, 4.2)] + [InlineData("en-US", "4.2 keV", EnergyUnit.KiloelectronVolt, 4.2)] + [InlineData("en-US", "4.2 kJ", EnergyUnit.Kilojoule, 4.2)] + [InlineData("en-US", "4.2 kWd", EnergyUnit.KilowattDay, 4.2)] + [InlineData("en-US", "4.2 kWh", EnergyUnit.KilowattHour, 4.2)] + [InlineData("en-US", "4.2 MBTU", EnergyUnit.MegabritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 Mcal", EnergyUnit.Megacalorie, 4.2)] + [InlineData("en-US", "4.2 MeV", EnergyUnit.MegaelectronVolt, 4.2)] + [InlineData("en-US", "4.2 MJ", EnergyUnit.Megajoule, 4.2)] + [InlineData("en-US", "4.2 MWd", EnergyUnit.MegawattDay, 4.2)] + [InlineData("en-US", "4.2 MWh", EnergyUnit.MegawattHour, 4.2)] + [InlineData("en-US", "4.2 µJ", EnergyUnit.Microjoule, 4.2)] + [InlineData("en-US", "4.2 mJ", EnergyUnit.Millijoule, 4.2)] + [InlineData("en-US", "4.2 nJ", EnergyUnit.Nanojoule, 4.2)] + [InlineData("en-US", "4.2 PJ", EnergyUnit.Petajoule, 4.2)] + [InlineData("en-US", "4.2 TeV", EnergyUnit.TeraelectronVolt, 4.2)] + [InlineData("en-US", "4.2 TJ", EnergyUnit.Terajoule, 4.2)] + [InlineData("en-US", "4.2 TWd", EnergyUnit.TerawattDay, 4.2)] + [InlineData("en-US", "4.2 TWh", EnergyUnit.TerawattHour, 4.2)] + [InlineData("en-US", "4.2 th (E.C.)", EnergyUnit.ThermEc, 4.2)] + [InlineData("en-US", "4.2 th (imp.)", EnergyUnit.ThermImperial, 4.2)] + [InlineData("en-US", "4.2 th (U.S.)", EnergyUnit.ThermUs, 4.2)] + [InlineData("en-US", "4.2 Wd", EnergyUnit.WattDay, 4.2)] + [InlineData("en-US", "4.2 Wh", EnergyUnit.WattHour, 4.2)] + [InlineData("ru-RU", "4,2 Европейский декатерм", EnergyUnit.DecathermEc, 4.2)] + [InlineData("ru-RU", "4,2 Английский декатерм", EnergyUnit.DecathermImperial, 4.2)] + [InlineData("ru-RU", "4,2 Американский декатерм", EnergyUnit.DecathermUs, 4.2)] + [InlineData("ru-RU", "4,2 эВ", EnergyUnit.ElectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ГэВ", EnergyUnit.GigaelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ГВт/д", EnergyUnit.GigawattDay, 4.2)] + [InlineData("ru-RU", "4,2 ГВт/ч", EnergyUnit.GigawattHour, 4.2)] + [InlineData("ru-RU", "4,2 кэВ", EnergyUnit.KiloelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 кВт/д", EnergyUnit.KilowattDay, 4.2)] + [InlineData("ru-RU", "4,2 кВт/ч", EnergyUnit.KilowattHour, 4.2)] + [InlineData("ru-RU", "4,2 МэВ", EnergyUnit.MegaelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 МВт/д", EnergyUnit.MegawattDay, 4.2)] + [InlineData("ru-RU", "4,2 МВт/ч", EnergyUnit.MegawattHour, 4.2)] + [InlineData("ru-RU", "4,2 ТэВ", EnergyUnit.TeraelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ТВт/д", EnergyUnit.TerawattDay, 4.2)] + [InlineData("ru-RU", "4,2 ТВт/ч", EnergyUnit.TerawattHour, 4.2)] + [InlineData("ru-RU", "4,2 Европейский терм", EnergyUnit.ThermEc, 4.2)] + [InlineData("ru-RU", "4,2 Английский терм", EnergyUnit.ThermImperial, 4.2)] + [InlineData("ru-RU", "4,2 Американский терм", EnergyUnit.ThermUs, 4.2)] + [InlineData("ru-RU", "4,2 Вт/д", EnergyUnit.WattDay, 4.2)] + [InlineData("ru-RU", "4,2 Вт/ч", EnergyUnit.WattHour, 4.2)] + public void Parse(string culture, string quantityString, EnergyUnit expectedUnit, double expectedValue) { - try - { - var parsed = Energy.Parse("1 BTU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnits, BritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.BritishThermalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 cal", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Calories, CaloriesTolerance); - Assert.Equal(EnergyUnit.Calorie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Dth (E.C.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecathermsEc, DecathermsEcTolerance); - Assert.Equal(EnergyUnit.DecathermEc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Европейский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecathermsEc, DecathermsEcTolerance); - Assert.Equal(EnergyUnit.DecathermEc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Dth (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecathermsImperial, DecathermsImperialTolerance); - Assert.Equal(EnergyUnit.DecathermImperial, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Английский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecathermsImperial, DecathermsImperialTolerance); - Assert.Equal(EnergyUnit.DecathermImperial, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Dth (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecathermsUs, DecathermsUsTolerance); - Assert.Equal(EnergyUnit.DecathermUs, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Американский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecathermsUs, DecathermsUsTolerance); - Assert.Equal(EnergyUnit.DecathermUs, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 eV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ElectronVolts, ElectronVoltsTolerance); - Assert.Equal(EnergyUnit.ElectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 эВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ElectronVolts, ElectronVoltsTolerance); - Assert.Equal(EnergyUnit.ElectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 erg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Ergs, ErgsTolerance); - Assert.Equal(EnergyUnit.Erg, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ft·lb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FootPounds, FootPoundsTolerance); - Assert.Equal(EnergyUnit.FootPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 GBTU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigabritishThermalUnits, GigabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.GigabritishThermalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 GeV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigaelectronVolts, GigaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ГэВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GigaelectronVolts, GigaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 GJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigajoules, GigajoulesTolerance); - Assert.Equal(EnergyUnit.Gigajoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 GWd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattDays, GigawattDaysTolerance); - Assert.Equal(EnergyUnit.GigawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ГВт/д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GigawattDays, GigawattDaysTolerance); - Assert.Equal(EnergyUnit.GigawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 GWh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHours, GigawattHoursTolerance); - Assert.Equal(EnergyUnit.GigawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ГВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GigawattHours, GigawattHoursTolerance); - Assert.Equal(EnergyUnit.GigawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 hp·h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HorsepowerHours, HorsepowerHoursTolerance); - Assert.Equal(EnergyUnit.HorsepowerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 J", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Joules, JoulesTolerance); - Assert.Equal(EnergyUnit.Joule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 kBTU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnits, KilobritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.KilobritishThermalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 kcal", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilocalories, KilocaloriesTolerance); - Assert.Equal(EnergyUnit.Kilocalorie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 keV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloelectronVolts, KiloelectronVoltsTolerance); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 кэВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KiloelectronVolts, KiloelectronVoltsTolerance); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 kJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilojoules, KilojoulesTolerance); - Assert.Equal(EnergyUnit.Kilojoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 kWd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattDays, KilowattDaysTolerance); - Assert.Equal(EnergyUnit.KilowattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 кВт/д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilowattDays, KilowattDaysTolerance); - Assert.Equal(EnergyUnit.KilowattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 kWh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattHours, KilowattHoursTolerance); - Assert.Equal(EnergyUnit.KilowattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 кВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilowattHours, KilowattHoursTolerance); - Assert.Equal(EnergyUnit.KilowattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 MBTU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnits, MegabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.MegabritishThermalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Mcal", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megacalories, MegacaloriesTolerance); - Assert.Equal(EnergyUnit.Megacalorie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 MeV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaelectronVolts, MegaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 МэВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegaelectronVolts, MegaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 MJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megajoules, MegajoulesTolerance); - Assert.Equal(EnergyUnit.Megajoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 MWd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattDays, MegawattDaysTolerance); - Assert.Equal(EnergyUnit.MegawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 МВт/д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegawattDays, MegawattDaysTolerance); - Assert.Equal(EnergyUnit.MegawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 MWh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHours, MegawattHoursTolerance); - Assert.Equal(EnergyUnit.MegawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 МВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegawattHours, MegawattHoursTolerance); - Assert.Equal(EnergyUnit.MegawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 µJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microjoules, MicrojoulesTolerance); - Assert.Equal(EnergyUnit.Microjoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 mJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millijoules, MillijoulesTolerance); - Assert.Equal(EnergyUnit.Millijoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 nJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanojoules, NanojoulesTolerance); - Assert.Equal(EnergyUnit.Nanojoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 PJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petajoules, PetajoulesTolerance); - Assert.Equal(EnergyUnit.Petajoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 TeV", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TeraelectronVolts, TeraelectronVoltsTolerance); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ТэВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TeraelectronVolts, TeraelectronVoltsTolerance); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 TJ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terajoules, TerajoulesTolerance); - Assert.Equal(EnergyUnit.Terajoule, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 TWd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattDays, TerawattDaysTolerance); - Assert.Equal(EnergyUnit.TerawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ТВт/д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TerawattDays, TerawattDaysTolerance); - Assert.Equal(EnergyUnit.TerawattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 TWh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattHours, TerawattHoursTolerance); - Assert.Equal(EnergyUnit.TerawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 ТВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TerawattHours, TerawattHoursTolerance); - Assert.Equal(EnergyUnit.TerawattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 th (E.C.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ThermsEc, ThermsEcTolerance); - Assert.Equal(EnergyUnit.ThermEc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Европейский терм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ThermsEc, ThermsEcTolerance); - Assert.Equal(EnergyUnit.ThermEc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 th (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ThermsImperial, ThermsImperialTolerance); - Assert.Equal(EnergyUnit.ThermImperial, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Английский терм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ThermsImperial, ThermsImperialTolerance); - Assert.Equal(EnergyUnit.ThermImperial, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 th (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ThermsUs, ThermsUsTolerance); - Assert.Equal(EnergyUnit.ThermUs, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Американский терм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ThermsUs, ThermsUsTolerance); - Assert.Equal(EnergyUnit.ThermUs, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Wd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattDays, WattDaysTolerance); - Assert.Equal(EnergyUnit.WattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Вт/д", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.WattDays, WattDaysTolerance); - Assert.Equal(EnergyUnit.WattDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Wh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattHours, WattHoursTolerance); - Assert.Equal(EnergyUnit.WattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Energy.Parse("1 Вт/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.WattHours, WattHoursTolerance); - Assert.Equal(EnergyUnit.WattHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Energy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 BTU", EnergyUnit.BritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 cal", EnergyUnit.Calorie, 4.2)] + [InlineData("en-US", "4.2 Dth (E.C.)", EnergyUnit.DecathermEc, 4.2)] + [InlineData("en-US", "4.2 Dth (imp.)", EnergyUnit.DecathermImperial, 4.2)] + [InlineData("en-US", "4.2 Dth (U.S.)", EnergyUnit.DecathermUs, 4.2)] + [InlineData("en-US", "4.2 eV", EnergyUnit.ElectronVolt, 4.2)] + [InlineData("en-US", "4.2 erg", EnergyUnit.Erg, 4.2)] + [InlineData("en-US", "4.2 ft·lb", EnergyUnit.FootPound, 4.2)] + [InlineData("en-US", "4.2 GBTU", EnergyUnit.GigabritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 GeV", EnergyUnit.GigaelectronVolt, 4.2)] + [InlineData("en-US", "4.2 GJ", EnergyUnit.Gigajoule, 4.2)] + [InlineData("en-US", "4.2 GWd", EnergyUnit.GigawattDay, 4.2)] + [InlineData("en-US", "4.2 GWh", EnergyUnit.GigawattHour, 4.2)] + [InlineData("en-US", "4.2 hp·h", EnergyUnit.HorsepowerHour, 4.2)] + [InlineData("en-US", "4.2 J", EnergyUnit.Joule, 4.2)] + [InlineData("en-US", "4.2 kBTU", EnergyUnit.KilobritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 kcal", EnergyUnit.Kilocalorie, 4.2)] + [InlineData("en-US", "4.2 keV", EnergyUnit.KiloelectronVolt, 4.2)] + [InlineData("en-US", "4.2 kJ", EnergyUnit.Kilojoule, 4.2)] + [InlineData("en-US", "4.2 kWd", EnergyUnit.KilowattDay, 4.2)] + [InlineData("en-US", "4.2 kWh", EnergyUnit.KilowattHour, 4.2)] + [InlineData("en-US", "4.2 MBTU", EnergyUnit.MegabritishThermalUnit, 4.2)] + [InlineData("en-US", "4.2 Mcal", EnergyUnit.Megacalorie, 4.2)] + [InlineData("en-US", "4.2 MeV", EnergyUnit.MegaelectronVolt, 4.2)] + [InlineData("en-US", "4.2 MJ", EnergyUnit.Megajoule, 4.2)] + [InlineData("en-US", "4.2 MWd", EnergyUnit.MegawattDay, 4.2)] + [InlineData("en-US", "4.2 MWh", EnergyUnit.MegawattHour, 4.2)] + [InlineData("en-US", "4.2 µJ", EnergyUnit.Microjoule, 4.2)] + [InlineData("en-US", "4.2 mJ", EnergyUnit.Millijoule, 4.2)] + [InlineData("en-US", "4.2 nJ", EnergyUnit.Nanojoule, 4.2)] + [InlineData("en-US", "4.2 PJ", EnergyUnit.Petajoule, 4.2)] + [InlineData("en-US", "4.2 TeV", EnergyUnit.TeraelectronVolt, 4.2)] + [InlineData("en-US", "4.2 TJ", EnergyUnit.Terajoule, 4.2)] + [InlineData("en-US", "4.2 TWd", EnergyUnit.TerawattDay, 4.2)] + [InlineData("en-US", "4.2 TWh", EnergyUnit.TerawattHour, 4.2)] + [InlineData("en-US", "4.2 th (E.C.)", EnergyUnit.ThermEc, 4.2)] + [InlineData("en-US", "4.2 th (imp.)", EnergyUnit.ThermImperial, 4.2)] + [InlineData("en-US", "4.2 th (U.S.)", EnergyUnit.ThermUs, 4.2)] + [InlineData("en-US", "4.2 Wd", EnergyUnit.WattDay, 4.2)] + [InlineData("en-US", "4.2 Wh", EnergyUnit.WattHour, 4.2)] + [InlineData("ru-RU", "4,2 Европейский декатерм", EnergyUnit.DecathermEc, 4.2)] + [InlineData("ru-RU", "4,2 Английский декатерм", EnergyUnit.DecathermImperial, 4.2)] + [InlineData("ru-RU", "4,2 Американский декатерм", EnergyUnit.DecathermUs, 4.2)] + [InlineData("ru-RU", "4,2 эВ", EnergyUnit.ElectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ГэВ", EnergyUnit.GigaelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ГВт/д", EnergyUnit.GigawattDay, 4.2)] + [InlineData("ru-RU", "4,2 ГВт/ч", EnergyUnit.GigawattHour, 4.2)] + [InlineData("ru-RU", "4,2 кэВ", EnergyUnit.KiloelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 кВт/д", EnergyUnit.KilowattDay, 4.2)] + [InlineData("ru-RU", "4,2 кВт/ч", EnergyUnit.KilowattHour, 4.2)] + [InlineData("ru-RU", "4,2 МэВ", EnergyUnit.MegaelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 МВт/д", EnergyUnit.MegawattDay, 4.2)] + [InlineData("ru-RU", "4,2 МВт/ч", EnergyUnit.MegawattHour, 4.2)] + [InlineData("ru-RU", "4,2 ТэВ", EnergyUnit.TeraelectronVolt, 4.2)] + [InlineData("ru-RU", "4,2 ТВт/д", EnergyUnit.TerawattDay, 4.2)] + [InlineData("ru-RU", "4,2 ТВт/ч", EnergyUnit.TerawattHour, 4.2)] + [InlineData("ru-RU", "4,2 Европейский терм", EnergyUnit.ThermEc, 4.2)] + [InlineData("ru-RU", "4,2 Английский терм", EnergyUnit.ThermImperial, 4.2)] + [InlineData("ru-RU", "4,2 Американский терм", EnergyUnit.ThermUs, 4.2)] + [InlineData("ru-RU", "4,2 Вт/д", EnergyUnit.WattDay, 4.2)] + [InlineData("ru-RU", "4,2 Вт/ч", EnergyUnit.WattHour, 4.2)] + public void TryParse(string culture, string quantityString, EnergyUnit expectedUnit, double expectedValue) { - { - Assert.True(Energy.TryParse("1 BTU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnits, BritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.BritishThermalUnit, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 cal", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Calories, CaloriesTolerance); - Assert.Equal(EnergyUnit.Calorie, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Dth (E.C.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsEc, DecathermsEcTolerance); - Assert.Equal(EnergyUnit.DecathermEc, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Европейский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsEc, DecathermsEcTolerance); - Assert.Equal(EnergyUnit.DecathermEc, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Dth (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsImperial, DecathermsImperialTolerance); - Assert.Equal(EnergyUnit.DecathermImperial, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Английский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsImperial, DecathermsImperialTolerance); - Assert.Equal(EnergyUnit.DecathermImperial, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Dth (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsUs, DecathermsUsTolerance); - Assert.Equal(EnergyUnit.DecathermUs, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Американский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecathermsUs, DecathermsUsTolerance); - Assert.Equal(EnergyUnit.DecathermUs, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 eV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ElectronVolts, ElectronVoltsTolerance); - Assert.Equal(EnergyUnit.ElectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 эВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ElectronVolts, ElectronVoltsTolerance); - Assert.Equal(EnergyUnit.ElectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 erg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ergs, ErgsTolerance); - Assert.Equal(EnergyUnit.Erg, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ft·lb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FootPounds, FootPoundsTolerance); - Assert.Equal(EnergyUnit.FootPound, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 GBTU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigabritishThermalUnits, GigabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.GigabritishThermalUnit, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 GeV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigaelectronVolts, GigaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ГэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigaelectronVolts, GigaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 GJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigajoules, GigajoulesTolerance); - Assert.Equal(EnergyUnit.Gigajoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 GWd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattDays, GigawattDaysTolerance); - Assert.Equal(EnergyUnit.GigawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ГВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattDays, GigawattDaysTolerance); - Assert.Equal(EnergyUnit.GigawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 GWh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHours, GigawattHoursTolerance); - Assert.Equal(EnergyUnit.GigawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ГВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHours, GigawattHoursTolerance); - Assert.Equal(EnergyUnit.GigawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 hp·h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HorsepowerHours, HorsepowerHoursTolerance); - Assert.Equal(EnergyUnit.HorsepowerHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 J", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Joules, JoulesTolerance); - Assert.Equal(EnergyUnit.Joule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 kBTU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnits, KilobritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.KilobritishThermalUnit, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 kcal", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilocalories, KilocaloriesTolerance); - Assert.Equal(EnergyUnit.Kilocalorie, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 keV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloelectronVolts, KiloelectronVoltsTolerance); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 кэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloelectronVolts, KiloelectronVoltsTolerance); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 kJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilojoules, KilojoulesTolerance); - Assert.Equal(EnergyUnit.Kilojoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 kWd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattDays, KilowattDaysTolerance); - Assert.Equal(EnergyUnit.KilowattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 кВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattDays, KilowattDaysTolerance); - Assert.Equal(EnergyUnit.KilowattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 kWh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHours, KilowattHoursTolerance); - Assert.Equal(EnergyUnit.KilowattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 кВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHours, KilowattHoursTolerance); - Assert.Equal(EnergyUnit.KilowattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 MBTU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnits, MegabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.MegabritishThermalUnit, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Mcal", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megacalories, MegacaloriesTolerance); - Assert.Equal(EnergyUnit.Megacalorie, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 MeV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaelectronVolts, MegaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 МэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaelectronVolts, MegaelectronVoltsTolerance); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 MWd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattDays, MegawattDaysTolerance); - Assert.Equal(EnergyUnit.MegawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 МВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattDays, MegawattDaysTolerance); - Assert.Equal(EnergyUnit.MegawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 MWh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattHours, MegawattHoursTolerance); - Assert.Equal(EnergyUnit.MegawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 МВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattHours, MegawattHoursTolerance); - Assert.Equal(EnergyUnit.MegawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 µJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microjoules, MicrojoulesTolerance); - Assert.Equal(EnergyUnit.Microjoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 nJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanojoules, NanojoulesTolerance); - Assert.Equal(EnergyUnit.Nanojoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 PJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Petajoules, PetajoulesTolerance); - Assert.Equal(EnergyUnit.Petajoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 TeV", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TeraelectronVolts, TeraelectronVoltsTolerance); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ТэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TeraelectronVolts, TeraelectronVoltsTolerance); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 TJ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terajoules, TerajoulesTolerance); - Assert.Equal(EnergyUnit.Terajoule, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 TWd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattDays, TerawattDaysTolerance); - Assert.Equal(EnergyUnit.TerawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ТВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattDays, TerawattDaysTolerance); - Assert.Equal(EnergyUnit.TerawattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 TWh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattHours, TerawattHoursTolerance); - Assert.Equal(EnergyUnit.TerawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 ТВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattHours, TerawattHoursTolerance); - Assert.Equal(EnergyUnit.TerawattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 th (E.C.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsEc, ThermsEcTolerance); - Assert.Equal(EnergyUnit.ThermEc, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Европейский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsEc, ThermsEcTolerance); - Assert.Equal(EnergyUnit.ThermEc, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 th (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsImperial, ThermsImperialTolerance); - Assert.Equal(EnergyUnit.ThermImperial, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Английский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsImperial, ThermsImperialTolerance); - Assert.Equal(EnergyUnit.ThermImperial, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 th (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsUs, ThermsUsTolerance); - Assert.Equal(EnergyUnit.ThermUs, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Американский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ThermsUs, ThermsUsTolerance); - Assert.Equal(EnergyUnit.ThermUs, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Wd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattDays, WattDaysTolerance); - Assert.Equal(EnergyUnit.WattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Вт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattDays, WattDaysTolerance); - Assert.Equal(EnergyUnit.WattDay, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Wh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHours, WattHoursTolerance); - Assert.Equal(EnergyUnit.WattHour, parsed.Unit); - } - - { - Assert.True(Energy.TryParse("1 Вт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHours, WattHoursTolerance); - Assert.Equal(EnergyUnit.WattHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Energy.TryParse(quantityString, out Energy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1765,6 +1114,87 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Energy Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", EnergyUnit.BritishThermalUnit, "BTU")] + [InlineData("en-US", EnergyUnit.Calorie, "cal")] + [InlineData("en-US", EnergyUnit.DecathermEc, "Dth (E.C.)")] + [InlineData("en-US", EnergyUnit.DecathermImperial, "Dth (imp.)")] + [InlineData("en-US", EnergyUnit.DecathermUs, "Dth (U.S.)")] + [InlineData("en-US", EnergyUnit.ElectronVolt, "eV")] + [InlineData("en-US", EnergyUnit.Erg, "erg")] + [InlineData("en-US", EnergyUnit.FootPound, "ft·lb")] + [InlineData("en-US", EnergyUnit.GigabritishThermalUnit, "GBTU")] + [InlineData("en-US", EnergyUnit.GigaelectronVolt, "GeV")] + [InlineData("en-US", EnergyUnit.Gigajoule, "GJ")] + [InlineData("en-US", EnergyUnit.GigawattDay, "GWd")] + [InlineData("en-US", EnergyUnit.GigawattHour, "GWh")] + [InlineData("en-US", EnergyUnit.HorsepowerHour, "hp·h")] + [InlineData("en-US", EnergyUnit.Joule, "J")] + [InlineData("en-US", EnergyUnit.KilobritishThermalUnit, "kBTU")] + [InlineData("en-US", EnergyUnit.Kilocalorie, "kcal")] + [InlineData("en-US", EnergyUnit.KiloelectronVolt, "keV")] + [InlineData("en-US", EnergyUnit.Kilojoule, "kJ")] + [InlineData("en-US", EnergyUnit.KilowattDay, "kWd")] + [InlineData("en-US", EnergyUnit.KilowattHour, "kWh")] + [InlineData("en-US", EnergyUnit.MegabritishThermalUnit, "MBTU")] + [InlineData("en-US", EnergyUnit.Megacalorie, "Mcal")] + [InlineData("en-US", EnergyUnit.MegaelectronVolt, "MeV")] + [InlineData("en-US", EnergyUnit.Megajoule, "MJ")] + [InlineData("en-US", EnergyUnit.MegawattDay, "MWd")] + [InlineData("en-US", EnergyUnit.MegawattHour, "MWh")] + [InlineData("en-US", EnergyUnit.Microjoule, "µJ")] + [InlineData("en-US", EnergyUnit.Millijoule, "mJ")] + [InlineData("en-US", EnergyUnit.Nanojoule, "nJ")] + [InlineData("en-US", EnergyUnit.Petajoule, "PJ")] + [InlineData("en-US", EnergyUnit.TeraelectronVolt, "TeV")] + [InlineData("en-US", EnergyUnit.Terajoule, "TJ")] + [InlineData("en-US", EnergyUnit.TerawattDay, "TWd")] + [InlineData("en-US", EnergyUnit.TerawattHour, "TWh")] + [InlineData("en-US", EnergyUnit.ThermEc, "th (E.C.)")] + [InlineData("en-US", EnergyUnit.ThermImperial, "th (imp.)")] + [InlineData("en-US", EnergyUnit.ThermUs, "th (U.S.)")] + [InlineData("en-US", EnergyUnit.WattDay, "Wd")] + [InlineData("en-US", EnergyUnit.WattHour, "Wh")] + [InlineData("ru-RU", EnergyUnit.DecathermEc, "Европейский декатерм")] + [InlineData("ru-RU", EnergyUnit.DecathermImperial, "Английский декатерм")] + [InlineData("ru-RU", EnergyUnit.DecathermUs, "Американский декатерм")] + [InlineData("ru-RU", EnergyUnit.ElectronVolt, "эВ")] + [InlineData("ru-RU", EnergyUnit.GigaelectronVolt, "ГэВ")] + [InlineData("ru-RU", EnergyUnit.GigawattDay, "ГВт/д")] + [InlineData("ru-RU", EnergyUnit.GigawattHour, "ГВт/ч")] + [InlineData("ru-RU", EnergyUnit.KiloelectronVolt, "кэВ")] + [InlineData("ru-RU", EnergyUnit.KilowattDay, "кВт/д")] + [InlineData("ru-RU", EnergyUnit.KilowattHour, "кВт/ч")] + [InlineData("ru-RU", EnergyUnit.MegaelectronVolt, "МэВ")] + [InlineData("ru-RU", EnergyUnit.MegawattDay, "МВт/д")] + [InlineData("ru-RU", EnergyUnit.MegawattHour, "МВт/ч")] + [InlineData("ru-RU", EnergyUnit.TeraelectronVolt, "ТэВ")] + [InlineData("ru-RU", EnergyUnit.TerawattDay, "ТВт/д")] + [InlineData("ru-RU", EnergyUnit.TerawattHour, "ТВт/ч")] + [InlineData("ru-RU", EnergyUnit.ThermEc, "Европейский терм")] + [InlineData("ru-RU", EnergyUnit.ThermImperial, "Английский терм")] + [InlineData("ru-RU", EnergyUnit.ThermUs, "Американский терм")] + [InlineData("ru-RU", EnergyUnit.WattDay, "Вт/д")] + [InlineData("ru-RU", EnergyUnit.WattHour, "Вт/ч")] + public void GetAbbreviationForCulture(string culture, EnergyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Energy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Energy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Energy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(EnergyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index 044a177e43..98a8717cdf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -306,105 +306,36 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cal/K", EntropyUnit.CaloriePerKelvin, 4.2)] + [InlineData("en-US", "4.2 J/°C", EntropyUnit.JoulePerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/K", EntropyUnit.JoulePerKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/K", EntropyUnit.KilocaloriePerKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/°C", EntropyUnit.KilojoulePerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/K", EntropyUnit.KilojoulePerKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/K", EntropyUnit.MegajoulePerKelvin, 4.2)] + public void Parse(string culture, string quantityString, EntropyUnit expectedUnit, double expectedValue) { - try - { - var parsed = Entropy.Parse("1 cal/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CaloriesPerKelvin, CaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.CaloriePerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 J/°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerDegreeCelsius, JoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.JoulePerDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 J/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerKelvin, JoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.JoulePerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 kcal/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerKelvin, KilocaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilocaloriePerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 kJ/°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerDegreeCelsius, KilojoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.KilojoulePerDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 kJ/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKelvin, KilojoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilojoulePerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Entropy.Parse("1 MJ/K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKelvin, MegajoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.MegajoulePerKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Entropy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cal/K", EntropyUnit.CaloriePerKelvin, 4.2)] + [InlineData("en-US", "4.2 J/°C", EntropyUnit.JoulePerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/K", EntropyUnit.JoulePerKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/K", EntropyUnit.KilocaloriePerKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/°C", EntropyUnit.KilojoulePerDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/K", EntropyUnit.KilojoulePerKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/K", EntropyUnit.MegajoulePerKelvin, 4.2)] + public void TryParse(string culture, string quantityString, EntropyUnit expectedUnit, double expectedValue) { - { - Assert.True(Entropy.TryParse("1 cal/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CaloriesPerKelvin, CaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.CaloriePerKelvin, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 J/°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerDegreeCelsius, JoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.JoulePerDegreeCelsius, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 J/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerKelvin, JoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.JoulePerKelvin, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 kcal/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerKelvin, KilocaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilocaloriePerKelvin, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 kJ/°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerDegreeCelsius, KilojoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.KilojoulePerDegreeCelsius, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 kJ/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKelvin, KilojoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilojoulePerKelvin, parsed.Unit); - } - - { - Assert.True(Entropy.TryParse("1 MJ/K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKelvin, MegajoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.MegajoulePerKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Entropy.TryParse(quantityString, out Entropy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -529,6 +460,33 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Entrop Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", EntropyUnit.CaloriePerKelvin, "cal/K")] + [InlineData("en-US", EntropyUnit.JoulePerDegreeCelsius, "J/°C")] + [InlineData("en-US", EntropyUnit.JoulePerKelvin, "J/K")] + [InlineData("en-US", EntropyUnit.KilocaloriePerKelvin, "kcal/K")] + [InlineData("en-US", EntropyUnit.KilojoulePerDegreeCelsius, "kJ/°C")] + [InlineData("en-US", EntropyUnit.KilojoulePerKelvin, "kJ/K")] + [InlineData("en-US", EntropyUnit.MegajoulePerKelvin, "MJ/K")] + public void GetAbbreviationForCulture(string culture, EntropyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Entropy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Entropy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Entropy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(EntropyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FluidResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FluidResistanceTestsBase.g.cs index 2a8956d0bb..85853170ba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FluidResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FluidResistanceTestsBase.g.cs @@ -378,560 +378,106 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 dyn·s/cm⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("en-US", "4.2 dyn·s·cm⁻⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("en-US", "4.2 MPa·s/m³", FluidResistanceUnit.MegapascalSecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/cm³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/m³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/l", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/ml", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/cm³", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/m³", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/l", FluidResistanceUnit.MillimeterMercurySecondPerLiter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/ml", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/cm³", FluidResistanceUnit.PascalMinutePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/m³", FluidResistanceUnit.PascalMinutePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/l", FluidResistanceUnit.PascalMinutePerLiter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/ml", FluidResistanceUnit.PascalMinutePerMilliliter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/cm³", FluidResistanceUnit.PascalSecondPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/m³", FluidResistanceUnit.PascalSecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/l", FluidResistanceUnit.PascalSecondPerLiter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/ml", FluidResistanceUnit.PascalSecondPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 WU", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("en-US", "4.2 HRU", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("ru-RU", "4,2 дин·с/см⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("ru-RU", "4,2 дин·с·см⁻⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("ru-RU", "4,2 МПа·с/м³", FluidResistanceUnit.MegapascalSecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/см³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/м³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/л", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/мл", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/см³", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/м³", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/л", FluidResistanceUnit.MillimeterMercurySecondPerLiter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/мл", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/см³", FluidResistanceUnit.PascalMinutePerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/м³", FluidResistanceUnit.PascalMinutePerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/л", FluidResistanceUnit.PascalMinutePerLiter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/мл", FluidResistanceUnit.PascalMinutePerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/см³", FluidResistanceUnit.PascalSecondPerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/м³", FluidResistanceUnit.PascalSecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/л", FluidResistanceUnit.PascalSecondPerLiter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/мл", FluidResistanceUnit.PascalSecondPerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 ЕВ", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("ru-RU", "4,2 ЕГС", FluidResistanceUnit.WoodUnit, 4.2)] + public void Parse(string culture, string quantityString, FluidResistanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = FluidResistance.Parse("1 dyn·s/cm⁵", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 dyn·s·cm⁻⁵", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 дин·с/см⁵", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 дин·с·см⁻⁵", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 MPa·s/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapascalSecondsPerCubicMeter, MegapascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MegapascalSecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 МПа·с/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapascalSecondsPerCubicMeter, MegapascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MegapascalSecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·min/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicCentimeter, MillimeterMercuryMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·мин/см³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicCentimeter, MillimeterMercuryMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·min/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicMeter, MillimeterMercuryMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·мин/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicMeter, MillimeterMercuryMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·min/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerLiter, MillimeterMercuryMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·мин/л", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerLiter, MillimeterMercuryMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·min/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerMilliliter, MillimeterMercuryMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·мин/мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerMilliliter, MillimeterMercuryMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·s/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicCentimeter, MillimeterMercurySecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·с/см³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicCentimeter, MillimeterMercurySecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·s/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicMeter, MillimeterMercurySecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·с/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicMeter, MillimeterMercurySecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·s/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerLiter, MillimeterMercurySecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·с/л", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerLiter, MillimeterMercurySecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 mmHg·s/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerMilliliter, MillimeterMercurySecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 мм рт.ст·с/мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerMilliliter, MillimeterMercurySecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·min/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicCentimeter, PascalMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·мин/см³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicCentimeter, PascalMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·min/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicMeter, PascalMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·мин/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicMeter, PascalMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·min/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerLiter, PascalMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·мин/л", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerLiter, PascalMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·min/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerMilliliter, PascalMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·мин/мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerMilliliter, PascalMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·s/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicCentimeter, PascalSecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·с/см³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicCentimeter, PascalSecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·s/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicMeter, PascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·с/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicMeter, PascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·s/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerLiter, PascalSecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·с/л", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerLiter, PascalSecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Pa·s/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerMilliliter, PascalSecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 Па·с/мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerMilliliter, PascalSecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 WU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 HRU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 ЕВ", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FluidResistance.Parse("1 ЕГС", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = FluidResistance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 dyn·s/cm⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("en-US", "4.2 dyn·s·cm⁻⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("en-US", "4.2 MPa·s/m³", FluidResistanceUnit.MegapascalSecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/cm³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/m³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/l", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, 4.2)] + [InlineData("en-US", "4.2 mmHg·min/ml", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/cm³", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/m³", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/l", FluidResistanceUnit.MillimeterMercurySecondPerLiter, 4.2)] + [InlineData("en-US", "4.2 mmHg·s/ml", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/cm³", FluidResistanceUnit.PascalMinutePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/m³", FluidResistanceUnit.PascalMinutePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/l", FluidResistanceUnit.PascalMinutePerLiter, 4.2)] + [InlineData("en-US", "4.2 Pa·min/ml", FluidResistanceUnit.PascalMinutePerMilliliter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/cm³", FluidResistanceUnit.PascalSecondPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/m³", FluidResistanceUnit.PascalSecondPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/l", FluidResistanceUnit.PascalSecondPerLiter, 4.2)] + [InlineData("en-US", "4.2 Pa·s/ml", FluidResistanceUnit.PascalSecondPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 WU", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("en-US", "4.2 HRU", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("ru-RU", "4,2 дин·с/см⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("ru-RU", "4,2 дин·с·см⁻⁵", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, 4.2)] + [InlineData("ru-RU", "4,2 МПа·с/м³", FluidResistanceUnit.MegapascalSecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/см³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/м³", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/л", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·мин/мл", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/см³", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/м³", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/л", FluidResistanceUnit.MillimeterMercurySecondPerLiter, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст·с/мл", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/см³", FluidResistanceUnit.PascalMinutePerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/м³", FluidResistanceUnit.PascalMinutePerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/л", FluidResistanceUnit.PascalMinutePerLiter, 4.2)] + [InlineData("ru-RU", "4,2 Па·мин/мл", FluidResistanceUnit.PascalMinutePerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/см³", FluidResistanceUnit.PascalSecondPerCubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/м³", FluidResistanceUnit.PascalSecondPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/л", FluidResistanceUnit.PascalSecondPerLiter, 4.2)] + [InlineData("ru-RU", "4,2 Па·с/мл", FluidResistanceUnit.PascalSecondPerMilliliter, 4.2)] + [InlineData("ru-RU", "4,2 ЕВ", FluidResistanceUnit.WoodUnit, 4.2)] + [InlineData("ru-RU", "4,2 ЕГС", FluidResistanceUnit.WoodUnit, 4.2)] + public void TryParse(string culture, string quantityString, FluidResistanceUnit expectedUnit, double expectedValue) { - { - Assert.True(FluidResistance.TryParse("1 dyn·s/cm⁵", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 dyn·s·cm⁻⁵", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 дин·с/см⁵", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 дин·с·см⁻⁵", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DyneSecondsPerCentimeterToTheFifth, DyneSecondsPerCentimeterToTheFifthTolerance); - Assert.Equal(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 MPa·s/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalSecondsPerCubicMeter, MegapascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MegapascalSecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 МПа·с/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalSecondsPerCubicMeter, MegapascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MegapascalSecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·min/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicCentimeter, MillimeterMercuryMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·мин/см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicCentimeter, MillimeterMercuryMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·min/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicMeter, MillimeterMercuryMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·мин/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerCubicMeter, MillimeterMercuryMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·min/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerLiter, MillimeterMercuryMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·мин/л", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerLiter, MillimeterMercuryMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·min/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerMilliliter, MillimeterMercuryMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·мин/мл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercuryMinutesPerMilliliter, MillimeterMercuryMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·s/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicCentimeter, MillimeterMercurySecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·с/см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicCentimeter, MillimeterMercurySecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·s/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicMeter, MillimeterMercurySecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·с/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerCubicMeter, MillimeterMercurySecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·s/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerLiter, MillimeterMercurySecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·с/л", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerLiter, MillimeterMercurySecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 mmHg·s/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerMilliliter, MillimeterMercurySecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 мм рт.ст·с/мл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimeterMercurySecondsPerMilliliter, MillimeterMercurySecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·min/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicCentimeter, PascalMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·мин/см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicCentimeter, PascalMinutesPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·min/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicMeter, PascalMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·мин/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerCubicMeter, PascalMinutesPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·min/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerLiter, PascalMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·мин/л", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerLiter, PascalMinutesPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·min/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerMilliliter, PascalMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·мин/мл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalMinutesPerMilliliter, PascalMinutesPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalMinutePerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·s/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicCentimeter, PascalSecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·с/см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicCentimeter, PascalSecondsPerCubicCentimeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·s/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicMeter, PascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·с/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerCubicMeter, PascalSecondsPerCubicMeterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerCubicMeter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·s/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerLiter, PascalSecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·с/л", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerLiter, PascalSecondsPerLiterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerLiter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Pa·s/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerMilliliter, PascalSecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 Па·с/мл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalSecondsPerMilliliter, PascalSecondsPerMilliliterTolerance); - Assert.Equal(FluidResistanceUnit.PascalSecondPerMilliliter, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 WU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 HRU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 ЕВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } - - { - Assert.True(FluidResistance.TryParse("1 ЕГС", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WoodUnits, WoodUnitsTolerance); - Assert.Equal(FluidResistanceUnit.WoodUnit, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(FluidResistance.TryParse(quantityString, out FluidResistance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1252,6 +798,64 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, FluidR Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, "dyn·s/cm⁵")] + [InlineData("en-US", FluidResistanceUnit.MegapascalSecondPerCubicMeter, "MPa·s/m³")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, "mmHg·min/cm³")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, "mmHg·min/m³")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, "mmHg·min/l")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, "mmHg·min/ml")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, "mmHg·s/cm³")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, "mmHg·s/m³")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercurySecondPerLiter, "mmHg·s/l")] + [InlineData("en-US", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, "mmHg·s/ml")] + [InlineData("en-US", FluidResistanceUnit.PascalMinutePerCubicCentimeter, "Pa·min/cm³")] + [InlineData("en-US", FluidResistanceUnit.PascalMinutePerCubicMeter, "Pa·min/m³")] + [InlineData("en-US", FluidResistanceUnit.PascalMinutePerLiter, "Pa·min/l")] + [InlineData("en-US", FluidResistanceUnit.PascalMinutePerMilliliter, "Pa·min/ml")] + [InlineData("en-US", FluidResistanceUnit.PascalSecondPerCubicCentimeter, "Pa·s/cm³")] + [InlineData("en-US", FluidResistanceUnit.PascalSecondPerCubicMeter, "Pa·s/m³")] + [InlineData("en-US", FluidResistanceUnit.PascalSecondPerLiter, "Pa·s/l")] + [InlineData("en-US", FluidResistanceUnit.PascalSecondPerMilliliter, "Pa·s/ml")] + [InlineData("en-US", FluidResistanceUnit.WoodUnit, "WU")] + [InlineData("ru-RU", FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, "дин·с/см⁵")] + [InlineData("ru-RU", FluidResistanceUnit.MegapascalSecondPerCubicMeter, "МПа·с/м³")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, "мм рт.ст·мин/см³")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, "мм рт.ст·мин/м³")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercuryMinutePerLiter, "мм рт.ст·мин/л")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, "мм рт.ст·мин/мл")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, "мм рт.ст·с/см³")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, "мм рт.ст·с/м³")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercurySecondPerLiter, "мм рт.ст·с/л")] + [InlineData("ru-RU", FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, "мм рт.ст·с/мл")] + [InlineData("ru-RU", FluidResistanceUnit.PascalMinutePerCubicCentimeter, "Па·мин/см³")] + [InlineData("ru-RU", FluidResistanceUnit.PascalMinutePerCubicMeter, "Па·мин/м³")] + [InlineData("ru-RU", FluidResistanceUnit.PascalMinutePerLiter, "Па·мин/л")] + [InlineData("ru-RU", FluidResistanceUnit.PascalMinutePerMilliliter, "Па·мин/мл")] + [InlineData("ru-RU", FluidResistanceUnit.PascalSecondPerCubicCentimeter, "Па·с/см³")] + [InlineData("ru-RU", FluidResistanceUnit.PascalSecondPerCubicMeter, "Па·с/м³")] + [InlineData("ru-RU", FluidResistanceUnit.PascalSecondPerLiter, "Па·с/л")] + [InlineData("ru-RU", FluidResistanceUnit.PascalSecondPerMilliliter, "Па·с/мл")] + [InlineData("ru-RU", FluidResistanceUnit.WoodUnit, "ЕВ")] + public void GetAbbreviationForCulture(string culture, FluidResistanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = FluidResistance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(FluidResistance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = FluidResistance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(FluidResistanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index 077eb98e69..24b96b1253 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -354,261 +354,60 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cN/s", ForceChangeRateUnit.CentinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 daN/min", ForceChangeRateUnit.DecanewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 daN/s", ForceChangeRateUnit.DecanewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 dN/s", ForceChangeRateUnit.DecinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 kN/min", ForceChangeRateUnit.KilonewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 kN/s", ForceChangeRateUnit.KilonewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 kip/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 k/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 kip/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 k/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 µN/s", ForceChangeRateUnit.MicronewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 mN/s", ForceChangeRateUnit.MillinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 nN/s", ForceChangeRateUnit.NanonewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 N/min", ForceChangeRateUnit.NewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 N/s", ForceChangeRateUnit.NewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 lbf/min", ForceChangeRateUnit.PoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 lbf/s", ForceChangeRateUnit.PoundForcePerSecond, 4.2)] + public void Parse(string culture, string quantityString, ForceChangeRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = ForceChangeRate.Parse("1 cN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerSecond, CentinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.CentinewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 daN/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMinute, DecanewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 daN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerSecond, DecanewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 dN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerSecond, DecinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecinewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kN/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMinute, KilonewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSecond, KilonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kipf/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kip/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 k/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kipf/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 kip/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 k/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 µN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerSecond, MicronewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MicronewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 mN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonsPerSecond, MillinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MillinewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 nN/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerSecond, NanonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NanonewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 N/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMinute, NewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 N/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSecond, NewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 lbf/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerMinute, PoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.PoundForcePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForceChangeRate.Parse("1 lbf/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSecond, PoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.PoundForcePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ForceChangeRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cN/s", ForceChangeRateUnit.CentinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 daN/min", ForceChangeRateUnit.DecanewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 daN/s", ForceChangeRateUnit.DecanewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 dN/s", ForceChangeRateUnit.DecinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 kN/min", ForceChangeRateUnit.KilonewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 kN/s", ForceChangeRateUnit.KilonewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 kip/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 k/min", ForceChangeRateUnit.KilopoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 kip/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 k/s", ForceChangeRateUnit.KilopoundForcePerSecond, 4.2)] + [InlineData("en-US", "4.2 µN/s", ForceChangeRateUnit.MicronewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 mN/s", ForceChangeRateUnit.MillinewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 nN/s", ForceChangeRateUnit.NanonewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 N/min", ForceChangeRateUnit.NewtonPerMinute, 4.2)] + [InlineData("en-US", "4.2 N/s", ForceChangeRateUnit.NewtonPerSecond, 4.2)] + [InlineData("en-US", "4.2 lbf/min", ForceChangeRateUnit.PoundForcePerMinute, 4.2)] + [InlineData("en-US", "4.2 lbf/s", ForceChangeRateUnit.PoundForcePerSecond, 4.2)] + public void TryParse(string culture, string quantityString, ForceChangeRateUnit expectedUnit, double expectedValue) { - { - Assert.True(ForceChangeRate.TryParse("1 cN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerSecond, CentinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.CentinewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 daN/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMinute, DecanewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 daN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerSecond, DecanewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 dN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerSecond, DecinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecinewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kN/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMinute, KilonewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSecond, KilonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kipf/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kip/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 k/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerMinute, KilopoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kipf/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 kip/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 k/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSecond, KilopoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 µN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerSecond, MicronewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MicronewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 mN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillinewtonsPerSecond, MillinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MillinewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 nN/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerSecond, NanonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NanonewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 N/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMinute, NewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 N/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSecond, NewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 lbf/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerMinute, PoundsForcePerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.PoundForcePerMinute, parsed.Unit); - } - - { - Assert.True(ForceChangeRate.TryParse("1 lbf/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSecond, PoundsForcePerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.PoundForcePerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ForceChangeRate.TryParse(quantityString, out ForceChangeRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -829,6 +628,41 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, ForceC Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ForceChangeRateUnit.CentinewtonPerSecond, "cN/s")] + [InlineData("en-US", ForceChangeRateUnit.DecanewtonPerMinute, "daN/min")] + [InlineData("en-US", ForceChangeRateUnit.DecanewtonPerSecond, "daN/s")] + [InlineData("en-US", ForceChangeRateUnit.DecinewtonPerSecond, "dN/s")] + [InlineData("en-US", ForceChangeRateUnit.KilonewtonPerMinute, "kN/min")] + [InlineData("en-US", ForceChangeRateUnit.KilonewtonPerSecond, "kN/s")] + [InlineData("en-US", ForceChangeRateUnit.KilopoundForcePerMinute, "kipf/min")] + [InlineData("en-US", ForceChangeRateUnit.KilopoundForcePerSecond, "kipf/s")] + [InlineData("en-US", ForceChangeRateUnit.MicronewtonPerSecond, "µN/s")] + [InlineData("en-US", ForceChangeRateUnit.MillinewtonPerSecond, "mN/s")] + [InlineData("en-US", ForceChangeRateUnit.NanonewtonPerSecond, "nN/s")] + [InlineData("en-US", ForceChangeRateUnit.NewtonPerMinute, "N/min")] + [InlineData("en-US", ForceChangeRateUnit.NewtonPerSecond, "N/s")] + [InlineData("en-US", ForceChangeRateUnit.PoundForcePerMinute, "lbf/min")] + [InlineData("en-US", ForceChangeRateUnit.PoundForcePerSecond, "lbf/s")] + public void GetAbbreviationForCulture(string culture, ForceChangeRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ForceChangeRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ForceChangeRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ForceChangeRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ForceChangeRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 0792ee12f8..6b8c42cc68 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -492,602 +492,118 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 cN/m", ForcePerLengthUnit.CentinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 daN/m", ForcePerLengthUnit.DecanewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 dN/m", ForcePerLengthUnit.DecinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m", ForcePerLengthUnit.KilogramForcePerMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m", ForcePerLengthUnit.KilonewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 k/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 kipf/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 kip/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 k/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 MN/m", ForcePerLengthUnit.MeganewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 µN/m", ForcePerLengthUnit.MicronewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mN/m", ForcePerLengthUnit.MillinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 nN/m", ForcePerLengthUnit.NanonewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 N/cm", ForcePerLengthUnit.NewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m", ForcePerLengthUnit.NewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm", ForcePerLengthUnit.NewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbf/ft", ForcePerLengthUnit.PoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 lbf/in", ForcePerLengthUnit.PoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 lbf/yd", ForcePerLengthUnit.PoundForcePerYard, 4.2)] + [InlineData("en-US", "4.2 tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m", ForcePerLengthUnit.TonneForcePerMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/м", ForcePerLengthUnit.KilogramForcePerMeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/см", ForcePerLengthUnit.TonneForcePerCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/м", ForcePerLengthUnit.TonneForcePerMeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter, 4.2)] + public void Parse(string culture, string quantityString, ForcePerLengthUnit expectedUnit, double expectedValue) { - try - { - var parsed = ForcePerLength.Parse("1 cN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerCentimeter, CentinewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 cN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerMeter, CentinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 cN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerMillimeter, CentinewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 daN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerCentimeter, DecanewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 daN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMeter, DecanewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 daN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMillimeter, DecanewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 dN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerCentimeter, DecinewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 dN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerMeter, DecinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 dN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerMillimeter, DecinewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kgf/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCentimeter, KilogramsForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 кгс/см", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCentimeter, KilogramsForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kgf/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 кгс/м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kgf/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMillimeter, KilogramsForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 кгс/мм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMillimeter, KilogramsForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCentimeter, KilonewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMeter, KilonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMillimeter, KilonewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kipf/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kip/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 k/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kipf/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 kip/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 k/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 MN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerCentimeter, MeganewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 MN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerMeter, MeganewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 MN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerMillimeter, MeganewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 µN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerCentimeter, MicronewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 µN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerMeter, MicronewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 µN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerMillimeter, MicronewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 mN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonsPerCentimeter, MillinewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 mN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonsPerMeter, MillinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 mN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonsPerMillimeter, MillinewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 nN/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerCentimeter, NanonewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 nN/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerMeter, NanonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 nN/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerMillimeter, NanonewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 N/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCentimeter, NewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 N/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMeter, NewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 N/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMillimeter, NewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 lbf/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerFoot, PoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 lbf/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerInch, PoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 lbf/yd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerYard, PoundsForcePerYardTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 tf/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCentimeter, TonnesForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 тс/см", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCentimeter, TonnesForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 tf/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMeter, TonnesForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 тс/м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMeter, TonnesForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 tf/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMillimeter, TonnesForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ForcePerLength.Parse("1 тс/мм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMillimeter, TonnesForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ForcePerLength.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 cN/m", ForcePerLengthUnit.CentinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 daN/m", ForcePerLengthUnit.DecanewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 dN/m", ForcePerLengthUnit.DecinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m", ForcePerLengthUnit.KilogramForcePerMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m", ForcePerLengthUnit.KilonewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 k/ft", ForcePerLengthUnit.KilopoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 kipf/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 kip/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 k/in", ForcePerLengthUnit.KilopoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 MN/m", ForcePerLengthUnit.MeganewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 µN/m", ForcePerLengthUnit.MicronewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mN/m", ForcePerLengthUnit.MillinewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 nN/m", ForcePerLengthUnit.NanonewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 N/cm", ForcePerLengthUnit.NewtonPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m", ForcePerLengthUnit.NewtonPerMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm", ForcePerLengthUnit.NewtonPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbf/ft", ForcePerLengthUnit.PoundForcePerFoot, 4.2)] + [InlineData("en-US", "4.2 lbf/in", ForcePerLengthUnit.PoundForcePerInch, 4.2)] + [InlineData("en-US", "4.2 lbf/yd", ForcePerLengthUnit.PoundForcePerYard, 4.2)] + [InlineData("en-US", "4.2 tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m", ForcePerLengthUnit.TonneForcePerMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/м", ForcePerLengthUnit.KilogramForcePerMeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/см", ForcePerLengthUnit.TonneForcePerCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/м", ForcePerLengthUnit.TonneForcePerMeter, 4.2)] + [InlineData("ru-RU", "4,2 тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, ForcePerLengthUnit expectedUnit, double expectedValue) { - { - Assert.True(ForcePerLength.TryParse("1 cN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerCentimeter, CentinewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 cN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerMeter, CentinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 cN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonsPerMillimeter, CentinewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 daN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerCentimeter, DecanewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 daN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMeter, DecanewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 daN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonsPerMillimeter, DecanewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 dN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerCentimeter, DecinewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 dN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerMeter, DecinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 dN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonsPerMillimeter, DecinewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kgf/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCentimeter, KilogramsForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 кгс/см", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCentimeter, KilogramsForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kgf/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 кгс/м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kgf/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMillimeter, KilogramsForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 кгс/мм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerMillimeter, KilogramsForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCentimeter, KilonewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMeter, KilonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerMillimeter, KilonewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kipf/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kip/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 k/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerFoot, KilopoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kipf/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 kip/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 k/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerInch, KilopoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 µN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerCentimeter, MicronewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 µN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerMeter, MicronewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 µN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonsPerMillimeter, MicronewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 nN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerCentimeter, NanonewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 nN/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerMeter, NanonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 nN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonsPerMillimeter, NanonewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 N/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCentimeter, NewtonsPerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 N/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMeter, NewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 N/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerMillimeter, NewtonsPerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 lbf/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerFoot, PoundsForcePerFootTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerFoot, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 lbf/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerInch, PoundsForcePerInchTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerInch, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 lbf/yd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerYard, PoundsForcePerYardTolerance); - Assert.Equal(ForcePerLengthUnit.PoundForcePerYard, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 tf/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCentimeter, TonnesForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 тс/см", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCentimeter, TonnesForcePerCentimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 tf/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMeter, TonnesForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 тс/м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMeter, TonnesForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 tf/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMillimeter, TonnesForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsed.Unit); - } - - { - Assert.True(ForcePerLength.TryParse("1 тс/мм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerMillimeter, TonnesForcePerMillimeterTolerance); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ForcePerLength.TryParse(quantityString, out ForcePerLength parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1516,6 +1032,70 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, ForceP Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ForcePerLengthUnit.CentinewtonPerCentimeter, "cN/cm")] + [InlineData("en-US", ForcePerLengthUnit.CentinewtonPerMeter, "cN/m")] + [InlineData("en-US", ForcePerLengthUnit.CentinewtonPerMillimeter, "cN/mm")] + [InlineData("en-US", ForcePerLengthUnit.DecanewtonPerCentimeter, "daN/cm")] + [InlineData("en-US", ForcePerLengthUnit.DecanewtonPerMeter, "daN/m")] + [InlineData("en-US", ForcePerLengthUnit.DecanewtonPerMillimeter, "daN/mm")] + [InlineData("en-US", ForcePerLengthUnit.DecinewtonPerCentimeter, "dN/cm")] + [InlineData("en-US", ForcePerLengthUnit.DecinewtonPerMeter, "dN/m")] + [InlineData("en-US", ForcePerLengthUnit.DecinewtonPerMillimeter, "dN/mm")] + [InlineData("en-US", ForcePerLengthUnit.KilogramForcePerCentimeter, "kgf/cm")] + [InlineData("en-US", ForcePerLengthUnit.KilogramForcePerMeter, "kgf/m")] + [InlineData("en-US", ForcePerLengthUnit.KilogramForcePerMillimeter, "kgf/mm")] + [InlineData("en-US", ForcePerLengthUnit.KilonewtonPerCentimeter, "kN/cm")] + [InlineData("en-US", ForcePerLengthUnit.KilonewtonPerMeter, "kN/m")] + [InlineData("en-US", ForcePerLengthUnit.KilonewtonPerMillimeter, "kN/mm")] + [InlineData("en-US", ForcePerLengthUnit.KilopoundForcePerFoot, "kipf/ft")] + [InlineData("en-US", ForcePerLengthUnit.KilopoundForcePerInch, "kipf/in")] + [InlineData("en-US", ForcePerLengthUnit.MeganewtonPerCentimeter, "MN/cm")] + [InlineData("en-US", ForcePerLengthUnit.MeganewtonPerMeter, "MN/m")] + [InlineData("en-US", ForcePerLengthUnit.MeganewtonPerMillimeter, "MN/mm")] + [InlineData("en-US", ForcePerLengthUnit.MicronewtonPerCentimeter, "µN/cm")] + [InlineData("en-US", ForcePerLengthUnit.MicronewtonPerMeter, "µN/m")] + [InlineData("en-US", ForcePerLengthUnit.MicronewtonPerMillimeter, "µN/mm")] + [InlineData("en-US", ForcePerLengthUnit.MillinewtonPerCentimeter, "mN/cm")] + [InlineData("en-US", ForcePerLengthUnit.MillinewtonPerMeter, "mN/m")] + [InlineData("en-US", ForcePerLengthUnit.MillinewtonPerMillimeter, "mN/mm")] + [InlineData("en-US", ForcePerLengthUnit.NanonewtonPerCentimeter, "nN/cm")] + [InlineData("en-US", ForcePerLengthUnit.NanonewtonPerMeter, "nN/m")] + [InlineData("en-US", ForcePerLengthUnit.NanonewtonPerMillimeter, "nN/mm")] + [InlineData("en-US", ForcePerLengthUnit.NewtonPerCentimeter, "N/cm")] + [InlineData("en-US", ForcePerLengthUnit.NewtonPerMeter, "N/m")] + [InlineData("en-US", ForcePerLengthUnit.NewtonPerMillimeter, "N/mm")] + [InlineData("en-US", ForcePerLengthUnit.PoundForcePerFoot, "lbf/ft")] + [InlineData("en-US", ForcePerLengthUnit.PoundForcePerInch, "lbf/in")] + [InlineData("en-US", ForcePerLengthUnit.PoundForcePerYard, "lbf/yd")] + [InlineData("en-US", ForcePerLengthUnit.TonneForcePerCentimeter, "tf/cm")] + [InlineData("en-US", ForcePerLengthUnit.TonneForcePerMeter, "tf/m")] + [InlineData("en-US", ForcePerLengthUnit.TonneForcePerMillimeter, "tf/mm")] + [InlineData("ru-RU", ForcePerLengthUnit.KilogramForcePerCentimeter, "кгс/см")] + [InlineData("ru-RU", ForcePerLengthUnit.KilogramForcePerMeter, "кгс/м")] + [InlineData("ru-RU", ForcePerLengthUnit.KilogramForcePerMillimeter, "кгс/мм")] + [InlineData("ru-RU", ForcePerLengthUnit.TonneForcePerCentimeter, "тс/см")] + [InlineData("ru-RU", ForcePerLengthUnit.TonneForcePerMeter, "тс/м")] + [InlineData("ru-RU", ForcePerLengthUnit.TonneForcePerMillimeter, "тс/мм")] + public void GetAbbreviationForCulture(string culture, ForcePerLengthUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ForcePerLength.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ForcePerLength.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ForcePerLength.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ForcePerLengthUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 7423cf111e..784389df1d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -354,433 +354,102 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 daN", ForceUnit.Decanewton, 4.2)] + [InlineData("en-US", "4.2 dyn", ForceUnit.Dyn, 4.2)] + [InlineData("en-US", "4.2 kgf", ForceUnit.KilogramForce, 4.2)] + [InlineData("en-US", "4.2 kN", ForceUnit.Kilonewton, 4.2)] + [InlineData("en-US", "4.2 kp", ForceUnit.KiloPond, 4.2)] + [InlineData("en-US", "4.2 kipf", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 kip", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 k", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 MN", ForceUnit.Meganewton, 4.2)] + [InlineData("en-US", "4.2 µN", ForceUnit.Micronewton, 4.2)] + [InlineData("en-US", "4.2 mN", ForceUnit.Millinewton, 4.2)] + [InlineData("en-US", "4.2 N", ForceUnit.Newton, 4.2)] + [InlineData("en-US", "4.2 ozf", ForceUnit.OunceForce, 4.2)] + [InlineData("en-US", "4.2 pdl", ForceUnit.Poundal, 4.2)] + [InlineData("en-US", "4.2 lbf", ForceUnit.PoundForce, 4.2)] + [InlineData("en-US", "4.2 tf (short)", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 t (US)f", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 short tons-force", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 tf", ForceUnit.TonneForce, 4.2)] + [InlineData("en-US", "4.2 Ton", ForceUnit.TonneForce, 4.2)] + [InlineData("ru-RU", "4,2 даН", ForceUnit.Decanewton, 4.2)] + [InlineData("ru-RU", "4,2 дин", ForceUnit.Dyn, 4.2)] + [InlineData("ru-RU", "4,2 кН", ForceUnit.Kilonewton, 4.2)] + [InlineData("ru-RU", "4,2 кипф", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 койка", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 К", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 МН", ForceUnit.Meganewton, 4.2)] + [InlineData("ru-RU", "4,2 мкН", ForceUnit.Micronewton, 4.2)] + [InlineData("ru-RU", "4,2 мН", ForceUnit.Millinewton, 4.2)] + [InlineData("ru-RU", "4,2 Н", ForceUnit.Newton, 4.2)] + [InlineData("ru-RU", "4,2 паундаль", ForceUnit.Poundal, 4.2)] + [InlineData("ru-RU", "4,2 фунт-сила", ForceUnit.PoundForce, 4.2)] + [InlineData("ru-RU", "4,2 тс", ForceUnit.TonneForce, 4.2)] + public void Parse(string culture, string quantityString, ForceUnit expectedUnit, double expectedValue) { - try - { - var parsed = Force.Parse("1 daN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decanewtons, DecanewtonsTolerance); - Assert.Equal(ForceUnit.Decanewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 даН", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decanewtons, DecanewtonsTolerance); - Assert.Equal(ForceUnit.Decanewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 dyn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Dyne, DyneTolerance); - Assert.Equal(ForceUnit.Dyn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 дин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Dyne, DyneTolerance); - Assert.Equal(ForceUnit.Dyn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 kgf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForce, KilogramsForceTolerance); - Assert.Equal(ForceUnit.KilogramForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 кгс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForce, KilogramsForceTolerance); - Assert.Equal(ForceUnit.KilogramForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 kN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilonewtons, KilonewtonsTolerance); - Assert.Equal(ForceUnit.Kilonewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 кН", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilonewtons, KilonewtonsTolerance); - Assert.Equal(ForceUnit.Kilonewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 kp", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloPonds, KiloPondsTolerance); - Assert.Equal(ForceUnit.KiloPond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 кгс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KiloPonds, KiloPondsTolerance); - Assert.Equal(ForceUnit.KiloPond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 kipf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 kip", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 k", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 кипф", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 койка", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 К", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 MN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Meganewtons, MeganewtonsTolerance); - Assert.Equal(ForceUnit.Meganewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 МН", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Meganewtons, MeganewtonsTolerance); - Assert.Equal(ForceUnit.Meganewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 µN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micronewtons, MicronewtonsTolerance); - Assert.Equal(ForceUnit.Micronewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 мкН", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Micronewtons, MicronewtonsTolerance); - Assert.Equal(ForceUnit.Micronewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 mN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millinewtons, MillinewtonsTolerance); - Assert.Equal(ForceUnit.Millinewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 мН", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millinewtons, MillinewtonsTolerance); - Assert.Equal(ForceUnit.Millinewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 N", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Newtons, NewtonsTolerance); - Assert.Equal(ForceUnit.Newton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 Н", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Newtons, NewtonsTolerance); - Assert.Equal(ForceUnit.Newton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 ozf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OunceForce, OunceForceTolerance); - Assert.Equal(ForceUnit.OunceForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 pdl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Poundals, PoundalsTolerance); - Assert.Equal(ForceUnit.Poundal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 паундаль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Poundals, PoundalsTolerance); - Assert.Equal(ForceUnit.Poundal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 lbf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForce, PoundsForceTolerance); - Assert.Equal(ForceUnit.PoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 фунт-сила", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForce, PoundsForceTolerance); - Assert.Equal(ForceUnit.PoundForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 tf (short)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 t (US)f", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 short tons-force", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 tf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 Ton", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Force.Parse("1 тс", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Force.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("ru-RU", "1 кгс")] // [KilogramForce, KiloPond] + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) { - { - Assert.True(Force.TryParse("1 daN", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decanewtons, DecanewtonsTolerance); - Assert.Equal(ForceUnit.Decanewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 даН", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decanewtons, DecanewtonsTolerance); - Assert.Equal(ForceUnit.Decanewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 dyn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Dyne, DyneTolerance); - Assert.Equal(ForceUnit.Dyn, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 дин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Dyne, DyneTolerance); - Assert.Equal(ForceUnit.Dyn, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 kgf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForce, KilogramsForceTolerance); - Assert.Equal(ForceUnit.KilogramForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 kN", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilonewtons, KilonewtonsTolerance); - Assert.Equal(ForceUnit.Kilonewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 кН", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilonewtons, KilonewtonsTolerance); - Assert.Equal(ForceUnit.Kilonewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 kp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloPonds, KiloPondsTolerance); - Assert.Equal(ForceUnit.KiloPond, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 kipf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 kip", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 k", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 кипф", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 койка", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 К", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForce, KilopoundsForceTolerance); - Assert.Equal(ForceUnit.KilopoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 µN", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micronewtons, MicronewtonsTolerance); - Assert.Equal(ForceUnit.Micronewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 мкН", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micronewtons, MicronewtonsTolerance); - Assert.Equal(ForceUnit.Micronewton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 N", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Newtons, NewtonsTolerance); - Assert.Equal(ForceUnit.Newton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 Н", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Newtons, NewtonsTolerance); - Assert.Equal(ForceUnit.Newton, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 ozf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OunceForce, OunceForceTolerance); - Assert.Equal(ForceUnit.OunceForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 pdl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Poundals, PoundalsTolerance); - Assert.Equal(ForceUnit.Poundal, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 паундаль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Poundals, PoundalsTolerance); - Assert.Equal(ForceUnit.Poundal, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 lbf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForce, PoundsForceTolerance); - Assert.Equal(ForceUnit.PoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 фунт-сила", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForce, PoundsForceTolerance); - Assert.Equal(ForceUnit.PoundForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 tf (short)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 t (US)f", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 short tons-force", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTonsForce, ShortTonsForceTolerance); - Assert.Equal(ForceUnit.ShortTonForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 tf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } - - { - Assert.True(Force.TryParse("1 Ton", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } + Assert.Throws(() => Force.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Force.TryParse("1 тс", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForce, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 daN", ForceUnit.Decanewton, 4.2)] + [InlineData("en-US", "4.2 dyn", ForceUnit.Dyn, 4.2)] + [InlineData("en-US", "4.2 kgf", ForceUnit.KilogramForce, 4.2)] + [InlineData("en-US", "4.2 kN", ForceUnit.Kilonewton, 4.2)] + [InlineData("en-US", "4.2 kp", ForceUnit.KiloPond, 4.2)] + [InlineData("en-US", "4.2 kipf", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 kip", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 k", ForceUnit.KilopoundForce, 4.2)] + [InlineData("en-US", "4.2 MN", ForceUnit.Meganewton, 4.2)] + [InlineData("en-US", "4.2 µN", ForceUnit.Micronewton, 4.2)] + [InlineData("en-US", "4.2 mN", ForceUnit.Millinewton, 4.2)] + [InlineData("en-US", "4.2 N", ForceUnit.Newton, 4.2)] + [InlineData("en-US", "4.2 ozf", ForceUnit.OunceForce, 4.2)] + [InlineData("en-US", "4.2 pdl", ForceUnit.Poundal, 4.2)] + [InlineData("en-US", "4.2 lbf", ForceUnit.PoundForce, 4.2)] + [InlineData("en-US", "4.2 tf (short)", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 t (US)f", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 short tons-force", ForceUnit.ShortTonForce, 4.2)] + [InlineData("en-US", "4.2 tf", ForceUnit.TonneForce, 4.2)] + [InlineData("en-US", "4.2 Ton", ForceUnit.TonneForce, 4.2)] + [InlineData("ru-RU", "4,2 даН", ForceUnit.Decanewton, 4.2)] + [InlineData("ru-RU", "4,2 дин", ForceUnit.Dyn, 4.2)] + [InlineData("ru-RU", "4,2 кН", ForceUnit.Kilonewton, 4.2)] + [InlineData("ru-RU", "4,2 кипф", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 койка", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 К", ForceUnit.KilopoundForce, 4.2)] + [InlineData("ru-RU", "4,2 МН", ForceUnit.Meganewton, 4.2)] + [InlineData("ru-RU", "4,2 мкН", ForceUnit.Micronewton, 4.2)] + [InlineData("ru-RU", "4,2 мН", ForceUnit.Millinewton, 4.2)] + [InlineData("ru-RU", "4,2 Н", ForceUnit.Newton, 4.2)] + [InlineData("ru-RU", "4,2 паундаль", ForceUnit.Poundal, 4.2)] + [InlineData("ru-RU", "4,2 фунт-сила", ForceUnit.PoundForce, 4.2)] + [InlineData("ru-RU", "4,2 тс", ForceUnit.TonneForce, 4.2)] + public void TryParse(string culture, string quantityString, ForceUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(Force.TryParse(quantityString, out Force parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("ru-RU", "1 кгс")] // [KilogramForce, KiloPond] + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.False(Force.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] @@ -1075,6 +744,54 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi Assert.False(Force.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } + [Theory] + [InlineData("en-US", ForceUnit.Decanewton, "daN")] + [InlineData("en-US", ForceUnit.Dyn, "dyn")] + [InlineData("en-US", ForceUnit.KilogramForce, "kgf")] + [InlineData("en-US", ForceUnit.Kilonewton, "kN")] + [InlineData("en-US", ForceUnit.KiloPond, "kp")] + [InlineData("en-US", ForceUnit.KilopoundForce, "kipf")] + [InlineData("en-US", ForceUnit.Meganewton, "MN")] + [InlineData("en-US", ForceUnit.Micronewton, "µN")] + [InlineData("en-US", ForceUnit.Millinewton, "mN")] + [InlineData("en-US", ForceUnit.Newton, "N")] + [InlineData("en-US", ForceUnit.OunceForce, "ozf")] + [InlineData("en-US", ForceUnit.Poundal, "pdl")] + [InlineData("en-US", ForceUnit.PoundForce, "lbf")] + [InlineData("en-US", ForceUnit.ShortTonForce, "tf (short)")] + [InlineData("en-US", ForceUnit.TonneForce, "tf")] + [InlineData("ru-RU", ForceUnit.Decanewton, "даН")] + [InlineData("ru-RU", ForceUnit.Dyn, "дин")] + [InlineData("ru-RU", ForceUnit.KilogramForce, "кгс")] + [InlineData("ru-RU", ForceUnit.Kilonewton, "кН")] + [InlineData("ru-RU", ForceUnit.KiloPond, "кгс")] + [InlineData("ru-RU", ForceUnit.KilopoundForce, "кипф")] + [InlineData("ru-RU", ForceUnit.Meganewton, "МН")] + [InlineData("ru-RU", ForceUnit.Micronewton, "мкН")] + [InlineData("ru-RU", ForceUnit.Millinewton, "мН")] + [InlineData("ru-RU", ForceUnit.Newton, "Н")] + [InlineData("ru-RU", ForceUnit.Poundal, "паундаль")] + [InlineData("ru-RU", ForceUnit.PoundForce, "фунт-сила")] + [InlineData("ru-RU", ForceUnit.TonneForce, "тс")] + public void GetAbbreviationForCulture(string culture, ForceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Force.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Force.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Force.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ForceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index c23a4bce2f..4ec0073a7b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -336,263 +336,64 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 bpm", FrequencyUnit.BeatPerMinute, 4.2)] + [InlineData("en-US", "4.2 cph", FrequencyUnit.CyclePerHour, 4.2)] + [InlineData("en-US", "4.2 cpm", FrequencyUnit.CyclePerMinute, 4.2)] + [InlineData("en-US", "4.2 GHz", FrequencyUnit.Gigahertz, 4.2)] + [InlineData("en-US", "4.2 Hz", FrequencyUnit.Hertz, 4.2)] + [InlineData("en-US", "4.2 kHz", FrequencyUnit.Kilohertz, 4.2)] + [InlineData("en-US", "4.2 MHz", FrequencyUnit.Megahertz, 4.2)] + [InlineData("en-US", "4.2 µHz", FrequencyUnit.Microhertz, 4.2)] + [InlineData("en-US", "4.2 mHz", FrequencyUnit.Millihertz, 4.2)] + [InlineData("en-US", "4.2 s⁻¹", FrequencyUnit.PerSecond, 4.2)] + [InlineData("en-US", "4.2 rad/s", FrequencyUnit.RadianPerSecond, 4.2)] + [InlineData("en-US", "4.2 THz", FrequencyUnit.Terahertz, 4.2)] + [InlineData("ru-RU", "4,2 ГГц", FrequencyUnit.Gigahertz, 4.2)] + [InlineData("ru-RU", "4,2 Гц", FrequencyUnit.Hertz, 4.2)] + [InlineData("ru-RU", "4,2 кГц", FrequencyUnit.Kilohertz, 4.2)] + [InlineData("ru-RU", "4,2 МГц", FrequencyUnit.Megahertz, 4.2)] + [InlineData("ru-RU", "4,2 мкГц", FrequencyUnit.Microhertz, 4.2)] + [InlineData("ru-RU", "4,2 мГц", FrequencyUnit.Millihertz, 4.2)] + [InlineData("ru-RU", "4,2 с⁻¹", FrequencyUnit.PerSecond, 4.2)] + [InlineData("ru-RU", "4,2 рад/с", FrequencyUnit.RadianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 ТГц", FrequencyUnit.Terahertz, 4.2)] + public void Parse(string culture, string quantityString, FrequencyUnit expectedUnit, double expectedValue) { - try - { - var parsed = Frequency.Parse("1 bpm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BeatsPerMinute, BeatsPerMinuteTolerance); - Assert.Equal(FrequencyUnit.BeatPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 cph", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CyclesPerHour, CyclesPerHourTolerance); - Assert.Equal(FrequencyUnit.CyclePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 cpm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CyclesPerMinute, CyclesPerMinuteTolerance); - Assert.Equal(FrequencyUnit.CyclePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 GHz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigahertz, GigahertzTolerance); - Assert.Equal(FrequencyUnit.Gigahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 ГГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigahertz, GigahertzTolerance); - Assert.Equal(FrequencyUnit.Gigahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 Hz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hertz, HertzTolerance); - Assert.Equal(FrequencyUnit.Hertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 Гц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hertz, HertzTolerance); - Assert.Equal(FrequencyUnit.Hertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 kHz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilohertz, KilohertzTolerance); - Assert.Equal(FrequencyUnit.Kilohertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 кГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilohertz, KilohertzTolerance); - Assert.Equal(FrequencyUnit.Kilohertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 MHz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megahertz, MegahertzTolerance); - Assert.Equal(FrequencyUnit.Megahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 МГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megahertz, MegahertzTolerance); - Assert.Equal(FrequencyUnit.Megahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 µHz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microhertz, MicrohertzTolerance); - Assert.Equal(FrequencyUnit.Microhertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 мкГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microhertz, MicrohertzTolerance); - Assert.Equal(FrequencyUnit.Microhertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 mHz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millihertz, MillihertzTolerance); - Assert.Equal(FrequencyUnit.Millihertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 мГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millihertz, MillihertzTolerance); - Assert.Equal(FrequencyUnit.Millihertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 s⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PerSecond, PerSecondTolerance); - Assert.Equal(FrequencyUnit.PerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 с⁻¹", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PerSecond, PerSecondTolerance); - Assert.Equal(FrequencyUnit.PerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 rad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 рад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 THz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terahertz, TerahertzTolerance); - Assert.Equal(FrequencyUnit.Terahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Frequency.Parse("1 ТГц", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Terahertz, TerahertzTolerance); - Assert.Equal(FrequencyUnit.Terahertz, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Frequency.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 bpm", FrequencyUnit.BeatPerMinute, 4.2)] + [InlineData("en-US", "4.2 cph", FrequencyUnit.CyclePerHour, 4.2)] + [InlineData("en-US", "4.2 cpm", FrequencyUnit.CyclePerMinute, 4.2)] + [InlineData("en-US", "4.2 GHz", FrequencyUnit.Gigahertz, 4.2)] + [InlineData("en-US", "4.2 Hz", FrequencyUnit.Hertz, 4.2)] + [InlineData("en-US", "4.2 kHz", FrequencyUnit.Kilohertz, 4.2)] + [InlineData("en-US", "4.2 MHz", FrequencyUnit.Megahertz, 4.2)] + [InlineData("en-US", "4.2 µHz", FrequencyUnit.Microhertz, 4.2)] + [InlineData("en-US", "4.2 mHz", FrequencyUnit.Millihertz, 4.2)] + [InlineData("en-US", "4.2 s⁻¹", FrequencyUnit.PerSecond, 4.2)] + [InlineData("en-US", "4.2 rad/s", FrequencyUnit.RadianPerSecond, 4.2)] + [InlineData("en-US", "4.2 THz", FrequencyUnit.Terahertz, 4.2)] + [InlineData("ru-RU", "4,2 ГГц", FrequencyUnit.Gigahertz, 4.2)] + [InlineData("ru-RU", "4,2 Гц", FrequencyUnit.Hertz, 4.2)] + [InlineData("ru-RU", "4,2 кГц", FrequencyUnit.Kilohertz, 4.2)] + [InlineData("ru-RU", "4,2 МГц", FrequencyUnit.Megahertz, 4.2)] + [InlineData("ru-RU", "4,2 мкГц", FrequencyUnit.Microhertz, 4.2)] + [InlineData("ru-RU", "4,2 мГц", FrequencyUnit.Millihertz, 4.2)] + [InlineData("ru-RU", "4,2 с⁻¹", FrequencyUnit.PerSecond, 4.2)] + [InlineData("ru-RU", "4,2 рад/с", FrequencyUnit.RadianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 ТГц", FrequencyUnit.Terahertz, 4.2)] + public void TryParse(string culture, string quantityString, FrequencyUnit expectedUnit, double expectedValue) { - { - Assert.True(Frequency.TryParse("1 bpm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BeatsPerMinute, BeatsPerMinuteTolerance); - Assert.Equal(FrequencyUnit.BeatPerMinute, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 cph", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CyclesPerHour, CyclesPerHourTolerance); - Assert.Equal(FrequencyUnit.CyclePerHour, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 cpm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CyclesPerMinute, CyclesPerMinuteTolerance); - Assert.Equal(FrequencyUnit.CyclePerMinute, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 GHz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigahertz, GigahertzTolerance); - Assert.Equal(FrequencyUnit.Gigahertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 ГГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigahertz, GigahertzTolerance); - Assert.Equal(FrequencyUnit.Gigahertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 Hz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hertz, HertzTolerance); - Assert.Equal(FrequencyUnit.Hertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 Гц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hertz, HertzTolerance); - Assert.Equal(FrequencyUnit.Hertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 kHz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilohertz, KilohertzTolerance); - Assert.Equal(FrequencyUnit.Kilohertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 кГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilohertz, KilohertzTolerance); - Assert.Equal(FrequencyUnit.Kilohertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 µHz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microhertz, MicrohertzTolerance); - Assert.Equal(FrequencyUnit.Microhertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 мкГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microhertz, MicrohertzTolerance); - Assert.Equal(FrequencyUnit.Microhertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 s⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PerSecond, PerSecondTolerance); - Assert.Equal(FrequencyUnit.PerSecond, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 с⁻¹", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PerSecond, PerSecondTolerance); - Assert.Equal(FrequencyUnit.PerSecond, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 rad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 рад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 THz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terahertz, TerahertzTolerance); - Assert.Equal(FrequencyUnit.Terahertz, parsed.Unit); - } - - { - Assert.True(Frequency.TryParse("1 ТГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terahertz, TerahertzTolerance); - Assert.Equal(FrequencyUnit.Terahertz, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Frequency.TryParse(quantityString, out Frequency parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -793,6 +594,47 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Freque Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", FrequencyUnit.BeatPerMinute, "bpm")] + [InlineData("en-US", FrequencyUnit.CyclePerHour, "cph")] + [InlineData("en-US", FrequencyUnit.CyclePerMinute, "cpm")] + [InlineData("en-US", FrequencyUnit.Gigahertz, "GHz")] + [InlineData("en-US", FrequencyUnit.Hertz, "Hz")] + [InlineData("en-US", FrequencyUnit.Kilohertz, "kHz")] + [InlineData("en-US", FrequencyUnit.Megahertz, "MHz")] + [InlineData("en-US", FrequencyUnit.Microhertz, "µHz")] + [InlineData("en-US", FrequencyUnit.Millihertz, "mHz")] + [InlineData("en-US", FrequencyUnit.PerSecond, "s⁻¹")] + [InlineData("en-US", FrequencyUnit.RadianPerSecond, "rad/s")] + [InlineData("en-US", FrequencyUnit.Terahertz, "THz")] + [InlineData("ru-RU", FrequencyUnit.Gigahertz, "ГГц")] + [InlineData("ru-RU", FrequencyUnit.Hertz, "Гц")] + [InlineData("ru-RU", FrequencyUnit.Kilohertz, "кГц")] + [InlineData("ru-RU", FrequencyUnit.Megahertz, "МГц")] + [InlineData("ru-RU", FrequencyUnit.Microhertz, "мкГц")] + [InlineData("ru-RU", FrequencyUnit.Millihertz, "мГц")] + [InlineData("ru-RU", FrequencyUnit.PerSecond, "с⁻¹")] + [InlineData("ru-RU", FrequencyUnit.RadianPerSecond, "рад/с")] + [InlineData("ru-RU", FrequencyUnit.Terahertz, "ТГц")] + public void GetAbbreviationForCulture(string culture, FrequencyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Frequency.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Frequency.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Frequency.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(FrequencyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 03fdb86fb2..f7a90800e9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -288,66 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 km/l", FuelEfficiencyUnit.KilometerPerLiter, 4.2)] + [InlineData("en-US", "4.2 l/100km", FuelEfficiencyUnit.LiterPer100Kilometers, 4.2)] + [InlineData("en-US", "4.2 mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon, 4.2)] + [InlineData("en-US", "4.2 mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon, 4.2)] + public void Parse(string culture, string quantityString, FuelEfficiencyUnit expectedUnit, double expectedValue) { - try - { - var parsed = FuelEfficiency.Parse("1 km/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerLiter, KilometersPerLiterTolerance); - Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FuelEfficiency.Parse("1 l/100km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPer100Kilometers, LitersPer100KilometersTolerance); - Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FuelEfficiency.Parse("1 mpg (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilesPerUkGallon, MilesPerUkGallonTolerance); - Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = FuelEfficiency.Parse("1 mpg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilesPerUsGallon, MilesPerUsGallonTolerance); - Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = FuelEfficiency.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 km/l", FuelEfficiencyUnit.KilometerPerLiter, 4.2)] + [InlineData("en-US", "4.2 l/100km", FuelEfficiencyUnit.LiterPer100Kilometers, 4.2)] + [InlineData("en-US", "4.2 mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon, 4.2)] + [InlineData("en-US", "4.2 mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon, 4.2)] + public void TryParse(string culture, string quantityString, FuelEfficiencyUnit expectedUnit, double expectedValue) { - { - Assert.True(FuelEfficiency.TryParse("1 km/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerLiter, KilometersPerLiterTolerance); - Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, parsed.Unit); - } - - { - Assert.True(FuelEfficiency.TryParse("1 l/100km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPer100Kilometers, LitersPer100KilometersTolerance); - Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, parsed.Unit); - } - - { - Assert.True(FuelEfficiency.TryParse("1 mpg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilesPerUkGallon, MilesPerUkGallonTolerance); - Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, parsed.Unit); - } - - { - Assert.True(FuelEfficiency.TryParse("1 mpg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilesPerUsGallon, MilesPerUsGallonTolerance); - Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(FuelEfficiency.TryParse(quantityString, out FuelEfficiency parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -448,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, FuelEf Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", FuelEfficiencyUnit.KilometerPerLiter, "km/l")] + [InlineData("en-US", FuelEfficiencyUnit.LiterPer100Kilometers, "l/100km")] + [InlineData("en-US", FuelEfficiencyUnit.MilePerUkGallon, "mpg (imp.)")] + [InlineData("en-US", FuelEfficiencyUnit.MilePerUsGallon, "mpg (U.S.)")] + public void GetAbbreviationForCulture(string culture, FuelEfficiencyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = FuelEfficiency.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(FuelEfficiency.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = FuelEfficiency.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(FuelEfficiencyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index f9a85d07b5..a6bc0a05a2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -372,261 +372,60 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch, 4.2)] + [InlineData("en-US", "4.2 cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 cW/m²", HeatFluxUnit.CentiwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 dW/m²", HeatFluxUnit.DeciwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/m²", HeatFluxUnit.KilowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µW/m²", HeatFluxUnit.MicrowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mW/m²", HeatFluxUnit.MilliwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nW/m²", HeatFluxUnit.NanowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond, 4.2)] + [InlineData("en-US", "4.2 lb/s³", HeatFluxUnit.PoundPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 lbm/s³", HeatFluxUnit.PoundPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 W/ft²", HeatFluxUnit.WattPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 W/in²", HeatFluxUnit.WattPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 W/m²", HeatFluxUnit.WattPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, HeatFluxUnit expectedUnit, double expectedValue) { - try - { - var parsed = HeatFlux.Parse("1 BTU/(h·ft²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFoot, BtusPerHourSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerHourSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 BTU/(min·ft²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerMinuteSquareFoot, BtusPerMinuteSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerMinuteSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 BTU/(s·ft²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerSecondSquareFoot, BtusPerSecondSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 BTU/(s·in²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerSecondSquareInch, BtusPerSecondSquareInchTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 cal/(s·cm²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CaloriesPerSecondSquareCentimeter, CaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.CaloriePerSecondSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 cW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentiwattsPerSquareMeter, CentiwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.CentiwattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 dW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerSquareMeter, DeciwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.DeciwattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 kcal/(h·m²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeter, KilocaloriesPerHourSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerHourSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 kcal/(s·cm²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerSecondSquareCentimeter, KilocaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 kW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 µW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MicrowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 mW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MilliwattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 nW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.NanowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 lbf/(ft·s)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerFootSecond, PoundsForcePerFootSecondTolerance); - Assert.Equal(HeatFluxUnit.PoundForcePerFootSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 lb/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecondCubed, PoundsPerSecondCubedTolerance); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 lbm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecondCubed, PoundsPerSecondCubedTolerance); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 W/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareFoot, WattsPerSquareFootTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 W/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareInch, WattsPerSquareInchTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatFlux.Parse("1 W/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = HeatFlux.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot, 4.2)] + [InlineData("en-US", "4.2 BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch, 4.2)] + [InlineData("en-US", "4.2 cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 cW/m²", HeatFluxUnit.CentiwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 dW/m²", HeatFluxUnit.DeciwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/m²", HeatFluxUnit.KilowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µW/m²", HeatFluxUnit.MicrowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mW/m²", HeatFluxUnit.MilliwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nW/m²", HeatFluxUnit.NanowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond, 4.2)] + [InlineData("en-US", "4.2 lb/s³", HeatFluxUnit.PoundPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 lbm/s³", HeatFluxUnit.PoundPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 W/ft²", HeatFluxUnit.WattPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 W/in²", HeatFluxUnit.WattPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 W/m²", HeatFluxUnit.WattPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, HeatFluxUnit expectedUnit, double expectedValue) { - { - Assert.True(HeatFlux.TryParse("1 BTU/(h·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerHourSquareFoot, BtusPerHourSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerHourSquareFoot, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 BTU/(min·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerMinuteSquareFoot, BtusPerMinuteSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerMinuteSquareFoot, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 BTU/(s·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerSecondSquareFoot, BtusPerSecondSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareFoot, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 BTU/(s·in²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerSecondSquareInch, BtusPerSecondSquareInchTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareInch, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 cal/(s·cm²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CaloriesPerSecondSquareCentimeter, CaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.CaloriePerSecondSquareCentimeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 cW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentiwattsPerSquareMeter, CentiwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.CentiwattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 dW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerSquareMeter, DeciwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.DeciwattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 kcal/(h·m²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerHourSquareMeter, KilocaloriesPerHourSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerHourSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 kcal/(s·cm²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerSecondSquareCentimeter, KilocaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 kW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 µW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MicrowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 mW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MilliwattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 nW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.NanowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 lbf/(ft·s)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerFootSecond, PoundsForcePerFootSecondTolerance); - Assert.Equal(HeatFluxUnit.PoundForcePerFootSecond, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 lb/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecondCubed, PoundsPerSecondCubedTolerance); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 lbm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecondCubed, PoundsPerSecondCubedTolerance); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 W/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareFoot, WattsPerSquareFootTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareFoot, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 W/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareInch, WattsPerSquareInchTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareInch, parsed.Unit); - } - - { - Assert.True(HeatFlux.TryParse("1 W/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(HeatFlux.TryParse(quantityString, out HeatFlux parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -847,6 +646,44 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, HeatFl Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", HeatFluxUnit.BtuPerHourSquareFoot, "BTU/(h·ft²)")] + [InlineData("en-US", HeatFluxUnit.BtuPerMinuteSquareFoot, "BTU/(min·ft²)")] + [InlineData("en-US", HeatFluxUnit.BtuPerSecondSquareFoot, "BTU/(s·ft²)")] + [InlineData("en-US", HeatFluxUnit.BtuPerSecondSquareInch, "BTU/(s·in²)")] + [InlineData("en-US", HeatFluxUnit.CaloriePerSecondSquareCentimeter, "cal/(s·cm²)")] + [InlineData("en-US", HeatFluxUnit.CentiwattPerSquareMeter, "cW/m²")] + [InlineData("en-US", HeatFluxUnit.DeciwattPerSquareMeter, "dW/m²")] + [InlineData("en-US", HeatFluxUnit.KilocaloriePerHourSquareMeter, "kcal/(h·m²)")] + [InlineData("en-US", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, "kcal/(s·cm²)")] + [InlineData("en-US", HeatFluxUnit.KilowattPerSquareMeter, "kW/m²")] + [InlineData("en-US", HeatFluxUnit.MicrowattPerSquareMeter, "µW/m²")] + [InlineData("en-US", HeatFluxUnit.MilliwattPerSquareMeter, "mW/m²")] + [InlineData("en-US", HeatFluxUnit.NanowattPerSquareMeter, "nW/m²")] + [InlineData("en-US", HeatFluxUnit.PoundForcePerFootSecond, "lbf/(ft·s)")] + [InlineData("en-US", HeatFluxUnit.PoundPerSecondCubed, "lb/s³")] + [InlineData("en-US", HeatFluxUnit.WattPerSquareFoot, "W/ft²")] + [InlineData("en-US", HeatFluxUnit.WattPerSquareInch, "W/in²")] + [InlineData("en-US", HeatFluxUnit.WattPerSquareMeter, "W/m²")] + public void GetAbbreviationForCulture(string culture, HeatFluxUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = HeatFlux.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(HeatFlux.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = HeatFlux.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(HeatFluxUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index e62c5eb1fd..e41865aec9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -294,196 +294,50 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, 4.2)] + [InlineData("en-US", "4.2 W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 4.2)] + public void Parse(string culture, string quantityString, HeatTransferCoefficientUnit expectedUnit, double expectedValue) { - 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.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.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 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 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 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 */ } - - try - { - var parsed = HeatTransferCoefficient.Parse("1 W/(m²·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = HeatTransferCoefficient.Parse("1 W/(m²·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = HeatTransferCoefficient.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, 4.2)] + [InlineData("en-US", "4.2 W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 4.2)] + public void TryParse(string culture, string quantityString, HeatTransferCoefficientUnit expectedUnit, double expectedValue) { - { - 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.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.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 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 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 kkcal/(m²·hr·°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 W/(m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, parsed.Unit); - } - - { - Assert.True(HeatTransferCoefficient.TryParse("1 W/(m²·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(HeatTransferCoefficient.TryParse(quantityString, out HeatTransferCoefficient parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -664,6 +518,31 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, HeatTr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "Btu/(h·ft²·°F)")] + [InlineData("en-US", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, "kcal/(h·m²·°C)")] + [InlineData("en-US", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "kkcal/(h·m²·°C)")] + [InlineData("en-US", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "W/(m²·°C)")] + [InlineData("en-US", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "W/(m²·K)")] + public void GetAbbreviationForCulture(string culture, HeatTransferCoefficientUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = HeatTransferCoefficient.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(HeatTransferCoefficient.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = HeatTransferCoefficient.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(HeatTransferCoefficientUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index ab55de0b92..6e1aba949a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -288,54 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 klx", IlluminanceUnit.Kilolux, 4.2)] + [InlineData("en-US", "4.2 lx", IlluminanceUnit.Lux, 4.2)] + [InlineData("en-US", "4.2 Mlx", IlluminanceUnit.Megalux, 4.2)] + [InlineData("en-US", "4.2 mlx", IlluminanceUnit.Millilux, 4.2)] + public void Parse(string culture, string quantityString, IlluminanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = Illuminance.Parse("1 klx", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilolux, KiloluxTolerance); - Assert.Equal(IlluminanceUnit.Kilolux, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Illuminance.Parse("1 lx", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Lux, LuxTolerance); - Assert.Equal(IlluminanceUnit.Lux, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Illuminance.Parse("1 Mlx", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megalux, MegaluxTolerance); - Assert.Equal(IlluminanceUnit.Megalux, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Illuminance.Parse("1 mlx", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millilux, MilliluxTolerance); - Assert.Equal(IlluminanceUnit.Millilux, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Illuminance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 klx", IlluminanceUnit.Kilolux, 4.2)] + [InlineData("en-US", "4.2 lx", IlluminanceUnit.Lux, 4.2)] + [InlineData("en-US", "4.2 Mlx", IlluminanceUnit.Megalux, 4.2)] + [InlineData("en-US", "4.2 mlx", IlluminanceUnit.Millilux, 4.2)] + public void TryParse(string culture, string quantityString, IlluminanceUnit expectedUnit, double expectedValue) { - { - Assert.True(Illuminance.TryParse("1 klx", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilolux, KiloluxTolerance); - Assert.Equal(IlluminanceUnit.Kilolux, parsed.Unit); - } - - { - Assert.True(Illuminance.TryParse("1 lx", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Lux, LuxTolerance); - Assert.Equal(IlluminanceUnit.Lux, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Illuminance.TryParse(quantityString, out Illuminance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -436,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Illumi Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", IlluminanceUnit.Kilolux, "klx")] + [InlineData("en-US", IlluminanceUnit.Lux, "lx")] + [InlineData("en-US", IlluminanceUnit.Megalux, "Mlx")] + [InlineData("en-US", IlluminanceUnit.Millilux, "mlx")] + public void GetAbbreviationForCulture(string culture, IlluminanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Illuminance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Illuminance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Illuminance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(IlluminanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs index 060c0ef831..9c87a96813 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs @@ -342,171 +342,48 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cN·s", ImpulseUnit.CentinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 daN·s", ImpulseUnit.DecanewtonSecond, 4.2)] + [InlineData("en-US", "4.2 dN·s", ImpulseUnit.DecinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 kg·m/s", ImpulseUnit.KilogramMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kN·s", ImpulseUnit.KilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 MN·s", ImpulseUnit.MeganewtonSecond, 4.2)] + [InlineData("en-US", "4.2 µN·s", ImpulseUnit.MicronewtonSecond, 4.2)] + [InlineData("en-US", "4.2 mN·s", ImpulseUnit.MillinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 nN·s", ImpulseUnit.NanonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 N·s", ImpulseUnit.NewtonSecond, 4.2)] + [InlineData("en-US", "4.2 lb·ft/s", ImpulseUnit.PoundFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 lbf·s", ImpulseUnit.PoundForceSecond, 4.2)] + [InlineData("en-US", "4.2 slug·ft/s", ImpulseUnit.SlugFootPerSecond, 4.2)] + public void Parse(string culture, string quantityString, ImpulseUnit expectedUnit, double expectedValue) { - try - { - var parsed = Impulse.Parse("1 cN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonSeconds, CentinewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.CentinewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 daN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonSeconds, DecanewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.DecanewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 dN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonSeconds, DecinewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.DecinewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 kg·m/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramMetersPerSecond, KilogramMetersPerSecondTolerance); - Assert.Equal(ImpulseUnit.KilogramMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 kN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonSeconds, KilonewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.KilonewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 MN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonSeconds, MeganewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.MeganewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 µN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonSeconds, MicronewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.MicronewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 mN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonSeconds, MillinewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.MillinewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 nN·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonSeconds, NanonewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.NanonewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 N·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonSeconds, NewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.NewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 lb·ft/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundFeetPerSecond, PoundFeetPerSecondTolerance); - Assert.Equal(ImpulseUnit.PoundFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 lbf·s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceSeconds, PoundForceSecondsTolerance); - Assert.Equal(ImpulseUnit.PoundForceSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Impulse.Parse("1 slug·ft/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugFeetPerSecond, SlugFeetPerSecondTolerance); - Assert.Equal(ImpulseUnit.SlugFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Impulse.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cN·s", ImpulseUnit.CentinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 daN·s", ImpulseUnit.DecanewtonSecond, 4.2)] + [InlineData("en-US", "4.2 dN·s", ImpulseUnit.DecinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 kg·m/s", ImpulseUnit.KilogramMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kN·s", ImpulseUnit.KilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 MN·s", ImpulseUnit.MeganewtonSecond, 4.2)] + [InlineData("en-US", "4.2 µN·s", ImpulseUnit.MicronewtonSecond, 4.2)] + [InlineData("en-US", "4.2 mN·s", ImpulseUnit.MillinewtonSecond, 4.2)] + [InlineData("en-US", "4.2 nN·s", ImpulseUnit.NanonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 N·s", ImpulseUnit.NewtonSecond, 4.2)] + [InlineData("en-US", "4.2 lb·ft/s", ImpulseUnit.PoundFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 lbf·s", ImpulseUnit.PoundForceSecond, 4.2)] + [InlineData("en-US", "4.2 slug·ft/s", ImpulseUnit.SlugFootPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, ImpulseUnit expectedUnit, double expectedValue) { - { - Assert.True(Impulse.TryParse("1 cN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonSeconds, CentinewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.CentinewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 daN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonSeconds, DecanewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.DecanewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 dN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonSeconds, DecinewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.DecinewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 kg·m/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramMetersPerSecond, KilogramMetersPerSecondTolerance); - Assert.Equal(ImpulseUnit.KilogramMeterPerSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 kN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonSeconds, KilonewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.KilonewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 µN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonSeconds, MicronewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.MicronewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 nN·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonSeconds, NanonewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.NanonewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 N·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonSeconds, NewtonSecondsTolerance); - Assert.Equal(ImpulseUnit.NewtonSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 lb·ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundFeetPerSecond, PoundFeetPerSecondTolerance); - Assert.Equal(ImpulseUnit.PoundFootPerSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 lbf·s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceSeconds, PoundForceSecondsTolerance); - Assert.Equal(ImpulseUnit.PoundForceSecond, parsed.Unit); - } - - { - Assert.True(Impulse.TryParse("1 slug·ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugFeetPerSecond, SlugFeetPerSecondTolerance); - Assert.Equal(ImpulseUnit.SlugFootPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Impulse.TryParse(quantityString, out Impulse parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -679,6 +556,39 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Impuls Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ImpulseUnit.CentinewtonSecond, "cN·s")] + [InlineData("en-US", ImpulseUnit.DecanewtonSecond, "daN·s")] + [InlineData("en-US", ImpulseUnit.DecinewtonSecond, "dN·s")] + [InlineData("en-US", ImpulseUnit.KilogramMeterPerSecond, "kg·m/s")] + [InlineData("en-US", ImpulseUnit.KilonewtonSecond, "kN·s")] + [InlineData("en-US", ImpulseUnit.MeganewtonSecond, "MN·s")] + [InlineData("en-US", ImpulseUnit.MicronewtonSecond, "µN·s")] + [InlineData("en-US", ImpulseUnit.MillinewtonSecond, "mN·s")] + [InlineData("en-US", ImpulseUnit.NanonewtonSecond, "nN·s")] + [InlineData("en-US", ImpulseUnit.NewtonSecond, "N·s")] + [InlineData("en-US", ImpulseUnit.PoundFootPerSecond, "lb·ft/s")] + [InlineData("en-US", ImpulseUnit.PoundForceSecond, "lbf·s")] + [InlineData("en-US", ImpulseUnit.SlugFootPerSecond, "slug·ft/s")] + public void GetAbbreviationForCulture(string culture, ImpulseUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Impulse.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Impulse.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Impulse.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ImpulseUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index 6f47029d34..fe9488bcfb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -438,365 +438,100 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 b", InformationUnit.Bit, 4.2)] + [InlineData("en-US", "4.2 B", InformationUnit.Byte, 4.2)] + [InlineData("en-US", "4.2 Eb", InformationUnit.Exabit, 4.2)] + [InlineData("en-US", "4.2 EB", InformationUnit.Exabyte, 4.2)] + [InlineData("en-US", "4.2 Eo", InformationUnit.Exaoctet, 4.2)] + [InlineData("en-US", "4.2 Eib", InformationUnit.Exbibit, 4.2)] + [InlineData("en-US", "4.2 EiB", InformationUnit.Exbibyte, 4.2)] + [InlineData("en-US", "4.2 Eio", InformationUnit.Exbioctet, 4.2)] + [InlineData("en-US", "4.2 Gib", InformationUnit.Gibibit, 4.2)] + [InlineData("en-US", "4.2 GiB", InformationUnit.Gibibyte, 4.2)] + [InlineData("en-US", "4.2 Gio", InformationUnit.Gibioctet, 4.2)] + [InlineData("en-US", "4.2 Gb", InformationUnit.Gigabit, 4.2)] + [InlineData("en-US", "4.2 GB", InformationUnit.Gigabyte, 4.2)] + [InlineData("en-US", "4.2 Go", InformationUnit.Gigaoctet, 4.2)] + [InlineData("en-US", "4.2 Kib", InformationUnit.Kibibit, 4.2)] + [InlineData("en-US", "4.2 KiB", InformationUnit.Kibibyte, 4.2)] + [InlineData("en-US", "4.2 Kio", InformationUnit.Kibioctet, 4.2)] + [InlineData("en-US", "4.2 kb", InformationUnit.Kilobit, 4.2)] + [InlineData("en-US", "4.2 kB", InformationUnit.Kilobyte, 4.2)] + [InlineData("en-US", "4.2 ko", InformationUnit.Kilooctet, 4.2)] + [InlineData("en-US", "4.2 Mib", InformationUnit.Mebibit, 4.2)] + [InlineData("en-US", "4.2 MiB", InformationUnit.Mebibyte, 4.2)] + [InlineData("en-US", "4.2 Mio", InformationUnit.Mebioctet, 4.2)] + [InlineData("en-US", "4.2 Mb", InformationUnit.Megabit, 4.2)] + [InlineData("en-US", "4.2 MB", InformationUnit.Megabyte, 4.2)] + [InlineData("en-US", "4.2 Mo", InformationUnit.Megaoctet, 4.2)] + [InlineData("en-US", "4.2 o", InformationUnit.Octet, 4.2)] + [InlineData("en-US", "4.2 Pib", InformationUnit.Pebibit, 4.2)] + [InlineData("en-US", "4.2 PiB", InformationUnit.Pebibyte, 4.2)] + [InlineData("en-US", "4.2 Pio", InformationUnit.Pebioctet, 4.2)] + [InlineData("en-US", "4.2 Pb", InformationUnit.Petabit, 4.2)] + [InlineData("en-US", "4.2 PB", InformationUnit.Petabyte, 4.2)] + [InlineData("en-US", "4.2 Po", InformationUnit.Petaoctet, 4.2)] + [InlineData("en-US", "4.2 Tib", InformationUnit.Tebibit, 4.2)] + [InlineData("en-US", "4.2 TiB", InformationUnit.Tebibyte, 4.2)] + [InlineData("en-US", "4.2 Tio", InformationUnit.Tebioctet, 4.2)] + [InlineData("en-US", "4.2 Tb", InformationUnit.Terabit, 4.2)] + [InlineData("en-US", "4.2 TB", InformationUnit.Terabyte, 4.2)] + [InlineData("en-US", "4.2 To", InformationUnit.Teraoctet, 4.2)] + public void Parse(string culture, string quantityString, InformationUnit expectedUnit, double expectedValue) { - try - { - var parsed = Information.Parse("1 b", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Bits, BitsTolerance); - Assert.Equal(InformationUnit.Bit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 B", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Bytes, BytesTolerance); - Assert.Equal(InformationUnit.Byte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Eb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exabits, ExabitsTolerance); - Assert.Equal(InformationUnit.Exabit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 EB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exabytes, ExabytesTolerance); - Assert.Equal(InformationUnit.Exabyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Eo", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exaoctets, ExaoctetsTolerance); - Assert.Equal(InformationUnit.Exaoctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Eib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exbibits, ExbibitsTolerance); - Assert.Equal(InformationUnit.Exbibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 EiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exbibytes, ExbibytesTolerance); - Assert.Equal(InformationUnit.Exbibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Eio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exbioctets, ExbioctetsTolerance); - Assert.Equal(InformationUnit.Exbioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Gib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gibibits, GibibitsTolerance); - Assert.Equal(InformationUnit.Gibibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 GiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gibibytes, GibibytesTolerance); - Assert.Equal(InformationUnit.Gibibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Gio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gibioctets, GibioctetsTolerance); - Assert.Equal(InformationUnit.Gibioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Gb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigabits, GigabitsTolerance); - Assert.Equal(InformationUnit.Gigabit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 GB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigabytes, GigabytesTolerance); - Assert.Equal(InformationUnit.Gigabyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Go", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigaoctets, GigaoctetsTolerance); - Assert.Equal(InformationUnit.Gigaoctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Kib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kibibits, KibibitsTolerance); - Assert.Equal(InformationUnit.Kibibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 KiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kibibytes, KibibytesTolerance); - Assert.Equal(InformationUnit.Kibibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Kio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kibioctets, KibioctetsTolerance); - Assert.Equal(InformationUnit.Kibioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 kb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilobits, KilobitsTolerance); - Assert.Equal(InformationUnit.Kilobit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 kB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilobytes, KilobytesTolerance); - Assert.Equal(InformationUnit.Kilobyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 ko", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilooctets, KilooctetsTolerance); - Assert.Equal(InformationUnit.Kilooctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Mib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mebibits, MebibitsTolerance); - Assert.Equal(InformationUnit.Mebibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 MiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mebibytes, MebibytesTolerance); - Assert.Equal(InformationUnit.Mebibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Mio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mebioctets, MebioctetsTolerance); - Assert.Equal(InformationUnit.Mebioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Mb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megabits, MegabitsTolerance); - Assert.Equal(InformationUnit.Megabit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 MB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megabytes, MegabytesTolerance); - Assert.Equal(InformationUnit.Megabyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Mo", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaoctets, MegaoctetsTolerance); - Assert.Equal(InformationUnit.Megaoctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 o", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Octets, OctetsTolerance); - Assert.Equal(InformationUnit.Octet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Pib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pebibits, PebibitsTolerance); - Assert.Equal(InformationUnit.Pebibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 PiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pebibytes, PebibytesTolerance); - Assert.Equal(InformationUnit.Pebibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Pio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pebioctets, PebioctetsTolerance); - Assert.Equal(InformationUnit.Pebioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Pb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petabits, PetabitsTolerance); - Assert.Equal(InformationUnit.Petabit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 PB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petabytes, PetabytesTolerance); - Assert.Equal(InformationUnit.Petabyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Po", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petaoctets, PetaoctetsTolerance); - Assert.Equal(InformationUnit.Petaoctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Tib", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Tebibits, TebibitsTolerance); - Assert.Equal(InformationUnit.Tebibit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 TiB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Tebibytes, TebibytesTolerance); - Assert.Equal(InformationUnit.Tebibyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Tio", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Tebioctets, TebioctetsTolerance); - Assert.Equal(InformationUnit.Tebioctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 Tb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terabits, TerabitsTolerance); - Assert.Equal(InformationUnit.Terabit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 TB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terabytes, TerabytesTolerance); - Assert.Equal(InformationUnit.Terabyte, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Information.Parse("1 To", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teraoctets, TeraoctetsTolerance); - Assert.Equal(InformationUnit.Teraoctet, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Information.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 b", InformationUnit.Bit, 4.2)] + [InlineData("en-US", "4.2 B", InformationUnit.Byte, 4.2)] + [InlineData("en-US", "4.2 Eb", InformationUnit.Exabit, 4.2)] + [InlineData("en-US", "4.2 EB", InformationUnit.Exabyte, 4.2)] + [InlineData("en-US", "4.2 Eo", InformationUnit.Exaoctet, 4.2)] + [InlineData("en-US", "4.2 Eib", InformationUnit.Exbibit, 4.2)] + [InlineData("en-US", "4.2 EiB", InformationUnit.Exbibyte, 4.2)] + [InlineData("en-US", "4.2 Eio", InformationUnit.Exbioctet, 4.2)] + [InlineData("en-US", "4.2 Gib", InformationUnit.Gibibit, 4.2)] + [InlineData("en-US", "4.2 GiB", InformationUnit.Gibibyte, 4.2)] + [InlineData("en-US", "4.2 Gio", InformationUnit.Gibioctet, 4.2)] + [InlineData("en-US", "4.2 Gb", InformationUnit.Gigabit, 4.2)] + [InlineData("en-US", "4.2 GB", InformationUnit.Gigabyte, 4.2)] + [InlineData("en-US", "4.2 Go", InformationUnit.Gigaoctet, 4.2)] + [InlineData("en-US", "4.2 Kib", InformationUnit.Kibibit, 4.2)] + [InlineData("en-US", "4.2 KiB", InformationUnit.Kibibyte, 4.2)] + [InlineData("en-US", "4.2 Kio", InformationUnit.Kibioctet, 4.2)] + [InlineData("en-US", "4.2 kb", InformationUnit.Kilobit, 4.2)] + [InlineData("en-US", "4.2 kB", InformationUnit.Kilobyte, 4.2)] + [InlineData("en-US", "4.2 ko", InformationUnit.Kilooctet, 4.2)] + [InlineData("en-US", "4.2 Mib", InformationUnit.Mebibit, 4.2)] + [InlineData("en-US", "4.2 MiB", InformationUnit.Mebibyte, 4.2)] + [InlineData("en-US", "4.2 Mio", InformationUnit.Mebioctet, 4.2)] + [InlineData("en-US", "4.2 Mb", InformationUnit.Megabit, 4.2)] + [InlineData("en-US", "4.2 MB", InformationUnit.Megabyte, 4.2)] + [InlineData("en-US", "4.2 Mo", InformationUnit.Megaoctet, 4.2)] + [InlineData("en-US", "4.2 o", InformationUnit.Octet, 4.2)] + [InlineData("en-US", "4.2 Pib", InformationUnit.Pebibit, 4.2)] + [InlineData("en-US", "4.2 PiB", InformationUnit.Pebibyte, 4.2)] + [InlineData("en-US", "4.2 Pio", InformationUnit.Pebioctet, 4.2)] + [InlineData("en-US", "4.2 Pb", InformationUnit.Petabit, 4.2)] + [InlineData("en-US", "4.2 PB", InformationUnit.Petabyte, 4.2)] + [InlineData("en-US", "4.2 Po", InformationUnit.Petaoctet, 4.2)] + [InlineData("en-US", "4.2 Tib", InformationUnit.Tebibit, 4.2)] + [InlineData("en-US", "4.2 TiB", InformationUnit.Tebibyte, 4.2)] + [InlineData("en-US", "4.2 Tio", InformationUnit.Tebioctet, 4.2)] + [InlineData("en-US", "4.2 Tb", InformationUnit.Terabit, 4.2)] + [InlineData("en-US", "4.2 TB", InformationUnit.Terabyte, 4.2)] + [InlineData("en-US", "4.2 To", InformationUnit.Teraoctet, 4.2)] + public void TryParse(string culture, string quantityString, InformationUnit expectedUnit, double expectedValue) { - { - Assert.True(Information.TryParse("1 Eo", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Exaoctets, ExaoctetsTolerance); - Assert.Equal(InformationUnit.Exaoctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Eio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Exbioctets, ExbioctetsTolerance); - Assert.Equal(InformationUnit.Exbioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Gio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gibioctets, GibioctetsTolerance); - Assert.Equal(InformationUnit.Gibioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Go", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigaoctets, GigaoctetsTolerance); - Assert.Equal(InformationUnit.Gigaoctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Kio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kibioctets, KibioctetsTolerance); - Assert.Equal(InformationUnit.Kibioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 ko", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilooctets, KilooctetsTolerance); - Assert.Equal(InformationUnit.Kilooctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Mio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mebioctets, MebioctetsTolerance); - Assert.Equal(InformationUnit.Mebioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Mo", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megaoctets, MegaoctetsTolerance); - Assert.Equal(InformationUnit.Megaoctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 o", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Octets, OctetsTolerance); - Assert.Equal(InformationUnit.Octet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Pio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pebioctets, PebioctetsTolerance); - Assert.Equal(InformationUnit.Pebioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Po", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Petaoctets, PetaoctetsTolerance); - Assert.Equal(InformationUnit.Petaoctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 Tio", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Tebioctets, TebioctetsTolerance); - Assert.Equal(InformationUnit.Tebioctet, parsed.Unit); - } - - { - Assert.True(Information.TryParse("1 To", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teraoctets, TeraoctetsTolerance); - Assert.Equal(InformationUnit.Teraoctet, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Information.TryParse(quantityString, out Information parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1177,6 +912,65 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Inform Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", InformationUnit.Bit, "b")] + [InlineData("en-US", InformationUnit.Byte, "B")] + [InlineData("en-US", InformationUnit.Exabit, "Eb")] + [InlineData("en-US", InformationUnit.Exabyte, "EB")] + [InlineData("en-US", InformationUnit.Exaoctet, "Eo")] + [InlineData("en-US", InformationUnit.Exbibit, "Eib")] + [InlineData("en-US", InformationUnit.Exbibyte, "EiB")] + [InlineData("en-US", InformationUnit.Exbioctet, "Eio")] + [InlineData("en-US", InformationUnit.Gibibit, "Gib")] + [InlineData("en-US", InformationUnit.Gibibyte, "GiB")] + [InlineData("en-US", InformationUnit.Gibioctet, "Gio")] + [InlineData("en-US", InformationUnit.Gigabit, "Gb")] + [InlineData("en-US", InformationUnit.Gigabyte, "GB")] + [InlineData("en-US", InformationUnit.Gigaoctet, "Go")] + [InlineData("en-US", InformationUnit.Kibibit, "Kib")] + [InlineData("en-US", InformationUnit.Kibibyte, "KiB")] + [InlineData("en-US", InformationUnit.Kibioctet, "Kio")] + [InlineData("en-US", InformationUnit.Kilobit, "kb")] + [InlineData("en-US", InformationUnit.Kilobyte, "kB")] + [InlineData("en-US", InformationUnit.Kilooctet, "ko")] + [InlineData("en-US", InformationUnit.Mebibit, "Mib")] + [InlineData("en-US", InformationUnit.Mebibyte, "MiB")] + [InlineData("en-US", InformationUnit.Mebioctet, "Mio")] + [InlineData("en-US", InformationUnit.Megabit, "Mb")] + [InlineData("en-US", InformationUnit.Megabyte, "MB")] + [InlineData("en-US", InformationUnit.Megaoctet, "Mo")] + [InlineData("en-US", InformationUnit.Octet, "o")] + [InlineData("en-US", InformationUnit.Pebibit, "Pib")] + [InlineData("en-US", InformationUnit.Pebibyte, "PiB")] + [InlineData("en-US", InformationUnit.Pebioctet, "Pio")] + [InlineData("en-US", InformationUnit.Petabit, "Pb")] + [InlineData("en-US", InformationUnit.Petabyte, "PB")] + [InlineData("en-US", InformationUnit.Petaoctet, "Po")] + [InlineData("en-US", InformationUnit.Tebibit, "Tib")] + [InlineData("en-US", InformationUnit.Tebibyte, "TiB")] + [InlineData("en-US", InformationUnit.Tebioctet, "Tio")] + [InlineData("en-US", InformationUnit.Terabit, "Tb")] + [InlineData("en-US", InformationUnit.Terabyte, "TB")] + [InlineData("en-US", InformationUnit.Teraoctet, "To")] + public void GetAbbreviationForCulture(string culture, InformationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Information.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Information.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Information.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(InformationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 683cf7426f..4054b20f05 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -348,172 +348,50 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/m²", IrradianceUnit.KilowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 MW/m²", IrradianceUnit.MegawattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 µW/m²", IrradianceUnit.MicrowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mW/m²", IrradianceUnit.MilliwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 nW/m²", IrradianceUnit.NanowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 pW/m²", IrradianceUnit.PicowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 W/cm²", IrradianceUnit.WattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 W/m²", IrradianceUnit.WattPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, IrradianceUnit expectedUnit, double expectedValue) { - try - { - var parsed = Irradiance.Parse("1 kW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareCentimeter, KilowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.KilowattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 kW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.KilowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 MW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerSquareCentimeter, MegawattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.MegawattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 MW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerSquareMeter, MegawattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.MegawattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 µW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareCentimeter, MicrowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.MicrowattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 µW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.MicrowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 mW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerSquareCentimeter, MilliwattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.MilliwattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 mW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.MilliwattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 nW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareCentimeter, NanowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.NanowattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 nW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.NanowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 pW/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerSquareCentimeter, PicowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.PicowattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 pW/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerSquareMeter, PicowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.PicowattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 W/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareCentimeter, WattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.WattPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiance.Parse("1 W/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.WattPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Irradiance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/m²", IrradianceUnit.KilowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 MW/m²", IrradianceUnit.MegawattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 µW/m²", IrradianceUnit.MicrowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mW/m²", IrradianceUnit.MilliwattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 nW/m²", IrradianceUnit.NanowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 pW/m²", IrradianceUnit.PicowattPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 W/cm²", IrradianceUnit.WattPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 W/m²", IrradianceUnit.WattPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, IrradianceUnit expectedUnit, double expectedValue) { - { - Assert.True(Irradiance.TryParse("1 kW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareCentimeter, KilowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.KilowattPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 kW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.KilowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 µW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareCentimeter, MicrowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.MicrowattPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 µW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.MicrowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 nW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareCentimeter, NanowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.NanowattPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 nW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.NanowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 pW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerSquareCentimeter, PicowattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.PicowattPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 pW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerSquareMeter, PicowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.PicowattPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 W/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareCentimeter, WattsPerSquareCentimeterTolerance); - Assert.Equal(IrradianceUnit.WattPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiance.TryParse("1 W/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.WattPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Irradiance.TryParse(quantityString, out Irradiance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -694,6 +572,40 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Irradi Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", IrradianceUnit.KilowattPerSquareCentimeter, "kW/cm²")] + [InlineData("en-US", IrradianceUnit.KilowattPerSquareMeter, "kW/m²")] + [InlineData("en-US", IrradianceUnit.MegawattPerSquareCentimeter, "MW/cm²")] + [InlineData("en-US", IrradianceUnit.MegawattPerSquareMeter, "MW/m²")] + [InlineData("en-US", IrradianceUnit.MicrowattPerSquareCentimeter, "µW/cm²")] + [InlineData("en-US", IrradianceUnit.MicrowattPerSquareMeter, "µW/m²")] + [InlineData("en-US", IrradianceUnit.MilliwattPerSquareCentimeter, "mW/cm²")] + [InlineData("en-US", IrradianceUnit.MilliwattPerSquareMeter, "mW/m²")] + [InlineData("en-US", IrradianceUnit.NanowattPerSquareCentimeter, "nW/cm²")] + [InlineData("en-US", IrradianceUnit.NanowattPerSquareMeter, "nW/m²")] + [InlineData("en-US", IrradianceUnit.PicowattPerSquareCentimeter, "pW/cm²")] + [InlineData("en-US", IrradianceUnit.PicowattPerSquareMeter, "pW/m²")] + [InlineData("en-US", IrradianceUnit.WattPerSquareCentimeter, "W/cm²")] + [InlineData("en-US", IrradianceUnit.WattPerSquareMeter, "W/m²")] + public void GetAbbreviationForCulture(string culture, IrradianceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Irradiance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Irradiance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Irradiance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(IrradianceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index b954f3b01b..0948307a33 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Btu/ft²", IrradiationUnit.BtuPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 J/cm²", IrradiationUnit.JoulePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 J/m²", IrradiationUnit.JoulePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 J/mm²", IrradiationUnit.JoulePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 kJ/m²", IrradiationUnit.KilojoulePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Wh/m²", IrradiationUnit.WattHourPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, IrradiationUnit expectedUnit, double expectedValue) { - try - { - var parsed = Irradiation.Parse("1 Btu/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerSquareFoot, BtusPerSquareFootTolerance); - Assert.Equal(IrradiationUnit.BtuPerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 J/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareCentimeter, JoulesPerSquareCentimeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 J/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 J/mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareMillimeter, JoulesPerSquareMillimeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 kBtu/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobtusPerSquareFoot, KilobtusPerSquareFootTolerance); - Assert.Equal(IrradiationUnit.KilobtuPerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 kJ/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerSquareMeter, KilojoulesPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.KilojoulePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 kWh/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerSquareMeter, KilowattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.KilowattHourPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 mJ/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillijoulesPerSquareCentimeter, MillijoulesPerSquareCentimeterTolerance); - Assert.Equal(IrradiationUnit.MillijoulePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Irradiation.Parse("1 Wh/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattHoursPerSquareMeter, WattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Irradiation.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Btu/ft²", IrradiationUnit.BtuPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 J/cm²", IrradiationUnit.JoulePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 J/m²", IrradiationUnit.JoulePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 J/mm²", IrradiationUnit.JoulePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 kJ/m²", IrradiationUnit.KilojoulePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Wh/m²", IrradiationUnit.WattHourPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, IrradiationUnit expectedUnit, double expectedValue) { - { - Assert.True(Irradiation.TryParse("1 Btu/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerSquareFoot, BtusPerSquareFootTolerance); - Assert.Equal(IrradiationUnit.BtuPerSquareFoot, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 J/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareCentimeter, JoulesPerSquareCentimeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 J/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 J/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerSquareMillimeter, JoulesPerSquareMillimeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 kBtu/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobtusPerSquareFoot, KilobtusPerSquareFootTolerance); - Assert.Equal(IrradiationUnit.KilobtuPerSquareFoot, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 kJ/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerSquareMeter, KilojoulesPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.KilojoulePerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 kWh/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerSquareMeter, KilowattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.KilowattHourPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 mJ/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillijoulesPerSquareCentimeter, MillijoulesPerSquareCentimeterTolerance); - Assert.Equal(IrradiationUnit.MillijoulePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Irradiation.TryParse("1 Wh/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHoursPerSquareMeter, WattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Irradiation.TryParse(quantityString, out Irradiation parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Irradi Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", IrradiationUnit.BtuPerSquareFoot, "Btu/ft²")] + [InlineData("en-US", IrradiationUnit.JoulePerSquareCentimeter, "J/cm²")] + [InlineData("en-US", IrradiationUnit.JoulePerSquareMeter, "J/m²")] + [InlineData("en-US", IrradiationUnit.JoulePerSquareMillimeter, "J/mm²")] + [InlineData("en-US", IrradiationUnit.KilobtuPerSquareFoot, "kBtu/ft²")] + [InlineData("en-US", IrradiationUnit.KilojoulePerSquareMeter, "kJ/m²")] + [InlineData("en-US", IrradiationUnit.KilowattHourPerSquareMeter, "kWh/m²")] + [InlineData("en-US", IrradiationUnit.MillijoulePerSquareCentimeter, "mJ/cm²")] + [InlineData("en-US", IrradiationUnit.WattHourPerSquareMeter, "Wh/m²")] + public void GetAbbreviationForCulture(string culture, IrradiationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Irradiation.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Irradiation.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Irradiation.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(IrradiationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index 1aaae751dc..113043f79a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -330,300 +330,66 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm/s³", JerkUnit.CentimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 dm/s³", JerkUnit.DecimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 ft/s³", JerkUnit.FootPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 in/s³", JerkUnit.InchPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 km/s³", JerkUnit.KilometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 m/s³", JerkUnit.MeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 µm/s³", JerkUnit.MicrometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 mm/s³", JerkUnit.MillimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 mg/s", JerkUnit.MillistandardGravitiesPerSecond, 4.2)] + [InlineData("en-US", "4.2 nm/s³", JerkUnit.NanometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 g/s", JerkUnit.StandardGravitiesPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см/с³", JerkUnit.CentimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 дм/с³", JerkUnit.DecimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 фут/с³", JerkUnit.FootPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 дюйм/с³", JerkUnit.InchPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 км/с³", JerkUnit.KilometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 м/с³", JerkUnit.MeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с³", JerkUnit.MicrometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мм/с³", JerkUnit.MillimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мg/s", JerkUnit.MillistandardGravitiesPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нм/с³", JerkUnit.NanometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 g/s", JerkUnit.StandardGravitiesPerSecond, 4.2)] + public void Parse(string culture, string quantityString, JerkUnit expectedUnit, double expectedValue) { - try - { - var parsed = Jerk.Parse("1 cm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondCubed, CentimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 см/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondCubed, CentimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 dm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondCubed, DecimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 дм/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondCubed, DecimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 ft/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondCubed, FeetPerSecondCubedTolerance); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 фут/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondCubed, FeetPerSecondCubedTolerance); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 in/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondCubed, InchesPerSecondCubedTolerance); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 дюйм/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondCubed, InchesPerSecondCubedTolerance); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 km/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondCubed, KilometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 км/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondCubed, KilometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 m/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondCubed, MetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 м/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondCubed, MetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 µm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondCubed, MicrometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 мкм/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondCubed, MicrometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 mm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondCubed, MillimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 мм/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondCubed, MillimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 mg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillistandardGravitiesPerSecond, MillistandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 мg/s", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillistandardGravitiesPerSecond, MillistandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 nm/s³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondCubed, NanometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 нм/с³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondCubed, NanometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 g/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardGravitiesPerSecond, StandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Jerk.Parse("1 g/s", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.StandardGravitiesPerSecond, StandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Jerk.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm/s³", JerkUnit.CentimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 dm/s³", JerkUnit.DecimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 ft/s³", JerkUnit.FootPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 in/s³", JerkUnit.InchPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 km/s³", JerkUnit.KilometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 m/s³", JerkUnit.MeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 µm/s³", JerkUnit.MicrometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 mm/s³", JerkUnit.MillimeterPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 mg/s", JerkUnit.MillistandardGravitiesPerSecond, 4.2)] + [InlineData("en-US", "4.2 nm/s³", JerkUnit.NanometerPerSecondCubed, 4.2)] + [InlineData("en-US", "4.2 g/s", JerkUnit.StandardGravitiesPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см/с³", JerkUnit.CentimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 дм/с³", JerkUnit.DecimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 фут/с³", JerkUnit.FootPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 дюйм/с³", JerkUnit.InchPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 км/с³", JerkUnit.KilometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 м/с³", JerkUnit.MeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с³", JerkUnit.MicrometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мм/с³", JerkUnit.MillimeterPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 мg/s", JerkUnit.MillistandardGravitiesPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нм/с³", JerkUnit.NanometerPerSecondCubed, 4.2)] + [InlineData("ru-RU", "4,2 g/s", JerkUnit.StandardGravitiesPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, JerkUnit expectedUnit, double expectedValue) { - { - Assert.True(Jerk.TryParse("1 cm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondCubed, CentimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 см/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecondCubed, CentimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 dm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondCubed, DecimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 дм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecondCubed, DecimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 ft/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondCubed, FeetPerSecondCubedTolerance); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 фут/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecondCubed, FeetPerSecondCubedTolerance); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 in/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondCubed, InchesPerSecondCubedTolerance); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 дюйм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerSecondCubed, InchesPerSecondCubedTolerance); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 km/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondCubed, KilometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 км/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecondCubed, KilometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 m/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondCubed, MetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 м/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecondCubed, MetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 µm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondCubed, MicrometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 мкм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecondCubed, MicrometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 mm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondCubed, MillimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 мм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecondCubed, MillimetersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 mg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillistandardGravitiesPerSecond, MillistandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 мg/s", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillistandardGravitiesPerSecond, MillistandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 nm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondCubed, NanometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 нм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecondCubed, NanometersPerSecondCubedTolerance); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 g/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardGravitiesPerSecond, StandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsed.Unit); - } - - { - Assert.True(Jerk.TryParse("1 g/s", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardGravitiesPerSecond, StandardGravitiesPerSecondTolerance); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Jerk.TryParse(quantityString, out Jerk parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -824,6 +590,48 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, JerkUn Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", JerkUnit.CentimeterPerSecondCubed, "cm/s³")] + [InlineData("en-US", JerkUnit.DecimeterPerSecondCubed, "dm/s³")] + [InlineData("en-US", JerkUnit.FootPerSecondCubed, "ft/s³")] + [InlineData("en-US", JerkUnit.InchPerSecondCubed, "in/s³")] + [InlineData("en-US", JerkUnit.KilometerPerSecondCubed, "km/s³")] + [InlineData("en-US", JerkUnit.MeterPerSecondCubed, "m/s³")] + [InlineData("en-US", JerkUnit.MicrometerPerSecondCubed, "µm/s³")] + [InlineData("en-US", JerkUnit.MillimeterPerSecondCubed, "mm/s³")] + [InlineData("en-US", JerkUnit.MillistandardGravitiesPerSecond, "mg/s")] + [InlineData("en-US", JerkUnit.NanometerPerSecondCubed, "nm/s³")] + [InlineData("en-US", JerkUnit.StandardGravitiesPerSecond, "g/s")] + [InlineData("ru-RU", JerkUnit.CentimeterPerSecondCubed, "см/с³")] + [InlineData("ru-RU", JerkUnit.DecimeterPerSecondCubed, "дм/с³")] + [InlineData("ru-RU", JerkUnit.FootPerSecondCubed, "фут/с³")] + [InlineData("ru-RU", JerkUnit.InchPerSecondCubed, "дюйм/с³")] + [InlineData("ru-RU", JerkUnit.KilometerPerSecondCubed, "км/с³")] + [InlineData("ru-RU", JerkUnit.MeterPerSecondCubed, "м/с³")] + [InlineData("ru-RU", JerkUnit.MicrometerPerSecondCubed, "мкм/с³")] + [InlineData("ru-RU", JerkUnit.MillimeterPerSecondCubed, "мм/с³")] + [InlineData("ru-RU", JerkUnit.MillistandardGravitiesPerSecond, "мg/s")] + [InlineData("ru-RU", JerkUnit.NanometerPerSecondCubed, "нм/с³")] + [InlineData("ru-RU", JerkUnit.StandardGravitiesPerSecond, "g/s")] + public void GetAbbreviationForCulture(string culture, JerkUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Jerk.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Jerk.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Jerk.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(JerkUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index 33d3fc53f6..789f19509b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -318,235 +318,56 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cSt", KinematicViscosityUnit.Centistokes, 4.2)] + [InlineData("en-US", "4.2 dSt", KinematicViscosityUnit.Decistokes, 4.2)] + [InlineData("en-US", "4.2 kSt", KinematicViscosityUnit.Kilostokes, 4.2)] + [InlineData("en-US", "4.2 µSt", KinematicViscosityUnit.Microstokes, 4.2)] + [InlineData("en-US", "4.2 mSt", KinematicViscosityUnit.Millistokes, 4.2)] + [InlineData("en-US", "4.2 nSt", KinematicViscosityUnit.Nanostokes, 4.2)] + [InlineData("en-US", "4.2 ft²/s", KinematicViscosityUnit.SquareFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 m²/s", KinematicViscosityUnit.SquareMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 St", KinematicViscosityUnit.Stokes, 4.2)] + [InlineData("ru-RU", "4,2 сСт", KinematicViscosityUnit.Centistokes, 4.2)] + [InlineData("ru-RU", "4,2 дСт", KinematicViscosityUnit.Decistokes, 4.2)] + [InlineData("ru-RU", "4,2 кСт", KinematicViscosityUnit.Kilostokes, 4.2)] + [InlineData("ru-RU", "4,2 мкСт", KinematicViscosityUnit.Microstokes, 4.2)] + [InlineData("ru-RU", "4,2 мСт", KinematicViscosityUnit.Millistokes, 4.2)] + [InlineData("ru-RU", "4,2 нСт", KinematicViscosityUnit.Nanostokes, 4.2)] + [InlineData("ru-RU", "4,2 м²/с", KinematicViscosityUnit.SquareMeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Ст", KinematicViscosityUnit.Stokes, 4.2)] + public void Parse(string culture, string quantityString, KinematicViscosityUnit expectedUnit, double expectedValue) { - try - { - var parsed = KinematicViscosity.Parse("1 cSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centistokes, CentistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 сСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centistokes, CentistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 dSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decistokes, DecistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 дСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decistokes, DecistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 kSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilostokes, KilostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 кСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilostokes, KilostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 µSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microstokes, MicrostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 мкСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microstokes, MicrostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 mSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millistokes, MillistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 мСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millistokes, MillistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 nSt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanostokes, NanostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 нСт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanostokes, NanostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 ft²/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareFeetPerSecond, SquareFeetPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 m²/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 м²/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 St", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Stokes, StokesTolerance); - Assert.Equal(KinematicViscosityUnit.Stokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = KinematicViscosity.Parse("1 Ст", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Stokes, StokesTolerance); - Assert.Equal(KinematicViscosityUnit.Stokes, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = KinematicViscosity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cSt", KinematicViscosityUnit.Centistokes, 4.2)] + [InlineData("en-US", "4.2 dSt", KinematicViscosityUnit.Decistokes, 4.2)] + [InlineData("en-US", "4.2 kSt", KinematicViscosityUnit.Kilostokes, 4.2)] + [InlineData("en-US", "4.2 µSt", KinematicViscosityUnit.Microstokes, 4.2)] + [InlineData("en-US", "4.2 mSt", KinematicViscosityUnit.Millistokes, 4.2)] + [InlineData("en-US", "4.2 nSt", KinematicViscosityUnit.Nanostokes, 4.2)] + [InlineData("en-US", "4.2 ft²/s", KinematicViscosityUnit.SquareFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 m²/s", KinematicViscosityUnit.SquareMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 St", KinematicViscosityUnit.Stokes, 4.2)] + [InlineData("ru-RU", "4,2 сСт", KinematicViscosityUnit.Centistokes, 4.2)] + [InlineData("ru-RU", "4,2 дСт", KinematicViscosityUnit.Decistokes, 4.2)] + [InlineData("ru-RU", "4,2 кСт", KinematicViscosityUnit.Kilostokes, 4.2)] + [InlineData("ru-RU", "4,2 мкСт", KinematicViscosityUnit.Microstokes, 4.2)] + [InlineData("ru-RU", "4,2 мСт", KinematicViscosityUnit.Millistokes, 4.2)] + [InlineData("ru-RU", "4,2 нСт", KinematicViscosityUnit.Nanostokes, 4.2)] + [InlineData("ru-RU", "4,2 м²/с", KinematicViscosityUnit.SquareMeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Ст", KinematicViscosityUnit.Stokes, 4.2)] + public void TryParse(string culture, string quantityString, KinematicViscosityUnit expectedUnit, double expectedValue) { - { - Assert.True(KinematicViscosity.TryParse("1 cSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centistokes, CentistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 сСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centistokes, CentistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 dSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decistokes, DecistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 дСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decistokes, DecistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 kSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilostokes, KilostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 кСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilostokes, KilostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 µSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microstokes, MicrostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 мкСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microstokes, MicrostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 mSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millistokes, MillistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 мСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millistokes, MillistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 nSt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanostokes, NanostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 нСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanostokes, NanostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 ft²/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareFeetPerSecond, SquareFeetPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareFootPerSecond, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 m²/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 м²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 St", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Stokes, StokesTolerance); - Assert.Equal(KinematicViscosityUnit.Stokes, parsed.Unit); - } - - { - Assert.True(KinematicViscosity.TryParse("1 Ст", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Stokes, StokesTolerance); - Assert.Equal(KinematicViscosityUnit.Stokes, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(KinematicViscosity.TryParse(quantityString, out KinematicViscosity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -719,6 +540,43 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Kinema Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", KinematicViscosityUnit.Centistokes, "cSt")] + [InlineData("en-US", KinematicViscosityUnit.Decistokes, "dSt")] + [InlineData("en-US", KinematicViscosityUnit.Kilostokes, "kSt")] + [InlineData("en-US", KinematicViscosityUnit.Microstokes, "µSt")] + [InlineData("en-US", KinematicViscosityUnit.Millistokes, "mSt")] + [InlineData("en-US", KinematicViscosityUnit.Nanostokes, "nSt")] + [InlineData("en-US", KinematicViscosityUnit.SquareFootPerSecond, "ft²/s")] + [InlineData("en-US", KinematicViscosityUnit.SquareMeterPerSecond, "m²/s")] + [InlineData("en-US", KinematicViscosityUnit.Stokes, "St")] + [InlineData("ru-RU", KinematicViscosityUnit.Centistokes, "сСт")] + [InlineData("ru-RU", KinematicViscosityUnit.Decistokes, "дСт")] + [InlineData("ru-RU", KinematicViscosityUnit.Kilostokes, "кСт")] + [InlineData("ru-RU", KinematicViscosityUnit.Microstokes, "мкСт")] + [InlineData("ru-RU", KinematicViscosityUnit.Millistokes, "мСт")] + [InlineData("ru-RU", KinematicViscosityUnit.Nanostokes, "нСт")] + [InlineData("ru-RU", KinematicViscosityUnit.SquareMeterPerSecond, "м²/с")] + [InlineData("ru-RU", KinematicViscosityUnit.Stokes, "Ст")] + public void GetAbbreviationForCulture(string culture, KinematicViscosityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = KinematicViscosity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(KinematicViscosity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = KinematicViscosity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(KinematicViscosityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs index 5d7dc4f356..891373c96f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs @@ -288,66 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 atm·cm³/s", LeakRateUnit.AtmCubicCentimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mbar·l/s", LeakRateUnit.MillibarLiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Torr·l/s", LeakRateUnit.TorrLiterPerSecond, 4.2)] + public void Parse(string culture, string quantityString, LeakRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = LeakRate.Parse("1 atm·cm³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AtmCubicCentimetersPerSecond, AtmCubicCentimetersPerSecondTolerance); - Assert.Equal(LeakRateUnit.AtmCubicCentimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LeakRate.Parse("1 mbar·l/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillibarLitersPerSecond, MillibarLitersPerSecondTolerance); - Assert.Equal(LeakRateUnit.MillibarLiterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LeakRate.Parse("1 Pa·m³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalCubicMetersPerSecond, PascalCubicMetersPerSecondTolerance); - Assert.Equal(LeakRateUnit.PascalCubicMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LeakRate.Parse("1 Torr·l/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TorrLitersPerSecond, TorrLitersPerSecondTolerance); - Assert.Equal(LeakRateUnit.TorrLiterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = LeakRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 atm·cm³/s", LeakRateUnit.AtmCubicCentimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mbar·l/s", LeakRateUnit.MillibarLiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Torr·l/s", LeakRateUnit.TorrLiterPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, LeakRateUnit expectedUnit, double expectedValue) { - { - Assert.True(LeakRate.TryParse("1 atm·cm³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AtmCubicCentimetersPerSecond, AtmCubicCentimetersPerSecondTolerance); - Assert.Equal(LeakRateUnit.AtmCubicCentimeterPerSecond, parsed.Unit); - } - - { - Assert.True(LeakRate.TryParse("1 mbar·l/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillibarLitersPerSecond, MillibarLitersPerSecondTolerance); - Assert.Equal(LeakRateUnit.MillibarLiterPerSecond, parsed.Unit); - } - - { - Assert.True(LeakRate.TryParse("1 Pa·m³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalCubicMetersPerSecond, PascalCubicMetersPerSecondTolerance); - Assert.Equal(LeakRateUnit.PascalCubicMeterPerSecond, parsed.Unit); - } - - { - Assert.True(LeakRate.TryParse("1 Torr·l/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TorrLitersPerSecond, TorrLitersPerSecondTolerance); - Assert.Equal(LeakRateUnit.TorrLiterPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(LeakRate.TryParse(quantityString, out LeakRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -448,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, LeakRa Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LeakRateUnit.AtmCubicCentimeterPerSecond, "atm·cm³/s")] + [InlineData("en-US", LeakRateUnit.MillibarLiterPerSecond, "mbar·l/s")] + [InlineData("en-US", LeakRateUnit.PascalCubicMeterPerSecond, "Pa·m³/s")] + [InlineData("en-US", LeakRateUnit.TorrLiterPerSecond, "Torr·l/s")] + public void GetAbbreviationForCulture(string culture, LeakRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = LeakRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(LeakRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = LeakRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LeakRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 17b71c83bb..03197ee137 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -516,1154 +516,218 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Å", LengthUnit.Angstrom, 4.2)] + [InlineData("en-US", "4.2 A", LengthUnit.Angstrom, 4.2)] + [InlineData("en-US", "4.2 au", LengthUnit.AstronomicalUnit, 4.2)] + [InlineData("en-US", "4.2 ua", LengthUnit.AstronomicalUnit, 4.2)] + [InlineData("en-US", "4.2 cm", LengthUnit.Centimeter, 4.2)] + [InlineData("en-US", "4.2 ch", LengthUnit.Chain, 4.2)] + [InlineData("en-US", "4.2 DM", LengthUnit.DataMile, 4.2)] + [InlineData("en-US", "4.2 dam", LengthUnit.Decameter, 4.2)] + [InlineData("en-US", "4.2 dm", LengthUnit.Decimeter, 4.2)] + [InlineData("en-US", "4.2 fathom", LengthUnit.Fathom, 4.2)] + [InlineData("en-US", "4.2 fm", LengthUnit.Femtometer, 4.2)] + [InlineData("en-US", "4.2 ft", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 '", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 ′", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 Gm", LengthUnit.Gigameter, 4.2)] + [InlineData("en-US", "4.2 h", LengthUnit.Hand, 4.2)] + [InlineData("en-US", "4.2 hh", LengthUnit.Hand, 4.2)] + [InlineData("en-US", "4.2 hm", LengthUnit.Hectometer, 4.2)] + [InlineData("en-US", "4.2 in", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 \"", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 ″", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 kft", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 k'", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 k′", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 kly", LengthUnit.KilolightYear, 4.2)] + [InlineData("en-US", "4.2 km", LengthUnit.Kilometer, 4.2)] + [InlineData("en-US", "4.2 kpc", LengthUnit.Kiloparsec, 4.2)] + [InlineData("en-US", "4.2 kyd", LengthUnit.Kiloyard, 4.2)] + [InlineData("en-US", "4.2 ly", LengthUnit.LightYear, 4.2)] + [InlineData("en-US", "4.2 Mly", LengthUnit.MegalightYear, 4.2)] + [InlineData("en-US", "4.2 Mm", LengthUnit.Megameter, 4.2)] + [InlineData("en-US", "4.2 Mpc", LengthUnit.Megaparsec, 4.2)] + [InlineData("en-US", "4.2 m", LengthUnit.Meter, 4.2)] + [InlineData("en-US", "4.2 µin", LengthUnit.Microinch, 4.2)] + [InlineData("en-US", "4.2 µm", LengthUnit.Micrometer, 4.2)] + [InlineData("en-US", "4.2 mil", LengthUnit.Mil, 4.2)] + [InlineData("en-US", "4.2 mi", LengthUnit.Mile, 4.2)] + [InlineData("en-US", "4.2 mm", LengthUnit.Millimeter, 4.2)] + [InlineData("en-US", "4.2 nm", LengthUnit.Nanometer, 4.2)] + [InlineData("en-US", "4.2 NM", LengthUnit.NauticalMile, 4.2)] + [InlineData("en-US", "4.2 nmi", LengthUnit.NauticalMile, 4.2)] + [InlineData("en-US", "4.2 pc", LengthUnit.Parsec, 4.2)] + [InlineData("en-US", "4.2 pm", LengthUnit.Picometer, 4.2)] + [InlineData("en-US", "4.2 shackle", LengthUnit.Shackle, 4.2)] + [InlineData("en-US", "4.2 R⊙", LengthUnit.SolarRadius, 4.2)] + [InlineData("en-US", "4.2 twip", LengthUnit.Twip, 4.2)] + [InlineData("en-US", "4.2 ftUS", LengthUnit.UsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 yd", LengthUnit.Yard, 4.2)] + [InlineData("ru-RU", "4,2 см", LengthUnit.Centimeter, 4.2)] + [InlineData("ru-RU", "4,2 дам", LengthUnit.Decameter, 4.2)] + [InlineData("ru-RU", "4,2 дм", LengthUnit.Decimeter, 4.2)] + [InlineData("ru-RU", "4,2 фм", LengthUnit.Femtometer, 4.2)] + [InlineData("ru-RU", "4,2 фут", LengthUnit.Foot, 4.2)] + [InlineData("ru-RU", "4,2 Гм", LengthUnit.Gigameter, 4.2)] + [InlineData("ru-RU", "4,2 гм", LengthUnit.Hectometer, 4.2)] + [InlineData("ru-RU", "4,2 дюйм", LengthUnit.Inch, 4.2)] + [InlineData("ru-RU", "4,2 кфут", LengthUnit.Kilofoot, 4.2)] + [InlineData("ru-RU", "4,2 км", LengthUnit.Kilometer, 4.2)] + [InlineData("ru-RU", "4,2 кярд", LengthUnit.Kiloyard, 4.2)] + [InlineData("ru-RU", "4,2 Мм", LengthUnit.Megameter, 4.2)] + [InlineData("ru-RU", "4,2 м", LengthUnit.Meter, 4.2)] + [InlineData("ru-RU", "4,2 микродюйм", LengthUnit.Microinch, 4.2)] + [InlineData("ru-RU", "4,2 мкм", LengthUnit.Micrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля", LengthUnit.Mile, 4.2)] + [InlineData("ru-RU", "4,2 мм", LengthUnit.Millimeter, 4.2)] + [InlineData("ru-RU", "4,2 нм", LengthUnit.Nanometer, 4.2)] + [InlineData("ru-RU", "4,2 пм", LengthUnit.Picometer, 4.2)] + [InlineData("ru-RU", "4,2 ярд", LengthUnit.Yard, 4.2)] + [InlineData("zh-CN", "4.2 厘米", LengthUnit.Centimeter, 4.2)] + [InlineData("zh-CN", "4.2 十米", LengthUnit.Decameter, 4.2)] + [InlineData("zh-CN", "4.2 分米", LengthUnit.Decimeter, 4.2)] + [InlineData("zh-CN", "4.2 飞米", LengthUnit.Femtometer, 4.2)] + [InlineData("zh-CN", "4.2 英尺", LengthUnit.Foot, 4.2)] + [InlineData("zh-CN", "4.2 吉米", LengthUnit.Gigameter, 4.2)] + [InlineData("zh-CN", "4.2 百米", LengthUnit.Hectometer, 4.2)] + [InlineData("zh-CN", "4.2 英寸", LengthUnit.Inch, 4.2)] + [InlineData("zh-CN", "4.2 千英尺", LengthUnit.Kilofoot, 4.2)] + [InlineData("zh-CN", "4.2 千米", LengthUnit.Kilometer, 4.2)] + [InlineData("zh-CN", "4.2 千码", LengthUnit.Kiloyard, 4.2)] + [InlineData("zh-CN", "4.2 兆米", LengthUnit.Megameter, 4.2)] + [InlineData("zh-CN", "4.2 米", LengthUnit.Meter, 4.2)] + [InlineData("zh-CN", "4.2 微英寸", LengthUnit.Microinch, 4.2)] + [InlineData("zh-CN", "4.2 微米", LengthUnit.Micrometer, 4.2)] + [InlineData("zh-CN", "4.2 密耳", LengthUnit.Mil, 4.2)] + [InlineData("zh-CN", "4.2 英里", LengthUnit.Mile, 4.2)] + [InlineData("zh-CN", "4.2 毫米", LengthUnit.Millimeter, 4.2)] + [InlineData("zh-CN", "4.2 皮米", LengthUnit.Picometer, 4.2)] + [InlineData("zh-CN", "4.2 码", LengthUnit.Yard, 4.2)] + public void Parse(string culture, string quantityString, LengthUnit expectedUnit, double expectedValue) { - try - { - var parsed = Length.Parse("1 Å", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Angstroms, AngstromsTolerance); - Assert.Equal(LengthUnit.Angstrom, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 A", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Angstroms, AngstromsTolerance); - Assert.Equal(LengthUnit.Angstrom, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 au", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AstronomicalUnits, AstronomicalUnitsTolerance); - Assert.Equal(LengthUnit.AstronomicalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ua", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AstronomicalUnits, AstronomicalUnitsTolerance); - Assert.Equal(LengthUnit.AstronomicalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 см", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 厘米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ch", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Chains, ChainsTolerance); - Assert.Equal(LengthUnit.Chain, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 DM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DataMiles, DataMilesTolerance); - Assert.Equal(LengthUnit.DataMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 dam", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 дам", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 十米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 dm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 дм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 分米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pica", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DtpPicas, DtpPicasTolerance); - Assert.Equal(LengthUnit.DtpPica, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DtpPoints, DtpPointsTolerance); - Assert.Equal(LengthUnit.DtpPoint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 fathom", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Fathoms, FathomsTolerance); - Assert.Equal(LengthUnit.Fathom, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 fm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 фм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 飞米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 '", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ′", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 фут", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 英尺", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Gm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigameters, GigametersTolerance); - Assert.Equal(LengthUnit.Gigameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Гм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigameters, GigametersTolerance); - Assert.Equal(LengthUnit.Gigameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 吉米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Gigameters, GigametersTolerance); - Assert.Equal(LengthUnit.Gigameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hands, HandsTolerance); - Assert.Equal(LengthUnit.Hand, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 hh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hands, HandsTolerance); - Assert.Equal(LengthUnit.Hand, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 hm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 гм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 百米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 \"", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ″", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 дюйм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 英寸", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 kft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 k'", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 k′", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 кфут", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 千英尺", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 kly", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolightYears, KilolightYearsTolerance); - Assert.Equal(LengthUnit.KilolightYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 км", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 千米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 kpc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloparsecs, KiloparsecsTolerance); - Assert.Equal(LengthUnit.Kiloparsec, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 kyd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 кярд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 千码", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ly", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LightYears, LightYearsTolerance); - Assert.Equal(LengthUnit.LightYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Mly", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalightYears, MegalightYearsTolerance); - Assert.Equal(LengthUnit.MegalightYear, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megameters, MegametersTolerance); - Assert.Equal(LengthUnit.Megameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Мм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megameters, MegametersTolerance); - Assert.Equal(LengthUnit.Megameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 兆米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Megameters, MegametersTolerance); - Assert.Equal(LengthUnit.Megameter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 Mpc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaparsecs, MegaparsecsTolerance); - Assert.Equal(LengthUnit.Megaparsec, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 µin", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 микродюйм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 微英寸", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 µm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 мкм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 微米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 mil", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 мил", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 密耳", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 mi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 миля", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 英里", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millimeters, MillimetersTolerance); - Assert.Equal(LengthUnit.Millimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 мм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millimeters, MillimetersTolerance); - Assert.Equal(LengthUnit.Millimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 毫米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Millimeters, MillimetersTolerance); - Assert.Equal(LengthUnit.Millimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 nm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanometers, NanometersTolerance); - Assert.Equal(LengthUnit.Nanometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 нм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanometers, NanometersTolerance); - Assert.Equal(LengthUnit.Nanometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 纳米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Nanometers, NanometersTolerance); - Assert.Equal(LengthUnit.Nanometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 NM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 nmi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 мил", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 纳米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Parsecs, ParsecsTolerance); - Assert.Equal(LengthUnit.Parsec, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 пм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 皮米", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pica", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PrinterPicas, PrinterPicasTolerance); - Assert.Equal(LengthUnit.PrinterPica, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 pt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PrinterPoints, PrinterPointsTolerance); - Assert.Equal(LengthUnit.PrinterPoint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 shackle", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Shackles, ShacklesTolerance); - Assert.Equal(LengthUnit.Shackle, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 R⊙", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SolarRadiuses, SolarRadiusesTolerance); - Assert.Equal(LengthUnit.SolarRadius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 twip", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Twips, TwipsTolerance); - Assert.Equal(LengthUnit.Twip, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ftUS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeet, UsSurveyFeetTolerance); - Assert.Equal(LengthUnit.UsSurveyFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 yd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 ярд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Length.Parse("1 码", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Length.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "1 pica")] // [DtpPica, PrinterPica] + [InlineData("en-US", "1 pt")] // [DtpPoint, PrinterPoint] + [InlineData("ru-RU", "1 мил")] // [Mil, NauticalMile] + [InlineData("zh-CN", "1 纳米")] // [Nanometer, NauticalMile] + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) { - { - Assert.True(Length.TryParse("1 Å", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Angstroms, AngstromsTolerance); - Assert.Equal(LengthUnit.Angstrom, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 A", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Angstroms, AngstromsTolerance); - Assert.Equal(LengthUnit.Angstrom, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 au", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AstronomicalUnits, AstronomicalUnitsTolerance); - Assert.Equal(LengthUnit.AstronomicalUnit, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ua", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AstronomicalUnits, AstronomicalUnitsTolerance); - Assert.Equal(LengthUnit.AstronomicalUnit, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 см", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 厘米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ch", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Chains, ChainsTolerance); - Assert.Equal(LengthUnit.Chain, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 dam", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 дам", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 十米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 дм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 分米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 fathom", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Fathoms, FathomsTolerance); - Assert.Equal(LengthUnit.Fathom, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 fm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 фм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 飞米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtometers, FemtometersTolerance); - Assert.Equal(LengthUnit.Femtometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 '", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ′", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 фут", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 Gm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigameters, GigametersTolerance); - Assert.Equal(LengthUnit.Gigameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 吉米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigameters, GigametersTolerance); - Assert.Equal(LengthUnit.Gigameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hands, HandsTolerance); - Assert.Equal(LengthUnit.Hand, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 hh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hands, HandsTolerance); - Assert.Equal(LengthUnit.Hand, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 hm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 百米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 \"", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ″", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 дюйм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 kft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 k'", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 k′", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 кфут", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 千英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofeet, KilofeetTolerance); - Assert.Equal(LengthUnit.Kilofoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 kly", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolightYears, KilolightYearsTolerance); - Assert.Equal(LengthUnit.KilolightYear, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 км", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 千米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 kpc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloparsecs, KiloparsecsTolerance); - Assert.Equal(LengthUnit.Kiloparsec, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 kyd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 кярд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 千码", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloyards, KiloyardsTolerance); - Assert.Equal(LengthUnit.Kiloyard, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ly", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LightYears, LightYearsTolerance); - Assert.Equal(LengthUnit.LightYear, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 Mly", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegalightYears, MegalightYearsTolerance); - Assert.Equal(LengthUnit.MegalightYear, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 兆米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megameters, MegametersTolerance); - Assert.Equal(LengthUnit.Megameter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 Mpc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megaparsecs, MegaparsecsTolerance); - Assert.Equal(LengthUnit.Megaparsec, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 µin", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 микродюйм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 微英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 µm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 мкм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 微米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 mil", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 密耳", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 mi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 миля", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 英里", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 毫米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millimeters, MillimetersTolerance); - Assert.Equal(LengthUnit.Millimeter, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 нм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanometers, NanometersTolerance); - Assert.Equal(LengthUnit.Nanometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 nmi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 pc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Parsecs, ParsecsTolerance); - Assert.Equal(LengthUnit.Parsec, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 pm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 пм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 皮米", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picometers, PicometersTolerance); - Assert.Equal(LengthUnit.Picometer, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 shackle", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Shackles, ShacklesTolerance); - Assert.Equal(LengthUnit.Shackle, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 R⊙", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SolarRadiuses, SolarRadiusesTolerance); - Assert.Equal(LengthUnit.SolarRadius, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 twip", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Twips, TwipsTolerance); - Assert.Equal(LengthUnit.Twip, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeet, UsSurveyFeetTolerance); - Assert.Equal(LengthUnit.UsSurveyFoot, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 yd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } - - { - Assert.True(Length.TryParse("1 ярд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } + Assert.Throws(() => Length.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Length.TryParse("1 码", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 Å", LengthUnit.Angstrom, 4.2)] + [InlineData("en-US", "4.2 A", LengthUnit.Angstrom, 4.2)] + [InlineData("en-US", "4.2 au", LengthUnit.AstronomicalUnit, 4.2)] + [InlineData("en-US", "4.2 ua", LengthUnit.AstronomicalUnit, 4.2)] + [InlineData("en-US", "4.2 cm", LengthUnit.Centimeter, 4.2)] + [InlineData("en-US", "4.2 ch", LengthUnit.Chain, 4.2)] + [InlineData("en-US", "4.2 DM", LengthUnit.DataMile, 4.2)] + [InlineData("en-US", "4.2 dam", LengthUnit.Decameter, 4.2)] + [InlineData("en-US", "4.2 dm", LengthUnit.Decimeter, 4.2)] + [InlineData("en-US", "4.2 fathom", LengthUnit.Fathom, 4.2)] + [InlineData("en-US", "4.2 fm", LengthUnit.Femtometer, 4.2)] + [InlineData("en-US", "4.2 ft", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 '", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 ′", LengthUnit.Foot, 4.2)] + [InlineData("en-US", "4.2 Gm", LengthUnit.Gigameter, 4.2)] + [InlineData("en-US", "4.2 h", LengthUnit.Hand, 4.2)] + [InlineData("en-US", "4.2 hh", LengthUnit.Hand, 4.2)] + [InlineData("en-US", "4.2 hm", LengthUnit.Hectometer, 4.2)] + [InlineData("en-US", "4.2 in", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 \"", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 ″", LengthUnit.Inch, 4.2)] + [InlineData("en-US", "4.2 kft", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 k'", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 k′", LengthUnit.Kilofoot, 4.2)] + [InlineData("en-US", "4.2 kly", LengthUnit.KilolightYear, 4.2)] + [InlineData("en-US", "4.2 km", LengthUnit.Kilometer, 4.2)] + [InlineData("en-US", "4.2 kpc", LengthUnit.Kiloparsec, 4.2)] + [InlineData("en-US", "4.2 kyd", LengthUnit.Kiloyard, 4.2)] + [InlineData("en-US", "4.2 ly", LengthUnit.LightYear, 4.2)] + [InlineData("en-US", "4.2 Mly", LengthUnit.MegalightYear, 4.2)] + [InlineData("en-US", "4.2 Mm", LengthUnit.Megameter, 4.2)] + [InlineData("en-US", "4.2 Mpc", LengthUnit.Megaparsec, 4.2)] + [InlineData("en-US", "4.2 m", LengthUnit.Meter, 4.2)] + [InlineData("en-US", "4.2 µin", LengthUnit.Microinch, 4.2)] + [InlineData("en-US", "4.2 µm", LengthUnit.Micrometer, 4.2)] + [InlineData("en-US", "4.2 mil", LengthUnit.Mil, 4.2)] + [InlineData("en-US", "4.2 mi", LengthUnit.Mile, 4.2)] + [InlineData("en-US", "4.2 mm", LengthUnit.Millimeter, 4.2)] + [InlineData("en-US", "4.2 nm", LengthUnit.Nanometer, 4.2)] + [InlineData("en-US", "4.2 NM", LengthUnit.NauticalMile, 4.2)] + [InlineData("en-US", "4.2 nmi", LengthUnit.NauticalMile, 4.2)] + [InlineData("en-US", "4.2 pc", LengthUnit.Parsec, 4.2)] + [InlineData("en-US", "4.2 pm", LengthUnit.Picometer, 4.2)] + [InlineData("en-US", "4.2 shackle", LengthUnit.Shackle, 4.2)] + [InlineData("en-US", "4.2 R⊙", LengthUnit.SolarRadius, 4.2)] + [InlineData("en-US", "4.2 twip", LengthUnit.Twip, 4.2)] + [InlineData("en-US", "4.2 ftUS", LengthUnit.UsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 yd", LengthUnit.Yard, 4.2)] + [InlineData("ru-RU", "4,2 см", LengthUnit.Centimeter, 4.2)] + [InlineData("ru-RU", "4,2 дам", LengthUnit.Decameter, 4.2)] + [InlineData("ru-RU", "4,2 дм", LengthUnit.Decimeter, 4.2)] + [InlineData("ru-RU", "4,2 фм", LengthUnit.Femtometer, 4.2)] + [InlineData("ru-RU", "4,2 фут", LengthUnit.Foot, 4.2)] + [InlineData("ru-RU", "4,2 Гм", LengthUnit.Gigameter, 4.2)] + [InlineData("ru-RU", "4,2 гм", LengthUnit.Hectometer, 4.2)] + [InlineData("ru-RU", "4,2 дюйм", LengthUnit.Inch, 4.2)] + [InlineData("ru-RU", "4,2 кфут", LengthUnit.Kilofoot, 4.2)] + [InlineData("ru-RU", "4,2 км", LengthUnit.Kilometer, 4.2)] + [InlineData("ru-RU", "4,2 кярд", LengthUnit.Kiloyard, 4.2)] + [InlineData("ru-RU", "4,2 Мм", LengthUnit.Megameter, 4.2)] + [InlineData("ru-RU", "4,2 м", LengthUnit.Meter, 4.2)] + [InlineData("ru-RU", "4,2 микродюйм", LengthUnit.Microinch, 4.2)] + [InlineData("ru-RU", "4,2 мкм", LengthUnit.Micrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля", LengthUnit.Mile, 4.2)] + [InlineData("ru-RU", "4,2 мм", LengthUnit.Millimeter, 4.2)] + [InlineData("ru-RU", "4,2 нм", LengthUnit.Nanometer, 4.2)] + [InlineData("ru-RU", "4,2 пм", LengthUnit.Picometer, 4.2)] + [InlineData("ru-RU", "4,2 ярд", LengthUnit.Yard, 4.2)] + [InlineData("zh-CN", "4.2 厘米", LengthUnit.Centimeter, 4.2)] + [InlineData("zh-CN", "4.2 十米", LengthUnit.Decameter, 4.2)] + [InlineData("zh-CN", "4.2 分米", LengthUnit.Decimeter, 4.2)] + [InlineData("zh-CN", "4.2 飞米", LengthUnit.Femtometer, 4.2)] + [InlineData("zh-CN", "4.2 英尺", LengthUnit.Foot, 4.2)] + [InlineData("zh-CN", "4.2 吉米", LengthUnit.Gigameter, 4.2)] + [InlineData("zh-CN", "4.2 百米", LengthUnit.Hectometer, 4.2)] + [InlineData("zh-CN", "4.2 英寸", LengthUnit.Inch, 4.2)] + [InlineData("zh-CN", "4.2 千英尺", LengthUnit.Kilofoot, 4.2)] + [InlineData("zh-CN", "4.2 千米", LengthUnit.Kilometer, 4.2)] + [InlineData("zh-CN", "4.2 千码", LengthUnit.Kiloyard, 4.2)] + [InlineData("zh-CN", "4.2 兆米", LengthUnit.Megameter, 4.2)] + [InlineData("zh-CN", "4.2 米", LengthUnit.Meter, 4.2)] + [InlineData("zh-CN", "4.2 微英寸", LengthUnit.Microinch, 4.2)] + [InlineData("zh-CN", "4.2 微米", LengthUnit.Micrometer, 4.2)] + [InlineData("zh-CN", "4.2 密耳", LengthUnit.Mil, 4.2)] + [InlineData("zh-CN", "4.2 英里", LengthUnit.Mile, 4.2)] + [InlineData("zh-CN", "4.2 毫米", LengthUnit.Millimeter, 4.2)] + [InlineData("zh-CN", "4.2 皮米", LengthUnit.Picometer, 4.2)] + [InlineData("zh-CN", "4.2 码", LengthUnit.Yard, 4.2)] + public void TryParse(string culture, string quantityString, LengthUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(Length.TryParse(quantityString, out Length parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("en-US", "1 pica")] // [DtpPica, PrinterPica] + [InlineData("en-US", "1 pt")] // [DtpPoint, PrinterPoint] + [InlineData("ru-RU", "1 мил")] // [Mil, NauticalMile] + [InlineData("zh-CN", "1 纳米")] // [Nanometer, NauticalMile] + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.False(Length.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] @@ -2296,6 +1360,112 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi Assert.False(Length.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } + [Theory] + [InlineData("en-US", LengthUnit.Angstrom, "Å")] + [InlineData("en-US", LengthUnit.AstronomicalUnit, "au")] + [InlineData("en-US", LengthUnit.Centimeter, "cm")] + [InlineData("en-US", LengthUnit.Chain, "ch")] + [InlineData("en-US", LengthUnit.DataMile, "DM")] + [InlineData("en-US", LengthUnit.Decameter, "dam")] + [InlineData("en-US", LengthUnit.Decimeter, "dm")] + [InlineData("en-US", LengthUnit.DtpPica, "pica")] + [InlineData("en-US", LengthUnit.DtpPoint, "pt")] + [InlineData("en-US", LengthUnit.Fathom, "fathom")] + [InlineData("en-US", LengthUnit.Femtometer, "fm")] + [InlineData("en-US", LengthUnit.Foot, "ft")] + [InlineData("en-US", LengthUnit.Gigameter, "Gm")] + [InlineData("en-US", LengthUnit.Hand, "h")] + [InlineData("en-US", LengthUnit.Hectometer, "hm")] + [InlineData("en-US", LengthUnit.Inch, "in")] + [InlineData("en-US", LengthUnit.Kilofoot, "kft")] + [InlineData("en-US", LengthUnit.KilolightYear, "kly")] + [InlineData("en-US", LengthUnit.Kilometer, "km")] + [InlineData("en-US", LengthUnit.Kiloparsec, "kpc")] + [InlineData("en-US", LengthUnit.Kiloyard, "kyd")] + [InlineData("en-US", LengthUnit.LightYear, "ly")] + [InlineData("en-US", LengthUnit.MegalightYear, "Mly")] + [InlineData("en-US", LengthUnit.Megameter, "Mm")] + [InlineData("en-US", LengthUnit.Megaparsec, "Mpc")] + [InlineData("en-US", LengthUnit.Meter, "m")] + [InlineData("en-US", LengthUnit.Microinch, "µin")] + [InlineData("en-US", LengthUnit.Micrometer, "µm")] + [InlineData("en-US", LengthUnit.Mil, "mil")] + [InlineData("en-US", LengthUnit.Mile, "mi")] + [InlineData("en-US", LengthUnit.Millimeter, "mm")] + [InlineData("en-US", LengthUnit.Nanometer, "nm")] + [InlineData("en-US", LengthUnit.NauticalMile, "NM")] + [InlineData("en-US", LengthUnit.Parsec, "pc")] + [InlineData("en-US", LengthUnit.Picometer, "pm")] + [InlineData("en-US", LengthUnit.PrinterPica, "pica")] + [InlineData("en-US", LengthUnit.PrinterPoint, "pt")] + [InlineData("en-US", LengthUnit.Shackle, "shackle")] + [InlineData("en-US", LengthUnit.SolarRadius, "R⊙")] + [InlineData("en-US", LengthUnit.Twip, "twip")] + [InlineData("en-US", LengthUnit.UsSurveyFoot, "ftUS")] + [InlineData("en-US", LengthUnit.Yard, "yd")] + [InlineData("ru-RU", LengthUnit.Centimeter, "см")] + [InlineData("ru-RU", LengthUnit.Decameter, "дам")] + [InlineData("ru-RU", LengthUnit.Decimeter, "дм")] + [InlineData("ru-RU", LengthUnit.Femtometer, "фм")] + [InlineData("ru-RU", LengthUnit.Foot, "фут")] + [InlineData("ru-RU", LengthUnit.Gigameter, "Гм")] + [InlineData("ru-RU", LengthUnit.Hectometer, "гм")] + [InlineData("ru-RU", LengthUnit.Inch, "дюйм")] + [InlineData("ru-RU", LengthUnit.Kilofoot, "кфут")] + [InlineData("ru-RU", LengthUnit.Kilometer, "км")] + [InlineData("ru-RU", LengthUnit.Kiloyard, "кярд")] + [InlineData("ru-RU", LengthUnit.Megameter, "Мм")] + [InlineData("ru-RU", LengthUnit.Meter, "м")] + [InlineData("ru-RU", LengthUnit.Microinch, "микродюйм")] + [InlineData("ru-RU", LengthUnit.Micrometer, "мкм")] + [InlineData("ru-RU", LengthUnit.Mil, "мил")] + [InlineData("ru-RU", LengthUnit.Mile, "миля")] + [InlineData("ru-RU", LengthUnit.Millimeter, "мм")] + [InlineData("ru-RU", LengthUnit.Nanometer, "нм")] + [InlineData("ru-RU", LengthUnit.NauticalMile, "мил")] + [InlineData("ru-RU", LengthUnit.Picometer, "пм")] + [InlineData("ru-RU", LengthUnit.Yard, "ярд")] + [InlineData("zh-CN", LengthUnit.Centimeter, "厘米")] + [InlineData("zh-CN", LengthUnit.Decameter, "十米")] + [InlineData("zh-CN", LengthUnit.Decimeter, "分米")] + [InlineData("zh-CN", LengthUnit.Femtometer, "飞米")] + [InlineData("zh-CN", LengthUnit.Foot, "英尺")] + [InlineData("zh-CN", LengthUnit.Gigameter, "吉米")] + [InlineData("zh-CN", LengthUnit.Hectometer, "百米")] + [InlineData("zh-CN", LengthUnit.Inch, "英寸")] + [InlineData("zh-CN", LengthUnit.Kilofoot, "千英尺")] + [InlineData("zh-CN", LengthUnit.Kilometer, "千米")] + [InlineData("zh-CN", LengthUnit.Kiloyard, "千码")] + [InlineData("zh-CN", LengthUnit.Megameter, "兆米")] + [InlineData("zh-CN", LengthUnit.Meter, "米")] + [InlineData("zh-CN", LengthUnit.Microinch, "微英寸")] + [InlineData("zh-CN", LengthUnit.Micrometer, "微米")] + [InlineData("zh-CN", LengthUnit.Mil, "密耳")] + [InlineData("zh-CN", LengthUnit.Mile, "英里")] + [InlineData("zh-CN", LengthUnit.Millimeter, "毫米")] + [InlineData("zh-CN", LengthUnit.Nanometer, "纳米")] + [InlineData("zh-CN", LengthUnit.NauticalMile, "纳米")] + [InlineData("zh-CN", LengthUnit.Picometer, "皮米")] + [InlineData("zh-CN", LengthUnit.Yard, "码")] + public void GetAbbreviationForCulture(string culture, LengthUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Length.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Length.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Length.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LengthUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index 7f0584c998..eda3beb235 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -216,40 +216,26 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 dB", LevelUnit.Decibel, 4.2)] + [InlineData("en-US", "4.2 Np", LevelUnit.Neper, 4.2)] + public void Parse(string culture, string quantityString, LevelUnit expectedUnit, double expectedValue) { - try - { - var parsed = Level.Parse("1 dB", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decibels, DecibelsTolerance); - Assert.Equal(LevelUnit.Decibel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Level.Parse("1 Np", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nepers, NepersTolerance); - Assert.Equal(LevelUnit.Neper, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Level.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 dB", LevelUnit.Decibel, 4.2)] + [InlineData("en-US", "4.2 Np", LevelUnit.Neper, 4.2)] + public void TryParse(string culture, string quantityString, LevelUnit expectedUnit, double expectedValue) { - { - Assert.True(Level.TryParse("1 dB", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decibels, DecibelsTolerance); - Assert.Equal(LevelUnit.Decibel, parsed.Unit); - } - - { - Assert.True(Level.TryParse("1 Np", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nepers, NepersTolerance); - Assert.Equal(LevelUnit.Neper, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Level.TryParse(quantityString, out Level parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -334,6 +320,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, LevelU Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LevelUnit.Decibel, "dB")] + [InlineData("en-US", LevelUnit.Neper, "Np")] + public void GetAbbreviationForCulture(string culture, LevelUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Level.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Level.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Level.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LevelUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 006170e7a9..7a0e44b4d6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -372,248 +372,58 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g/cm", LinearDensityUnit.GramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/ft", LinearDensityUnit.GramPerFoot, 4.2)] + [InlineData("en-US", "4.2 g/m", LinearDensityUnit.GramPerMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm", LinearDensityUnit.GramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/cm", LinearDensityUnit.KilogramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/ft", LinearDensityUnit.KilogramPerFoot, 4.2)] + [InlineData("en-US", "4.2 kg/m", LinearDensityUnit.KilogramPerMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm", LinearDensityUnit.KilogramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 µg/cm", LinearDensityUnit.MicrogramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 µg/ft", LinearDensityUnit.MicrogramPerFoot, 4.2)] + [InlineData("en-US", "4.2 µg/m", LinearDensityUnit.MicrogramPerMeter, 4.2)] + [InlineData("en-US", "4.2 µg/mm", LinearDensityUnit.MicrogramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mg/cm", LinearDensityUnit.MilligramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mg/ft", LinearDensityUnit.MilligramPerFoot, 4.2)] + [InlineData("en-US", "4.2 mg/m", LinearDensityUnit.MilligramPerMeter, 4.2)] + [InlineData("en-US", "4.2 mg/mm", LinearDensityUnit.MilligramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb/ft", LinearDensityUnit.PoundPerFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in", LinearDensityUnit.PoundPerInch, 4.2)] + public void Parse(string culture, string quantityString, LinearDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = LinearDensity.Parse("1 g/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCentimeter, GramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 g/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerFoot, GramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.GramPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 g/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMeter, GramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 g/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMillimeter, GramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 kg/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCentimeter, KilogramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 kg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerFoot, KilogramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 kg/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMeter, KilogramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 kg/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMillimeter, KilogramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 µg/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCentimeter, MicrogramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 µg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerFoot, MicrogramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 µg/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMeter, MicrogramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 µg/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMillimeter, MicrogramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 mg/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCentimeter, MilligramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 mg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerFoot, MilligramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 mg/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMeter, MilligramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 mg/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMillimeter, MilligramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 lb/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerFoot, PoundsPerFootTolerance); - Assert.Equal(LinearDensityUnit.PoundPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearDensity.Parse("1 lb/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerInch, PoundsPerInchTolerance); - Assert.Equal(LinearDensityUnit.PoundPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = LinearDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g/cm", LinearDensityUnit.GramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/ft", LinearDensityUnit.GramPerFoot, 4.2)] + [InlineData("en-US", "4.2 g/m", LinearDensityUnit.GramPerMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm", LinearDensityUnit.GramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/cm", LinearDensityUnit.KilogramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/ft", LinearDensityUnit.KilogramPerFoot, 4.2)] + [InlineData("en-US", "4.2 kg/m", LinearDensityUnit.KilogramPerMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm", LinearDensityUnit.KilogramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 µg/cm", LinearDensityUnit.MicrogramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 µg/ft", LinearDensityUnit.MicrogramPerFoot, 4.2)] + [InlineData("en-US", "4.2 µg/m", LinearDensityUnit.MicrogramPerMeter, 4.2)] + [InlineData("en-US", "4.2 µg/mm", LinearDensityUnit.MicrogramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mg/cm", LinearDensityUnit.MilligramPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mg/ft", LinearDensityUnit.MilligramPerFoot, 4.2)] + [InlineData("en-US", "4.2 mg/m", LinearDensityUnit.MilligramPerMeter, 4.2)] + [InlineData("en-US", "4.2 mg/mm", LinearDensityUnit.MilligramPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb/ft", LinearDensityUnit.PoundPerFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in", LinearDensityUnit.PoundPerInch, 4.2)] + public void TryParse(string culture, string quantityString, LinearDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(LinearDensity.TryParse("1 g/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCentimeter, GramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 g/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerFoot, GramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.GramPerFoot, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 g/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMeter, GramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerMeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 g/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMillimeter, GramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 kg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCentimeter, KilogramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 kg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerFoot, KilogramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerFoot, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 kg/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMeter, KilogramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerMeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 kg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMillimeter, KilogramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 µg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCentimeter, MicrogramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 µg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerFoot, MicrogramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerFoot, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 µg/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMeter, MicrogramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerMeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 µg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMillimeter, MicrogramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.MicrogramPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 mg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCentimeter, MilligramsPerCentimeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 mg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerFoot, MilligramsPerFootTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerFoot, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 mg/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMeter, MilligramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerMeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 mg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMillimeter, MilligramsPerMillimeterTolerance); - Assert.Equal(LinearDensityUnit.MilligramPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 lb/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerFoot, PoundsPerFootTolerance); - Assert.Equal(LinearDensityUnit.PoundPerFoot, parsed.Unit); - } - - { - Assert.True(LinearDensity.TryParse("1 lb/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerInch, PoundsPerInchTolerance); - Assert.Equal(LinearDensityUnit.PoundPerInch, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(LinearDensity.TryParse(quantityString, out LinearDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -826,6 +636,44 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Linear Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LinearDensityUnit.GramPerCentimeter, "g/cm")] + [InlineData("en-US", LinearDensityUnit.GramPerFoot, "g/ft")] + [InlineData("en-US", LinearDensityUnit.GramPerMeter, "g/m")] + [InlineData("en-US", LinearDensityUnit.GramPerMillimeter, "g/mm")] + [InlineData("en-US", LinearDensityUnit.KilogramPerCentimeter, "kg/cm")] + [InlineData("en-US", LinearDensityUnit.KilogramPerFoot, "kg/ft")] + [InlineData("en-US", LinearDensityUnit.KilogramPerMeter, "kg/m")] + [InlineData("en-US", LinearDensityUnit.KilogramPerMillimeter, "kg/mm")] + [InlineData("en-US", LinearDensityUnit.MicrogramPerCentimeter, "µg/cm")] + [InlineData("en-US", LinearDensityUnit.MicrogramPerFoot, "µg/ft")] + [InlineData("en-US", LinearDensityUnit.MicrogramPerMeter, "µg/m")] + [InlineData("en-US", LinearDensityUnit.MicrogramPerMillimeter, "µg/mm")] + [InlineData("en-US", LinearDensityUnit.MilligramPerCentimeter, "mg/cm")] + [InlineData("en-US", LinearDensityUnit.MilligramPerFoot, "mg/ft")] + [InlineData("en-US", LinearDensityUnit.MilligramPerMeter, "mg/m")] + [InlineData("en-US", LinearDensityUnit.MilligramPerMillimeter, "mg/mm")] + [InlineData("en-US", LinearDensityUnit.PoundPerFoot, "lb/ft")] + [InlineData("en-US", LinearDensityUnit.PoundPerInch, "lb/in")] + public void GetAbbreviationForCulture(string culture, LinearDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = LinearDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(LinearDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = LinearDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LinearDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index 974194518f..ab4460302e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -414,279 +414,72 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 GW/ft", LinearPowerDensityUnit.GigawattPerFoot, 4.2)] + [InlineData("en-US", "4.2 GW/in", LinearPowerDensityUnit.GigawattPerInch, 4.2)] + [InlineData("en-US", "4.2 GW/m", LinearPowerDensityUnit.GigawattPerMeter, 4.2)] + [InlineData("en-US", "4.2 GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/ft", LinearPowerDensityUnit.KilowattPerFoot, 4.2)] + [InlineData("en-US", "4.2 kW/in", LinearPowerDensityUnit.KilowattPerInch, 4.2)] + [InlineData("en-US", "4.2 kW/m", LinearPowerDensityUnit.KilowattPerMeter, 4.2)] + [InlineData("en-US", "4.2 kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 MW/ft", LinearPowerDensityUnit.MegawattPerFoot, 4.2)] + [InlineData("en-US", "4.2 MW/in", LinearPowerDensityUnit.MegawattPerInch, 4.2)] + [InlineData("en-US", "4.2 MW/m", LinearPowerDensityUnit.MegawattPerMeter, 4.2)] + [InlineData("en-US", "4.2 MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mW/ft", LinearPowerDensityUnit.MilliwattPerFoot, 4.2)] + [InlineData("en-US", "4.2 mW/in", LinearPowerDensityUnit.MilliwattPerInch, 4.2)] + [InlineData("en-US", "4.2 mW/m", LinearPowerDensityUnit.MilliwattPerMeter, 4.2)] + [InlineData("en-US", "4.2 mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 W/cm", LinearPowerDensityUnit.WattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 W/ft", LinearPowerDensityUnit.WattPerFoot, 4.2)] + [InlineData("en-US", "4.2 W/in", LinearPowerDensityUnit.WattPerInch, 4.2)] + [InlineData("en-US", "4.2 W/m", LinearPowerDensityUnit.WattPerMeter, 4.2)] + [InlineData("en-US", "4.2 W/mm", LinearPowerDensityUnit.WattPerMillimeter, 4.2)] + public void Parse(string culture, string quantityString, LinearPowerDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = LinearPowerDensity.Parse("1 GW/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCentimeter, GigawattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 GW/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerFoot, GigawattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 GW/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerInch, GigawattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 GW/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerMeter, GigawattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 GW/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerMillimeter, GigawattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 kW/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCentimeter, KilowattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 kW/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerFoot, KilowattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 kW/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerInch, KilowattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 kW/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerMeter, KilowattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 kW/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerMillimeter, KilowattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 MW/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerCentimeter, MegawattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MegawattPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 MW/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerFoot, MegawattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.MegawattPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 MW/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerInch, MegawattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.MegawattPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 MW/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerMeter, MegawattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MegawattPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 MW/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerMillimeter, MegawattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MegawattPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 mW/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerCentimeter, MilliwattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 mW/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerFoot, MilliwattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 mW/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerInch, MilliwattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 mW/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerMeter, MilliwattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 mW/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerMillimeter, MilliwattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 W/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerCentimeter, WattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 W/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerFoot, WattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 W/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerInch, WattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 W/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerMeter, WattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = LinearPowerDensity.Parse("1 W/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerMillimeter, WattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = LinearPowerDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 GW/ft", LinearPowerDensityUnit.GigawattPerFoot, 4.2)] + [InlineData("en-US", "4.2 GW/in", LinearPowerDensityUnit.GigawattPerInch, 4.2)] + [InlineData("en-US", "4.2 GW/m", LinearPowerDensityUnit.GigawattPerMeter, 4.2)] + [InlineData("en-US", "4.2 GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 kW/ft", LinearPowerDensityUnit.KilowattPerFoot, 4.2)] + [InlineData("en-US", "4.2 kW/in", LinearPowerDensityUnit.KilowattPerInch, 4.2)] + [InlineData("en-US", "4.2 kW/m", LinearPowerDensityUnit.KilowattPerMeter, 4.2)] + [InlineData("en-US", "4.2 kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 MW/ft", LinearPowerDensityUnit.MegawattPerFoot, 4.2)] + [InlineData("en-US", "4.2 MW/in", LinearPowerDensityUnit.MegawattPerInch, 4.2)] + [InlineData("en-US", "4.2 MW/m", LinearPowerDensityUnit.MegawattPerMeter, 4.2)] + [InlineData("en-US", "4.2 MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 mW/ft", LinearPowerDensityUnit.MilliwattPerFoot, 4.2)] + [InlineData("en-US", "4.2 mW/in", LinearPowerDensityUnit.MilliwattPerInch, 4.2)] + [InlineData("en-US", "4.2 mW/m", LinearPowerDensityUnit.MilliwattPerMeter, 4.2)] + [InlineData("en-US", "4.2 mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 W/cm", LinearPowerDensityUnit.WattPerCentimeter, 4.2)] + [InlineData("en-US", "4.2 W/ft", LinearPowerDensityUnit.WattPerFoot, 4.2)] + [InlineData("en-US", "4.2 W/in", LinearPowerDensityUnit.WattPerInch, 4.2)] + [InlineData("en-US", "4.2 W/m", LinearPowerDensityUnit.WattPerMeter, 4.2)] + [InlineData("en-US", "4.2 W/mm", LinearPowerDensityUnit.WattPerMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, LinearPowerDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(LinearPowerDensity.TryParse("1 GW/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCentimeter, GigawattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 GW/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerFoot, GigawattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 GW/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerInch, GigawattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 GW/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerMeter, GigawattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 GW/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerMillimeter, GigawattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 kW/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCentimeter, KilowattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 kW/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerFoot, KilowattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 kW/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerInch, KilowattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 kW/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerMeter, KilowattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 kW/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerMillimeter, KilowattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 W/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerCentimeter, WattsPerCentimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 W/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerFoot, WattsPerFootTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerFoot, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 W/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerInch, WattsPerInchTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerInch, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 W/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerMeter, WattsPerMeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerMeter, parsed.Unit); - } - - { - Assert.True(LinearPowerDensity.TryParse("1 W/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerMillimeter, WattsPerMillimeterTolerance); - Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(LinearPowerDensity.TryParse(quantityString, out LinearPowerDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -955,6 +748,51 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Linear Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LinearPowerDensityUnit.GigawattPerCentimeter, "GW/cm")] + [InlineData("en-US", LinearPowerDensityUnit.GigawattPerFoot, "GW/ft")] + [InlineData("en-US", LinearPowerDensityUnit.GigawattPerInch, "GW/in")] + [InlineData("en-US", LinearPowerDensityUnit.GigawattPerMeter, "GW/m")] + [InlineData("en-US", LinearPowerDensityUnit.GigawattPerMillimeter, "GW/mm")] + [InlineData("en-US", LinearPowerDensityUnit.KilowattPerCentimeter, "kW/cm")] + [InlineData("en-US", LinearPowerDensityUnit.KilowattPerFoot, "kW/ft")] + [InlineData("en-US", LinearPowerDensityUnit.KilowattPerInch, "kW/in")] + [InlineData("en-US", LinearPowerDensityUnit.KilowattPerMeter, "kW/m")] + [InlineData("en-US", LinearPowerDensityUnit.KilowattPerMillimeter, "kW/mm")] + [InlineData("en-US", LinearPowerDensityUnit.MegawattPerCentimeter, "MW/cm")] + [InlineData("en-US", LinearPowerDensityUnit.MegawattPerFoot, "MW/ft")] + [InlineData("en-US", LinearPowerDensityUnit.MegawattPerInch, "MW/in")] + [InlineData("en-US", LinearPowerDensityUnit.MegawattPerMeter, "MW/m")] + [InlineData("en-US", LinearPowerDensityUnit.MegawattPerMillimeter, "MW/mm")] + [InlineData("en-US", LinearPowerDensityUnit.MilliwattPerCentimeter, "mW/cm")] + [InlineData("en-US", LinearPowerDensityUnit.MilliwattPerFoot, "mW/ft")] + [InlineData("en-US", LinearPowerDensityUnit.MilliwattPerInch, "mW/in")] + [InlineData("en-US", LinearPowerDensityUnit.MilliwattPerMeter, "mW/m")] + [InlineData("en-US", LinearPowerDensityUnit.MilliwattPerMillimeter, "mW/mm")] + [InlineData("en-US", LinearPowerDensityUnit.WattPerCentimeter, "W/cm")] + [InlineData("en-US", LinearPowerDensityUnit.WattPerFoot, "W/ft")] + [InlineData("en-US", LinearPowerDensityUnit.WattPerInch, "W/in")] + [InlineData("en-US", LinearPowerDensityUnit.WattPerMeter, "W/m")] + [InlineData("en-US", LinearPowerDensityUnit.WattPerMillimeter, "W/mm")] + public void GetAbbreviationForCulture(string culture, LinearPowerDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = LinearPowerDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(LinearPowerDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = LinearPowerDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LinearPowerDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index 2ef64856a3..66065dba00 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -324,144 +324,42 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Cd/ft²", LuminanceUnit.CandelaPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 Cd/in²", LuminanceUnit.CandelaPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 Cd/m²", LuminanceUnit.CandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nt", LuminanceUnit.Nit, 4.2)] + public void Parse(string culture, string quantityString, LuminanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = Luminance.Parse("1 Cd/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareFoot, CandelasPerSquareFootTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 Cd/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareInch, CandelasPerSquareInchTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 Cd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareMeter, CandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 cCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CenticandelasPerSquareMeter, CenticandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.CenticandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 dCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecicandelasPerSquareMeter, DecicandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.DecicandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 kCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocandelasPerSquareMeter, KilocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.KilocandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 µCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrocandelasPerSquareMeter, MicrocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.MicrocandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 mCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillicandelasPerSquareMeter, MillicandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.MillicandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 nCd/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanocandelasPerSquareMeter, NanocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.NanocandelaPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminance.Parse("1 nt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nits, NitsTolerance); - Assert.Equal(LuminanceUnit.Nit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Luminance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Cd/ft²", LuminanceUnit.CandelaPerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 Cd/in²", LuminanceUnit.CandelaPerSquareInch, 4.2)] + [InlineData("en-US", "4.2 Cd/m²", LuminanceUnit.CandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 nt", LuminanceUnit.Nit, 4.2)] + public void TryParse(string culture, string quantityString, LuminanceUnit expectedUnit, double expectedValue) { - { - Assert.True(Luminance.TryParse("1 Cd/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareFoot, CandelasPerSquareFootTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareFoot, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 Cd/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareInch, CandelasPerSquareInchTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareInch, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 Cd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CandelasPerSquareMeter, CandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 cCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CenticandelasPerSquareMeter, CenticandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.CenticandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 dCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecicandelasPerSquareMeter, DecicandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.DecicandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 kCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocandelasPerSquareMeter, KilocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.KilocandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 µCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrocandelasPerSquareMeter, MicrocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.MicrocandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 mCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillicandelasPerSquareMeter, MillicandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.MillicandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 nCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanocandelasPerSquareMeter, NanocandelasPerSquareMeterTolerance); - Assert.Equal(LuminanceUnit.NanocandelaPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Luminance.TryParse("1 nt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nits, NitsTolerance); - Assert.Equal(LuminanceUnit.Nit, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Luminance.TryParse(quantityString, out Luminance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -610,6 +508,36 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Lumina Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LuminanceUnit.CandelaPerSquareFoot, "Cd/ft²")] + [InlineData("en-US", LuminanceUnit.CandelaPerSquareInch, "Cd/in²")] + [InlineData("en-US", LuminanceUnit.CandelaPerSquareMeter, "Cd/m²")] + [InlineData("en-US", LuminanceUnit.CenticandelaPerSquareMeter, "cCd/m²")] + [InlineData("en-US", LuminanceUnit.DecicandelaPerSquareMeter, "dCd/m²")] + [InlineData("en-US", LuminanceUnit.KilocandelaPerSquareMeter, "kCd/m²")] + [InlineData("en-US", LuminanceUnit.MicrocandelaPerSquareMeter, "µCd/m²")] + [InlineData("en-US", LuminanceUnit.MillicandelaPerSquareMeter, "mCd/m²")] + [InlineData("en-US", LuminanceUnit.NanocandelaPerSquareMeter, "nCd/m²")] + [InlineData("en-US", LuminanceUnit.Nit, "nt")] + public void GetAbbreviationForCulture(string culture, LuminanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Luminance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Luminance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Luminance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LuminanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 7f9f0c1990..9cd0f0a823 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -348,172 +348,50 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 daW", LuminosityUnit.Decawatt, 4.2)] + [InlineData("en-US", "4.2 dW", LuminosityUnit.Deciwatt, 4.2)] + [InlineData("en-US", "4.2 fW", LuminosityUnit.Femtowatt, 4.2)] + [InlineData("en-US", "4.2 GW", LuminosityUnit.Gigawatt, 4.2)] + [InlineData("en-US", "4.2 kW", LuminosityUnit.Kilowatt, 4.2)] + [InlineData("en-US", "4.2 MW", LuminosityUnit.Megawatt, 4.2)] + [InlineData("en-US", "4.2 µW", LuminosityUnit.Microwatt, 4.2)] + [InlineData("en-US", "4.2 mW", LuminosityUnit.Milliwatt, 4.2)] + [InlineData("en-US", "4.2 nW", LuminosityUnit.Nanowatt, 4.2)] + [InlineData("en-US", "4.2 PW", LuminosityUnit.Petawatt, 4.2)] + [InlineData("en-US", "4.2 pW", LuminosityUnit.Picowatt, 4.2)] + [InlineData("en-US", "4.2 L⊙", LuminosityUnit.SolarLuminosity, 4.2)] + [InlineData("en-US", "4.2 TW", LuminosityUnit.Terawatt, 4.2)] + [InlineData("en-US", "4.2 W", LuminosityUnit.Watt, 4.2)] + public void Parse(string culture, string quantityString, LuminosityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Luminosity.Parse("1 daW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decawatts, DecawattsTolerance); - Assert.Equal(LuminosityUnit.Decawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 dW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Deciwatts, DeciwattsTolerance); - Assert.Equal(LuminosityUnit.Deciwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 fW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtowatts, FemtowattsTolerance); - Assert.Equal(LuminosityUnit.Femtowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 GW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigawatts, GigawattsTolerance); - Assert.Equal(LuminosityUnit.Gigawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 kW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilowatts, KilowattsTolerance); - Assert.Equal(LuminosityUnit.Kilowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 MW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megawatts, MegawattsTolerance); - Assert.Equal(LuminosityUnit.Megawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 µW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microwatts, MicrowattsTolerance); - Assert.Equal(LuminosityUnit.Microwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 mW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliwatts, MilliwattsTolerance); - Assert.Equal(LuminosityUnit.Milliwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 nW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanowatts, NanowattsTolerance); - Assert.Equal(LuminosityUnit.Nanowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 PW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petawatts, PetawattsTolerance); - Assert.Equal(LuminosityUnit.Petawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 pW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picowatts, PicowattsTolerance); - Assert.Equal(LuminosityUnit.Picowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 L⊙", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SolarLuminosities, SolarLuminositiesTolerance); - Assert.Equal(LuminosityUnit.SolarLuminosity, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 TW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terawatts, TerawattsTolerance); - Assert.Equal(LuminosityUnit.Terawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Luminosity.Parse("1 W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Watts, WattsTolerance); - Assert.Equal(LuminosityUnit.Watt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Luminosity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 daW", LuminosityUnit.Decawatt, 4.2)] + [InlineData("en-US", "4.2 dW", LuminosityUnit.Deciwatt, 4.2)] + [InlineData("en-US", "4.2 fW", LuminosityUnit.Femtowatt, 4.2)] + [InlineData("en-US", "4.2 GW", LuminosityUnit.Gigawatt, 4.2)] + [InlineData("en-US", "4.2 kW", LuminosityUnit.Kilowatt, 4.2)] + [InlineData("en-US", "4.2 MW", LuminosityUnit.Megawatt, 4.2)] + [InlineData("en-US", "4.2 µW", LuminosityUnit.Microwatt, 4.2)] + [InlineData("en-US", "4.2 mW", LuminosityUnit.Milliwatt, 4.2)] + [InlineData("en-US", "4.2 nW", LuminosityUnit.Nanowatt, 4.2)] + [InlineData("en-US", "4.2 PW", LuminosityUnit.Petawatt, 4.2)] + [InlineData("en-US", "4.2 pW", LuminosityUnit.Picowatt, 4.2)] + [InlineData("en-US", "4.2 L⊙", LuminosityUnit.SolarLuminosity, 4.2)] + [InlineData("en-US", "4.2 TW", LuminosityUnit.Terawatt, 4.2)] + [InlineData("en-US", "4.2 W", LuminosityUnit.Watt, 4.2)] + public void TryParse(string culture, string quantityString, LuminosityUnit expectedUnit, double expectedValue) { - { - Assert.True(Luminosity.TryParse("1 daW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decawatts, DecawattsTolerance); - Assert.Equal(LuminosityUnit.Decawatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 dW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciwatts, DeciwattsTolerance); - Assert.Equal(LuminosityUnit.Deciwatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 fW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtowatts, FemtowattsTolerance); - Assert.Equal(LuminosityUnit.Femtowatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 GW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigawatts, GigawattsTolerance); - Assert.Equal(LuminosityUnit.Gigawatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 kW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilowatts, KilowattsTolerance); - Assert.Equal(LuminosityUnit.Kilowatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 µW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microwatts, MicrowattsTolerance); - Assert.Equal(LuminosityUnit.Microwatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 nW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanowatts, NanowattsTolerance); - Assert.Equal(LuminosityUnit.Nanowatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 L⊙", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SolarLuminosities, SolarLuminositiesTolerance); - Assert.Equal(LuminosityUnit.SolarLuminosity, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 TW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terawatts, TerawattsTolerance); - Assert.Equal(LuminosityUnit.Terawatt, parsed.Unit); - } - - { - Assert.True(Luminosity.TryParse("1 W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Watts, WattsTolerance); - Assert.Equal(LuminosityUnit.Watt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Luminosity.TryParse(quantityString, out Luminosity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -694,6 +572,40 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Lumino Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LuminosityUnit.Decawatt, "daW")] + [InlineData("en-US", LuminosityUnit.Deciwatt, "dW")] + [InlineData("en-US", LuminosityUnit.Femtowatt, "fW")] + [InlineData("en-US", LuminosityUnit.Gigawatt, "GW")] + [InlineData("en-US", LuminosityUnit.Kilowatt, "kW")] + [InlineData("en-US", LuminosityUnit.Megawatt, "MW")] + [InlineData("en-US", LuminosityUnit.Microwatt, "µW")] + [InlineData("en-US", LuminosityUnit.Milliwatt, "mW")] + [InlineData("en-US", LuminosityUnit.Nanowatt, "nW")] + [InlineData("en-US", LuminosityUnit.Petawatt, "PW")] + [InlineData("en-US", LuminosityUnit.Picowatt, "pW")] + [InlineData("en-US", LuminosityUnit.SolarLuminosity, "L⊙")] + [InlineData("en-US", LuminosityUnit.Terawatt, "TW")] + [InlineData("en-US", LuminosityUnit.Watt, "W")] + public void GetAbbreviationForCulture(string culture, LuminosityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Luminosity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Luminosity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Luminosity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LuminosityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index 37ef79be4f..7ae100daec 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 lm", LuminousFluxUnit.Lumen, 4.2)] + public void Parse(string culture, string quantityString, LuminousFluxUnit expectedUnit, double expectedValue) { - try - { - var parsed = LuminousFlux.Parse("1 lm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Lumens, LumensTolerance); - Assert.Equal(LuminousFluxUnit.Lumen, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = LuminousFlux.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 lm", LuminousFluxUnit.Lumen, 4.2)] + public void TryParse(string culture, string quantityString, LuminousFluxUnit expectedUnit, double expectedValue) { - { - Assert.True(LuminousFlux.TryParse("1 lm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Lumens, LumensTolerance); - Assert.Equal(LuminousFluxUnit.Lumen, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(LuminousFlux.TryParse(quantityString, out LuminousFlux parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Lumino Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LuminousFluxUnit.Lumen, "lm")] + public void GetAbbreviationForCulture(string culture, LuminousFluxUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = LuminousFlux.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(LuminousFlux.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = LuminousFlux.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LuminousFluxUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index 7f62c98294..57f1d51102 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cd", LuminousIntensityUnit.Candela, 4.2)] + public void Parse(string culture, string quantityString, LuminousIntensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = LuminousIntensity.Parse("1 cd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Candela, CandelaTolerance); - Assert.Equal(LuminousIntensityUnit.Candela, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = LuminousIntensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cd", LuminousIntensityUnit.Candela, 4.2)] + public void TryParse(string culture, string quantityString, LuminousIntensityUnit expectedUnit, double expectedValue) { - { - Assert.True(LuminousIntensity.TryParse("1 cd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Candela, CandelaTolerance); - Assert.Equal(LuminousIntensityUnit.Candela, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(LuminousIntensity.TryParse(quantityString, out LuminousIntensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Lumino Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", LuminousIntensityUnit.Candela, "cd")] + public void GetAbbreviationForCulture(string culture, LuminousIntensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = LuminousIntensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(LuminousIntensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = LuminousIntensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(LuminousIntensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index 4d40dc817b..d85e6638ce 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -300,92 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 G", MagneticFieldUnit.Gauss, 4.2)] + [InlineData("en-US", "4.2 µT", MagneticFieldUnit.Microtesla, 4.2)] + [InlineData("en-US", "4.2 mG", MagneticFieldUnit.Milligauss, 4.2)] + [InlineData("en-US", "4.2 mT", MagneticFieldUnit.Millitesla, 4.2)] + [InlineData("en-US", "4.2 nT", MagneticFieldUnit.Nanotesla, 4.2)] + [InlineData("en-US", "4.2 T", MagneticFieldUnit.Tesla, 4.2)] + public void Parse(string culture, string quantityString, MagneticFieldUnit expectedUnit, double expectedValue) { - try - { - var parsed = MagneticField.Parse("1 G", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gausses, GaussesTolerance); - Assert.Equal(MagneticFieldUnit.Gauss, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MagneticField.Parse("1 µT", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microteslas, MicroteslasTolerance); - Assert.Equal(MagneticFieldUnit.Microtesla, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MagneticField.Parse("1 mG", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milligausses, MilligaussesTolerance); - Assert.Equal(MagneticFieldUnit.Milligauss, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MagneticField.Parse("1 mT", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliteslas, MilliteslasTolerance); - Assert.Equal(MagneticFieldUnit.Millitesla, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MagneticField.Parse("1 nT", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoteslas, NanoteslasTolerance); - Assert.Equal(MagneticFieldUnit.Nanotesla, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MagneticField.Parse("1 T", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teslas, TeslasTolerance); - Assert.Equal(MagneticFieldUnit.Tesla, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MagneticField.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 G", MagneticFieldUnit.Gauss, 4.2)] + [InlineData("en-US", "4.2 µT", MagneticFieldUnit.Microtesla, 4.2)] + [InlineData("en-US", "4.2 mG", MagneticFieldUnit.Milligauss, 4.2)] + [InlineData("en-US", "4.2 mT", MagneticFieldUnit.Millitesla, 4.2)] + [InlineData("en-US", "4.2 nT", MagneticFieldUnit.Nanotesla, 4.2)] + [InlineData("en-US", "4.2 T", MagneticFieldUnit.Tesla, 4.2)] + public void TryParse(string culture, string quantityString, MagneticFieldUnit expectedUnit, double expectedValue) { - { - Assert.True(MagneticField.TryParse("1 G", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gausses, GaussesTolerance); - Assert.Equal(MagneticFieldUnit.Gauss, parsed.Unit); - } - - { - Assert.True(MagneticField.TryParse("1 µT", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microteslas, MicroteslasTolerance); - Assert.Equal(MagneticFieldUnit.Microtesla, parsed.Unit); - } - - { - Assert.True(MagneticField.TryParse("1 mG", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milligausses, MilligaussesTolerance); - Assert.Equal(MagneticFieldUnit.Milligauss, parsed.Unit); - } - - { - Assert.True(MagneticField.TryParse("1 mT", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliteslas, MilliteslasTolerance); - Assert.Equal(MagneticFieldUnit.Millitesla, parsed.Unit); - } - - { - Assert.True(MagneticField.TryParse("1 nT", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoteslas, NanoteslasTolerance); - Assert.Equal(MagneticFieldUnit.Nanotesla, parsed.Unit); - } - - { - Assert.True(MagneticField.TryParse("1 T", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teslas, TeslasTolerance); - Assert.Equal(MagneticFieldUnit.Tesla, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MagneticField.TryParse(quantityString, out MagneticField parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -502,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Magnet Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MagneticFieldUnit.Gauss, "G")] + [InlineData("en-US", MagneticFieldUnit.Microtesla, "µT")] + [InlineData("en-US", MagneticFieldUnit.Milligauss, "mG")] + [InlineData("en-US", MagneticFieldUnit.Millitesla, "mT")] + [InlineData("en-US", MagneticFieldUnit.Nanotesla, "nT")] + [InlineData("en-US", MagneticFieldUnit.Tesla, "T")] + public void GetAbbreviationForCulture(string culture, MagneticFieldUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MagneticField.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MagneticField.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MagneticField.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MagneticFieldUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index b3d9a16775..202f8fdf1e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Wb", MagneticFluxUnit.Weber, 4.2)] + public void Parse(string culture, string quantityString, MagneticFluxUnit expectedUnit, double expectedValue) { - try - { - var parsed = MagneticFlux.Parse("1 Wb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Webers, WebersTolerance); - Assert.Equal(MagneticFluxUnit.Weber, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MagneticFlux.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Wb", MagneticFluxUnit.Weber, 4.2)] + public void TryParse(string culture, string quantityString, MagneticFluxUnit expectedUnit, double expectedValue) { - { - Assert.True(MagneticFlux.TryParse("1 Wb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Webers, WebersTolerance); - Assert.Equal(MagneticFluxUnit.Weber, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MagneticFlux.TryParse(quantityString, out MagneticFlux parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Magnet Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MagneticFluxUnit.Weber, "Wb")] + public void GetAbbreviationForCulture(string culture, MagneticFluxUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MagneticFlux.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MagneticFlux.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MagneticFlux.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MagneticFluxUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index f859d178b0..2b82cf43d5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 A/m", MagnetizationUnit.AmperePerMeter, 4.2)] + public void Parse(string culture, string quantityString, MagnetizationUnit expectedUnit, double expectedValue) { - try - { - var parsed = Magnetization.Parse("1 A/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AmperesPerMeter, AmperesPerMeterTolerance); - Assert.Equal(MagnetizationUnit.AmperePerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Magnetization.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 A/m", MagnetizationUnit.AmperePerMeter, 4.2)] + public void TryParse(string culture, string quantityString, MagnetizationUnit expectedUnit, double expectedValue) { - { - Assert.True(Magnetization.TryParse("1 A/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AmperesPerMeter, AmperesPerMeterTolerance); - Assert.Equal(MagnetizationUnit.AmperePerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Magnetization.TryParse(quantityString, out Magnetization parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Magnet Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MagnetizationUnit.AmperePerMeter, "A/m")] + public void GetAbbreviationForCulture(string culture, MagnetizationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Magnetization.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Magnetization.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Magnetization.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MagnetizationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index b55a508b13..a4cba06c4e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -558,703 +558,128 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg/dl", MassConcentrationUnit.CentigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 cg/l", MassConcentrationUnit.CentigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 cg/μl", MassConcentrationUnit.CentigramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 cg/ml", MassConcentrationUnit.CentigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dg/dl", MassConcentrationUnit.DecigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 dg/l", MassConcentrationUnit.DecigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 dg/μl", MassConcentrationUnit.DecigramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 dg/ml", MassConcentrationUnit.DecigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 g/cm³", MassConcentrationUnit.GramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/m³", MassConcentrationUnit.GramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm³", MassConcentrationUnit.GramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 g/dl", MassConcentrationUnit.GramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 g/l", MassConcentrationUnit.GramPerLiter, 4.2)] + [InlineData("en-US", "4.2 g/μl", MassConcentrationUnit.GramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 g/ml", MassConcentrationUnit.GramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/m³", MassConcentrationUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/l", MassConcentrationUnit.KilogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kip/in³", MassConcentrationUnit.KilopoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µg/dl", MassConcentrationUnit.MicrogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 µg/l", MassConcentrationUnit.MicrogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 µg/μl", MassConcentrationUnit.MicrogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 µg/ml", MassConcentrationUnit.MicrogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mg/m³", MassConcentrationUnit.MilligramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mg/dl", MassConcentrationUnit.MilligramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 mg/l", MassConcentrationUnit.MilligramPerLiter, 4.2)] + [InlineData("en-US", "4.2 mg/μl", MassConcentrationUnit.MilligramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 mg/ml", MassConcentrationUnit.MilligramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ng/dl", MassConcentrationUnit.NanogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 ng/l", MassConcentrationUnit.NanogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 ng/μl", MassConcentrationUnit.NanogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 ng/ml", MassConcentrationUnit.NanogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon, 4.2)] + [InlineData("en-US", "4.2 pg/dl", MassConcentrationUnit.PicogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 pg/l", MassConcentrationUnit.PicogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 pg/μl", MassConcentrationUnit.PicogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 pg/ml", MassConcentrationUnit.PicogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 lb/ft³", MassConcentrationUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in³", MassConcentrationUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon, 4.2)] + [InlineData("en-US", "4.2 slug/ft³", MassConcentrationUnit.SlugPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 t/m³", MassConcentrationUnit.TonnePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 г/м³", MassConcentrationUnit.GramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 кг/м³", MassConcentrationUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мг/м³", MassConcentrationUnit.MilligramPerCubicMeter, 4.2)] + public void Parse(string culture, string quantityString, MassConcentrationUnit expectedUnit, double expectedValue) { - try - { - var parsed = MassConcentration.Parse("1 cg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDeciliter, CentigramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 cg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerLiter, CentigramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 cg/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMicroliter, CentigramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 cg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 dg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDeciliter, DecigramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 dg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerLiter, DecigramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 dg/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMicroliter, DecigramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 dg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 г/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerDeciliter, GramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerLiter, GramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMicroliter, GramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 g/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMilliliter, GramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kg/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 кг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kg/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerLiter, KilogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kip/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 kip/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 µg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 мкг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 µg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDeciliter, MicrogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 µg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerLiter, MicrogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 µg/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMicroliter, MicrogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 µg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 mg/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 мг/м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 mg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerDeciliter, MilligramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 mg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerLiter, MilligramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 mg/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMicroliter, MilligramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 mg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ng/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDeciliter, NanogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ng/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerLiter, NanogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ng/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMicroliter, NanogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ng/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 oz/gal (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OuncesPerImperialGallon, OuncesPerImperialGallonTolerance); - Assert.Equal(MassConcentrationUnit.OuncePerImperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 oz/gal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OuncesPerUSGallon, OuncesPerUSGallonTolerance); - Assert.Equal(MassConcentrationUnit.OuncePerUSGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 pg/dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerDeciliter, PicogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerDeciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 pg/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerLiter, PicogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 pg/μl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMicroliter, PicogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerMicroliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 pg/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 lb/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 lb/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ppg (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerImperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 ppg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerUSGallon, PoundsPerUSGallonTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerUSGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 slug/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.SlugPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 t/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 t/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassConcentration.Parse("1 t/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MassConcentration.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cg/dl", MassConcentrationUnit.CentigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 cg/l", MassConcentrationUnit.CentigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 cg/μl", MassConcentrationUnit.CentigramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 cg/ml", MassConcentrationUnit.CentigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dg/dl", MassConcentrationUnit.DecigramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 dg/l", MassConcentrationUnit.DecigramPerLiter, 4.2)] + [InlineData("en-US", "4.2 dg/μl", MassConcentrationUnit.DecigramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 dg/ml", MassConcentrationUnit.DecigramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 g/cm³", MassConcentrationUnit.GramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 g/m³", MassConcentrationUnit.GramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 g/mm³", MassConcentrationUnit.GramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 g/dl", MassConcentrationUnit.GramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 g/l", MassConcentrationUnit.GramPerLiter, 4.2)] + [InlineData("en-US", "4.2 g/μl", MassConcentrationUnit.GramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 g/ml", MassConcentrationUnit.GramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg/m³", MassConcentrationUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg/l", MassConcentrationUnit.KilogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kip/in³", MassConcentrationUnit.KilopoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µg/dl", MassConcentrationUnit.MicrogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 µg/l", MassConcentrationUnit.MicrogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 µg/μl", MassConcentrationUnit.MicrogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 µg/ml", MassConcentrationUnit.MicrogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 mg/m³", MassConcentrationUnit.MilligramPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mg/dl", MassConcentrationUnit.MilligramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 mg/l", MassConcentrationUnit.MilligramPerLiter, 4.2)] + [InlineData("en-US", "4.2 mg/μl", MassConcentrationUnit.MilligramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 mg/ml", MassConcentrationUnit.MilligramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ng/dl", MassConcentrationUnit.NanogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 ng/l", MassConcentrationUnit.NanogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 ng/μl", MassConcentrationUnit.NanogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 ng/ml", MassConcentrationUnit.NanogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon, 4.2)] + [InlineData("en-US", "4.2 pg/dl", MassConcentrationUnit.PicogramPerDeciliter, 4.2)] + [InlineData("en-US", "4.2 pg/l", MassConcentrationUnit.PicogramPerLiter, 4.2)] + [InlineData("en-US", "4.2 pg/μl", MassConcentrationUnit.PicogramPerMicroliter, 4.2)] + [InlineData("en-US", "4.2 pg/ml", MassConcentrationUnit.PicogramPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 lb/ft³", MassConcentrationUnit.PoundPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lb/in³", MassConcentrationUnit.PoundPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon, 4.2)] + [InlineData("en-US", "4.2 ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon, 4.2)] + [InlineData("en-US", "4.2 slug/ft³", MassConcentrationUnit.SlugPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 t/m³", MassConcentrationUnit.TonnePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 г/м³", MassConcentrationUnit.GramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 кг/м³", MassConcentrationUnit.KilogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мг/м³", MassConcentrationUnit.MilligramPerCubicMeter, 4.2)] + public void TryParse(string culture, string quantityString, MassConcentrationUnit expectedUnit, double expectedValue) { - { - Assert.True(MassConcentration.TryParse("1 cg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDeciliter, CentigramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 cg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerLiter, CentigramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 cg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMicroliter, CentigramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 cg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.CentigramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 dg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDeciliter, DecigramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 dg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerLiter, DecigramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 dg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMicroliter, DecigramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 dg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.DecigramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 г/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerDeciliter, GramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerLiter, GramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMicroliter, GramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 g/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMilliliter, GramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.GramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kg/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 кг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kg/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerLiter, KilogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.KilogramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kip/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicFoot, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 kip/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicInch, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 µg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 мкг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerCubicMeter, MicrogramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 µg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDeciliter, MicrogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 µg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerLiter, MicrogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 µg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMicroliter, MicrogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 µg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.MicrogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 mg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 мг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 mg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerDeciliter, MilligramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 mg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerLiter, MilligramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 mg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMicroliter, MilligramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 mg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.MilligramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ng/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDeciliter, NanogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ng/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerLiter, NanogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ng/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMicroliter, NanogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ng/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.NanogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 oz/gal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OuncesPerImperialGallon, OuncesPerImperialGallonTolerance); - Assert.Equal(MassConcentrationUnit.OuncePerImperialGallon, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 oz/gal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OuncesPerUSGallon, OuncesPerUSGallonTolerance); - Assert.Equal(MassConcentrationUnit.OuncePerUSGallon, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 pg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerDeciliter, PicogramsPerDeciliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerDeciliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 pg/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerLiter, PicogramsPerLiterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerLiter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 pg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMicroliter, PicogramsPerMicroliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerMicroliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 pg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - Assert.Equal(MassConcentrationUnit.PicogramPerMilliliter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 lb/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerCubicFoot, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 lb/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerCubicInch, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ppg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerImperialGallon, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 ppg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerUSGallon, PoundsPerUSGallonTolerance); - Assert.Equal(MassConcentrationUnit.PoundPerUSGallon, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 slug/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - Assert.Equal(MassConcentrationUnit.SlugPerCubicFoot, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 t/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 t/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMeter, parsed.Unit); - } - - { - Assert.True(MassConcentration.TryParse("1 t/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MassConcentration.TryParse(quantityString, out MassConcentration parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1731,6 +1156,79 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MassCo Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MassConcentrationUnit.CentigramPerDeciliter, "cg/dl")] + [InlineData("en-US", MassConcentrationUnit.CentigramPerLiter, "cg/l")] + [InlineData("en-US", MassConcentrationUnit.CentigramPerMicroliter, "cg/μl")] + [InlineData("en-US", MassConcentrationUnit.CentigramPerMilliliter, "cg/ml")] + [InlineData("en-US", MassConcentrationUnit.DecigramPerDeciliter, "dg/dl")] + [InlineData("en-US", MassConcentrationUnit.DecigramPerLiter, "dg/l")] + [InlineData("en-US", MassConcentrationUnit.DecigramPerMicroliter, "dg/μl")] + [InlineData("en-US", MassConcentrationUnit.DecigramPerMilliliter, "dg/ml")] + [InlineData("en-US", MassConcentrationUnit.GramPerCubicCentimeter, "g/cm³")] + [InlineData("en-US", MassConcentrationUnit.GramPerCubicMeter, "g/m³")] + [InlineData("en-US", MassConcentrationUnit.GramPerCubicMillimeter, "g/mm³")] + [InlineData("en-US", MassConcentrationUnit.GramPerDeciliter, "g/dl")] + [InlineData("en-US", MassConcentrationUnit.GramPerLiter, "g/l")] + [InlineData("en-US", MassConcentrationUnit.GramPerMicroliter, "g/μl")] + [InlineData("en-US", MassConcentrationUnit.GramPerMilliliter, "g/ml")] + [InlineData("en-US", MassConcentrationUnit.KilogramPerCubicCentimeter, "kg/cm³")] + [InlineData("en-US", MassConcentrationUnit.KilogramPerCubicMeter, "kg/m³")] + [InlineData("en-US", MassConcentrationUnit.KilogramPerCubicMillimeter, "kg/mm³")] + [InlineData("en-US", MassConcentrationUnit.KilogramPerLiter, "kg/l")] + [InlineData("en-US", MassConcentrationUnit.KilopoundPerCubicFoot, "kip/ft³")] + [InlineData("en-US", MassConcentrationUnit.KilopoundPerCubicInch, "kip/in³")] + [InlineData("en-US", MassConcentrationUnit.MicrogramPerCubicMeter, "µg/m³")] + [InlineData("en-US", MassConcentrationUnit.MicrogramPerDeciliter, "µg/dl")] + [InlineData("en-US", MassConcentrationUnit.MicrogramPerLiter, "µg/l")] + [InlineData("en-US", MassConcentrationUnit.MicrogramPerMicroliter, "µg/μl")] + [InlineData("en-US", MassConcentrationUnit.MicrogramPerMilliliter, "µg/ml")] + [InlineData("en-US", MassConcentrationUnit.MilligramPerCubicMeter, "mg/m³")] + [InlineData("en-US", MassConcentrationUnit.MilligramPerDeciliter, "mg/dl")] + [InlineData("en-US", MassConcentrationUnit.MilligramPerLiter, "mg/l")] + [InlineData("en-US", MassConcentrationUnit.MilligramPerMicroliter, "mg/μl")] + [InlineData("en-US", MassConcentrationUnit.MilligramPerMilliliter, "mg/ml")] + [InlineData("en-US", MassConcentrationUnit.NanogramPerDeciliter, "ng/dl")] + [InlineData("en-US", MassConcentrationUnit.NanogramPerLiter, "ng/l")] + [InlineData("en-US", MassConcentrationUnit.NanogramPerMicroliter, "ng/μl")] + [InlineData("en-US", MassConcentrationUnit.NanogramPerMilliliter, "ng/ml")] + [InlineData("en-US", MassConcentrationUnit.OuncePerImperialGallon, "oz/gal (imp.)")] + [InlineData("en-US", MassConcentrationUnit.OuncePerUSGallon, "oz/gal (U.S.)")] + [InlineData("en-US", MassConcentrationUnit.PicogramPerDeciliter, "pg/dl")] + [InlineData("en-US", MassConcentrationUnit.PicogramPerLiter, "pg/l")] + [InlineData("en-US", MassConcentrationUnit.PicogramPerMicroliter, "pg/μl")] + [InlineData("en-US", MassConcentrationUnit.PicogramPerMilliliter, "pg/ml")] + [InlineData("en-US", MassConcentrationUnit.PoundPerCubicFoot, "lb/ft³")] + [InlineData("en-US", MassConcentrationUnit.PoundPerCubicInch, "lb/in³")] + [InlineData("en-US", MassConcentrationUnit.PoundPerImperialGallon, "ppg (imp.)")] + [InlineData("en-US", MassConcentrationUnit.PoundPerUSGallon, "ppg (U.S.)")] + [InlineData("en-US", MassConcentrationUnit.SlugPerCubicFoot, "slug/ft³")] + [InlineData("en-US", MassConcentrationUnit.TonnePerCubicCentimeter, "t/cm³")] + [InlineData("en-US", MassConcentrationUnit.TonnePerCubicMeter, "t/m³")] + [InlineData("en-US", MassConcentrationUnit.TonnePerCubicMillimeter, "t/mm³")] + [InlineData("ru-RU", MassConcentrationUnit.GramPerCubicMeter, "г/м³")] + [InlineData("ru-RU", MassConcentrationUnit.KilogramPerCubicMeter, "кг/м³")] + [InlineData("ru-RU", MassConcentrationUnit.MicrogramPerCubicMeter, "мкг/м³")] + [InlineData("ru-RU", MassConcentrationUnit.MilligramPerCubicMeter, "мг/м³")] + public void GetAbbreviationForCulture(string culture, MassConcentrationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MassConcentration.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MassConcentration.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MassConcentration.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassConcentrationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 788b220ee0..b943551269 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -462,574 +462,110 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg/d", MassFlowUnit.CentigramPerDay, 4.2)] + [InlineData("en-US", "4.2 cg/s", MassFlowUnit.CentigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 cg/S", MassFlowUnit.CentigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dag/d", MassFlowUnit.DecagramPerDay, 4.2)] + [InlineData("en-US", "4.2 dag/s", MassFlowUnit.DecagramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dag/S", MassFlowUnit.DecagramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dg/d", MassFlowUnit.DecigramPerDay, 4.2)] + [InlineData("en-US", "4.2 dg/s", MassFlowUnit.DecigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dg/S", MassFlowUnit.DecigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 g/d", MassFlowUnit.GramPerDay, 4.2)] + [InlineData("en-US", "4.2 g/h", MassFlowUnit.GramPerHour, 4.2)] + [InlineData("en-US", "4.2 g/s", MassFlowUnit.GramPerSecond, 4.2)] + [InlineData("en-US", "4.2 g/S", MassFlowUnit.GramPerSecond, 4.2)] + [InlineData("en-US", "4.2 hg/d", MassFlowUnit.HectogramPerDay, 4.2)] + [InlineData("en-US", "4.2 hg/s", MassFlowUnit.HectogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 hg/S", MassFlowUnit.HectogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 kg/d", MassFlowUnit.KilogramPerDay, 4.2)] + [InlineData("en-US", "4.2 kg/h", MassFlowUnit.KilogramPerHour, 4.2)] + [InlineData("en-US", "4.2 kg/min", MassFlowUnit.KilogramPerMinute, 4.2)] + [InlineData("en-US", "4.2 kg/s", MassFlowUnit.KilogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 kg/S", MassFlowUnit.KilogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mg/d", MassFlowUnit.MegagramPerDay, 4.2)] + [InlineData("en-US", "4.2 Mlb/d", MassFlowUnit.MegapoundPerDay, 4.2)] + [InlineData("en-US", "4.2 Mlb/h", MassFlowUnit.MegapoundPerHour, 4.2)] + [InlineData("en-US", "4.2 Mlb/min", MassFlowUnit.MegapoundPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mlb/s", MassFlowUnit.MegapoundPerSecond, 4.2)] + [InlineData("en-US", "4.2 µg/d", MassFlowUnit.MicrogramPerDay, 4.2)] + [InlineData("en-US", "4.2 µg/s", MassFlowUnit.MicrogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 µg/S", MassFlowUnit.MicrogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 mg/d", MassFlowUnit.MilligramPerDay, 4.2)] + [InlineData("en-US", "4.2 mg/s", MassFlowUnit.MilligramPerSecond, 4.2)] + [InlineData("en-US", "4.2 mg/S", MassFlowUnit.MilligramPerSecond, 4.2)] + [InlineData("en-US", "4.2 ng/d", MassFlowUnit.NanogramPerDay, 4.2)] + [InlineData("en-US", "4.2 ng/s", MassFlowUnit.NanogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 ng/S", MassFlowUnit.NanogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 lb/d", MassFlowUnit.PoundPerDay, 4.2)] + [InlineData("en-US", "4.2 lb/h", MassFlowUnit.PoundPerHour, 4.2)] + [InlineData("en-US", "4.2 lb/min", MassFlowUnit.PoundPerMinute, 4.2)] + [InlineData("en-US", "4.2 lb/s", MassFlowUnit.PoundPerSecond, 4.2)] + [InlineData("en-US", "4.2 short tn/h", MassFlowUnit.ShortTonPerHour, 4.2)] + [InlineData("en-US", "4.2 t/d", MassFlowUnit.TonnePerDay, 4.2)] + [InlineData("en-US", "4.2 t/h", MassFlowUnit.TonnePerHour, 4.2)] + [InlineData("ru-RU", "4,2 кг/ч", MassFlowUnit.KilogramPerHour, 4.2)] + [InlineData("ru-RU", "4,2 кг/мин", MassFlowUnit.KilogramPerMinute, 4.2)] + public void Parse(string culture, string quantityString, MassFlowUnit expectedUnit, double expectedValue) { - try - { - var parsed = MassFlow.Parse("1 cg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDay, CentigramsPerDayTolerance); - Assert.Equal(MassFlowUnit.CentigramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 cg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerSecond, CentigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 cg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerSecond, CentigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dag/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerDay, DecagramsPerDayTolerance); - Assert.Equal(MassFlowUnit.DecagramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dag/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerSecond, DecagramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dag/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerSecond, DecagramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDay, DecigramsPerDayTolerance); - Assert.Equal(MassFlowUnit.DecigramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerSecond, DecigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 dg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerSecond, DecigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 g/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerDay, GramsPerDayTolerance); - Assert.Equal(MassFlowUnit.GramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 g/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerHour, GramsPerHourTolerance); - Assert.Equal(MassFlowUnit.GramPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 g/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSecond, GramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.GramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 g/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSecond, GramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.GramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 hg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerDay, HectogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.HectogramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 hg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerSecond, HectogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 hg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerSecond, HectogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 kg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerDay, KilogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.KilogramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 kg/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHour, KilogramsPerHourTolerance); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 кг/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHour, KilogramsPerHourTolerance); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 kg/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMinute, KilogramsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 кг/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMinute, KilogramsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 kg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecond, KilogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 kg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecond, KilogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 Mg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegagramsPerDay, MegagramsPerDayTolerance); - Assert.Equal(MassFlowUnit.MegagramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 Mlb/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerDay, MegapoundsPerDayTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 Mlb/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerHour, MegapoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 Mlb/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMinute, MegapoundsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 Mlb/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerSecond, MegapoundsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 µg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDay, MicrogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 µg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerSecond, MicrogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 µg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerSecond, MicrogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 mg/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerDay, MilligramsPerDayTolerance); - Assert.Equal(MassFlowUnit.MilligramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 mg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSecond, MilligramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 mg/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSecond, MilligramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 ng/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDay, NanogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.NanogramPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 ng/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerSecond, NanogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 ng/S", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerSecond, NanogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 lb/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerDay, PoundsPerDayTolerance); - Assert.Equal(MassFlowUnit.PoundPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 lb/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerHour, PoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.PoundPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 lb/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerMinute, PoundsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.PoundPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 lb/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecond, PoundsPerSecondTolerance); - Assert.Equal(MassFlowUnit.PoundPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 short tn/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTonsPerHour, ShortTonsPerHourTolerance); - Assert.Equal(MassFlowUnit.ShortTonPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 t/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerDay, TonnesPerDayTolerance); - Assert.Equal(MassFlowUnit.TonnePerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlow.Parse("1 t/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesPerHour, TonnesPerHourTolerance); - Assert.Equal(MassFlowUnit.TonnePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MassFlow.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cg/d", MassFlowUnit.CentigramPerDay, 4.2)] + [InlineData("en-US", "4.2 cg/s", MassFlowUnit.CentigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 cg/S", MassFlowUnit.CentigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dag/d", MassFlowUnit.DecagramPerDay, 4.2)] + [InlineData("en-US", "4.2 dag/s", MassFlowUnit.DecagramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dag/S", MassFlowUnit.DecagramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dg/d", MassFlowUnit.DecigramPerDay, 4.2)] + [InlineData("en-US", "4.2 dg/s", MassFlowUnit.DecigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 dg/S", MassFlowUnit.DecigramPerSecond, 4.2)] + [InlineData("en-US", "4.2 g/d", MassFlowUnit.GramPerDay, 4.2)] + [InlineData("en-US", "4.2 g/h", MassFlowUnit.GramPerHour, 4.2)] + [InlineData("en-US", "4.2 g/s", MassFlowUnit.GramPerSecond, 4.2)] + [InlineData("en-US", "4.2 g/S", MassFlowUnit.GramPerSecond, 4.2)] + [InlineData("en-US", "4.2 hg/d", MassFlowUnit.HectogramPerDay, 4.2)] + [InlineData("en-US", "4.2 hg/s", MassFlowUnit.HectogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 hg/S", MassFlowUnit.HectogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 kg/d", MassFlowUnit.KilogramPerDay, 4.2)] + [InlineData("en-US", "4.2 kg/h", MassFlowUnit.KilogramPerHour, 4.2)] + [InlineData("en-US", "4.2 kg/min", MassFlowUnit.KilogramPerMinute, 4.2)] + [InlineData("en-US", "4.2 kg/s", MassFlowUnit.KilogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 kg/S", MassFlowUnit.KilogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mg/d", MassFlowUnit.MegagramPerDay, 4.2)] + [InlineData("en-US", "4.2 Mlb/d", MassFlowUnit.MegapoundPerDay, 4.2)] + [InlineData("en-US", "4.2 Mlb/h", MassFlowUnit.MegapoundPerHour, 4.2)] + [InlineData("en-US", "4.2 Mlb/min", MassFlowUnit.MegapoundPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mlb/s", MassFlowUnit.MegapoundPerSecond, 4.2)] + [InlineData("en-US", "4.2 µg/d", MassFlowUnit.MicrogramPerDay, 4.2)] + [InlineData("en-US", "4.2 µg/s", MassFlowUnit.MicrogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 µg/S", MassFlowUnit.MicrogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 mg/d", MassFlowUnit.MilligramPerDay, 4.2)] + [InlineData("en-US", "4.2 mg/s", MassFlowUnit.MilligramPerSecond, 4.2)] + [InlineData("en-US", "4.2 mg/S", MassFlowUnit.MilligramPerSecond, 4.2)] + [InlineData("en-US", "4.2 ng/d", MassFlowUnit.NanogramPerDay, 4.2)] + [InlineData("en-US", "4.2 ng/s", MassFlowUnit.NanogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 ng/S", MassFlowUnit.NanogramPerSecond, 4.2)] + [InlineData("en-US", "4.2 lb/d", MassFlowUnit.PoundPerDay, 4.2)] + [InlineData("en-US", "4.2 lb/h", MassFlowUnit.PoundPerHour, 4.2)] + [InlineData("en-US", "4.2 lb/min", MassFlowUnit.PoundPerMinute, 4.2)] + [InlineData("en-US", "4.2 lb/s", MassFlowUnit.PoundPerSecond, 4.2)] + [InlineData("en-US", "4.2 short tn/h", MassFlowUnit.ShortTonPerHour, 4.2)] + [InlineData("en-US", "4.2 t/d", MassFlowUnit.TonnePerDay, 4.2)] + [InlineData("en-US", "4.2 t/h", MassFlowUnit.TonnePerHour, 4.2)] + [InlineData("ru-RU", "4,2 кг/ч", MassFlowUnit.KilogramPerHour, 4.2)] + [InlineData("ru-RU", "4,2 кг/мин", MassFlowUnit.KilogramPerMinute, 4.2)] + public void TryParse(string culture, string quantityString, MassFlowUnit expectedUnit, double expectedValue) { - { - Assert.True(MassFlow.TryParse("1 cg/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerDay, CentigramsPerDayTolerance); - Assert.Equal(MassFlowUnit.CentigramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 cg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerSecond, CentigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 cg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerSecond, CentigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dag/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerDay, DecagramsPerDayTolerance); - Assert.Equal(MassFlowUnit.DecagramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dag/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerSecond, DecagramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dag/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerSecond, DecagramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dg/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerDay, DecigramsPerDayTolerance); - Assert.Equal(MassFlowUnit.DecigramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerSecond, DecigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 dg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerSecond, DecigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 g/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerDay, GramsPerDayTolerance); - Assert.Equal(MassFlowUnit.GramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 g/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerHour, GramsPerHourTolerance); - Assert.Equal(MassFlowUnit.GramPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 g/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSecond, GramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.GramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 g/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSecond, GramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.GramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 hg/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerDay, HectogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.HectogramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 hg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerSecond, HectogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 hg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerSecond, HectogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 kg/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerDay, KilogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.KilogramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 kg/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHour, KilogramsPerHourTolerance); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 кг/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHour, KilogramsPerHourTolerance); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 kg/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMinute, KilogramsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 кг/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMinute, KilogramsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 kg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecond, KilogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 kg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecond, KilogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 Mlb/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerDay, MegapoundsPerDayTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 Mlb/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerHour, MegapoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 Mlb/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMinute, MegapoundsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerMinute, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 Mlb/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerSecond, MegapoundsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 µg/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerDay, MicrogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 µg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerSecond, MicrogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 µg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerSecond, MicrogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 mg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSecond, MilligramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 mg/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerSecond, MilligramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 ng/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerDay, NanogramsPerDayTolerance); - Assert.Equal(MassFlowUnit.NanogramPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 ng/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerSecond, NanogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 ng/S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerSecond, NanogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 lb/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerDay, PoundsPerDayTolerance); - Assert.Equal(MassFlowUnit.PoundPerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 lb/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerHour, PoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.PoundPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 lb/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerMinute, PoundsPerMinuteTolerance); - Assert.Equal(MassFlowUnit.PoundPerMinute, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 lb/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerSecond, PoundsPerSecondTolerance); - Assert.Equal(MassFlowUnit.PoundPerSecond, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 short tn/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTonsPerHour, ShortTonsPerHourTolerance); - Assert.Equal(MassFlowUnit.ShortTonPerHour, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 t/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerDay, TonnesPerDayTolerance); - Assert.Equal(MassFlowUnit.TonnePerDay, parsed.Unit); - } - - { - Assert.True(MassFlow.TryParse("1 t/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesPerHour, TonnesPerHourTolerance); - Assert.Equal(MassFlowUnit.TonnePerHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MassFlow.TryParse(quantityString, out MassFlow parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1442,6 +978,61 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFl Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MassFlowUnit.CentigramPerDay, "cg/d")] + [InlineData("en-US", MassFlowUnit.CentigramPerSecond, "cg/s")] + [InlineData("en-US", MassFlowUnit.DecagramPerDay, "dag/d")] + [InlineData("en-US", MassFlowUnit.DecagramPerSecond, "dag/s")] + [InlineData("en-US", MassFlowUnit.DecigramPerDay, "dg/d")] + [InlineData("en-US", MassFlowUnit.DecigramPerSecond, "dg/s")] + [InlineData("en-US", MassFlowUnit.GramPerDay, "g/d")] + [InlineData("en-US", MassFlowUnit.GramPerHour, "g/h")] + [InlineData("en-US", MassFlowUnit.GramPerSecond, "g/s")] + [InlineData("en-US", MassFlowUnit.HectogramPerDay, "hg/d")] + [InlineData("en-US", MassFlowUnit.HectogramPerSecond, "hg/s")] + [InlineData("en-US", MassFlowUnit.KilogramPerDay, "kg/d")] + [InlineData("en-US", MassFlowUnit.KilogramPerHour, "kg/h")] + [InlineData("en-US", MassFlowUnit.KilogramPerMinute, "kg/min")] + [InlineData("en-US", MassFlowUnit.KilogramPerSecond, "kg/s")] + [InlineData("en-US", MassFlowUnit.MegagramPerDay, "Mg/d")] + [InlineData("en-US", MassFlowUnit.MegapoundPerDay, "Mlb/d")] + [InlineData("en-US", MassFlowUnit.MegapoundPerHour, "Mlb/h")] + [InlineData("en-US", MassFlowUnit.MegapoundPerMinute, "Mlb/min")] + [InlineData("en-US", MassFlowUnit.MegapoundPerSecond, "Mlb/s")] + [InlineData("en-US", MassFlowUnit.MicrogramPerDay, "µg/d")] + [InlineData("en-US", MassFlowUnit.MicrogramPerSecond, "µg/s")] + [InlineData("en-US", MassFlowUnit.MilligramPerDay, "mg/d")] + [InlineData("en-US", MassFlowUnit.MilligramPerSecond, "mg/s")] + [InlineData("en-US", MassFlowUnit.NanogramPerDay, "ng/d")] + [InlineData("en-US", MassFlowUnit.NanogramPerSecond, "ng/s")] + [InlineData("en-US", MassFlowUnit.PoundPerDay, "lb/d")] + [InlineData("en-US", MassFlowUnit.PoundPerHour, "lb/h")] + [InlineData("en-US", MassFlowUnit.PoundPerMinute, "lb/min")] + [InlineData("en-US", MassFlowUnit.PoundPerSecond, "lb/s")] + [InlineData("en-US", MassFlowUnit.ShortTonPerHour, "short tn/h")] + [InlineData("en-US", MassFlowUnit.TonnePerDay, "t/d")] + [InlineData("en-US", MassFlowUnit.TonnePerHour, "t/h")] + [InlineData("ru-RU", MassFlowUnit.KilogramPerHour, "кг/ч")] + [InlineData("ru-RU", MassFlowUnit.KilogramPerMinute, "кг/мин")] + public void GetAbbreviationForCulture(string culture, MassFlowUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MassFlow.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MassFlow.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MassFlow.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassFlowUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index ca1decc5a4..43e6e155dc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -336,170 +336,46 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter, 4.2)] + public void Parse(string culture, string quantityString, MassFluxUnit expectedUnit, double expectedValue) { - try - { - var parsed = MassFlux.Parse("1 g·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareCentimeter, GramsPerHourPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 g·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareMeter, GramsPerHourPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 g·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareMillimeter, GramsPerHourPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 g·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareCentimeter, GramsPerSecondPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 g·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 g·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareMillimeter, GramsPerSecondPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareCentimeter, KilogramsPerHourPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareMeter, KilogramsPerHourPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareMillimeter, KilogramsPerHourPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareCentimeter, KilogramsPerSecondPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFlux.Parse("1 kg·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareMillimeter, KilogramsPerSecondPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MassFlux.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, MassFluxUnit expectedUnit, double expectedValue) { - { - Assert.True(MassFlux.TryParse("1 g·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareCentimeter, GramsPerHourPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 g·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareMeter, GramsPerHourPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 g·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerHourPerSquareMillimeter, GramsPerHourPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 g·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareCentimeter, GramsPerSecondPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 g·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 g·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerSecondPerSquareMillimeter, GramsPerSecondPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareCentimeter, KilogramsPerHourPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareMeter, KilogramsPerHourPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerHourPerSquareMillimeter, KilogramsPerHourPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareCentimeter, KilogramsPerSecondPerSquareCentimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, parsed.Unit); - } - - { - Assert.True(MassFlux.TryParse("1 kg·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerSecondPerSquareMillimeter, KilogramsPerSecondPerSquareMillimeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MassFlux.TryParse(quantityString, out MassFlux parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -664,6 +540,38 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFl Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MassFluxUnit.GramPerHourPerSquareCentimeter, "g·h⁻¹·cm⁻²")] + [InlineData("en-US", MassFluxUnit.GramPerHourPerSquareMeter, "g·h⁻¹·m⁻²")] + [InlineData("en-US", MassFluxUnit.GramPerHourPerSquareMillimeter, "g·h⁻¹·mm⁻²")] + [InlineData("en-US", MassFluxUnit.GramPerSecondPerSquareCentimeter, "g·s⁻¹·cm⁻²")] + [InlineData("en-US", MassFluxUnit.GramPerSecondPerSquareMeter, "g·s⁻¹·m⁻²")] + [InlineData("en-US", MassFluxUnit.GramPerSecondPerSquareMillimeter, "g·s⁻¹·mm⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerHourPerSquareCentimeter, "kg·h⁻¹·cm⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerHourPerSquareMeter, "kg·h⁻¹·m⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerHourPerSquareMillimeter, "kg·h⁻¹·mm⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerSecondPerSquareCentimeter, "kg·s⁻¹·cm⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerSecondPerSquareMeter, "kg·s⁻¹·m⁻²")] + [InlineData("en-US", MassFluxUnit.KilogramPerSecondPerSquareMillimeter, "kg·s⁻¹·mm⁻²")] + public void GetAbbreviationForCulture(string culture, MassFluxUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MassFlux.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MassFlux.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MassFlux.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassFluxUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index b720429ccf..4c46951652 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -348,339 +348,72 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg/g", MassFractionUnit.CentigramPerGram, 4.2)] + [InlineData("en-US", "4.2 cg/kg", MassFractionUnit.CentigramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 dag/g", MassFractionUnit.DecagramPerGram, 4.2)] + [InlineData("en-US", "4.2 dag/kg", MassFractionUnit.DecagramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 dg/g", MassFractionUnit.DecigramPerGram, 4.2)] + [InlineData("en-US", "4.2 dg/kg", MassFractionUnit.DecigramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ", MassFractionUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 g/g", MassFractionUnit.GramPerGram, 4.2)] + [InlineData("en-US", "4.2 g/kg", MassFractionUnit.GramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 hg/g", MassFractionUnit.HectogramPerGram, 4.2)] + [InlineData("en-US", "4.2 hg/kg", MassFractionUnit.HectogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kg/g", MassFractionUnit.KilogramPerGram, 4.2)] + [InlineData("en-US", "4.2 kg/kg", MassFractionUnit.KilogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µg/g", MassFractionUnit.MicrogramPerGram, 4.2)] + [InlineData("en-US", "4.2 µg/kg", MassFractionUnit.MicrogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mg/g", MassFractionUnit.MilligramPerGram, 4.2)] + [InlineData("en-US", "4.2 mg/kg", MassFractionUnit.MilligramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ng/g", MassFractionUnit.NanogramPerGram, 4.2)] + [InlineData("en-US", "4.2 ng/kg", MassFractionUnit.NanogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ppb", MassFractionUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", MassFractionUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", MassFractionUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", MassFractionUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", MassFractionUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 % (w/w)", MassFractionUnit.Percent, 4.2)] + public void Parse(string culture, string quantityString, MassFractionUnit expectedUnit, double expectedValue) { - try - { - var parsed = MassFraction.Parse("1 cg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerGram, CentigramsPerGramTolerance); - Assert.Equal(MassFractionUnit.CentigramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 cg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerKilogram, CentigramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.CentigramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 dag/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerGram, DecagramsPerGramTolerance); - Assert.Equal(MassFractionUnit.DecagramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 dag/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerKilogram, DecagramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.DecagramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 dg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerGram, DecigramsPerGramTolerance); - Assert.Equal(MassFractionUnit.DecigramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 dg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerKilogram, DecigramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.DecigramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(MassFractionUnit.DecimalFraction, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 g/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerGram, GramsPerGramTolerance); - Assert.Equal(MassFractionUnit.GramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 g/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerKilogram, GramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.GramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 hg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerGram, HectogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.HectogramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 hg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerKilogram, HectogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.HectogramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 kg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerGram, KilogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.KilogramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 kg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilogram, KilogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.KilogramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 µg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerGram, MicrogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.MicrogramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 µg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerKilogram, MicrogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.MicrogramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 mg/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerGram, MilligramsPerGramTolerance); - Assert.Equal(MassFractionUnit.MilligramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 mg/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerKilogram, MilligramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.MilligramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ng/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerGram, NanogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.NanogramPerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ng/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerKilogram, NanogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.NanogramPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ppb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(MassFractionUnit.PartPerBillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ppm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(MassFractionUnit.PartPerMillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ‰", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(MassFractionUnit.PartPerThousand, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 ppt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(MassFractionUnit.PartPerTrillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 %", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(MassFractionUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassFraction.Parse("1 % (w/w)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(MassFractionUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MassFraction.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cg/g", MassFractionUnit.CentigramPerGram, 4.2)] + [InlineData("en-US", "4.2 cg/kg", MassFractionUnit.CentigramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 dag/g", MassFractionUnit.DecagramPerGram, 4.2)] + [InlineData("en-US", "4.2 dag/kg", MassFractionUnit.DecagramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 dg/g", MassFractionUnit.DecigramPerGram, 4.2)] + [InlineData("en-US", "4.2 dg/kg", MassFractionUnit.DecigramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ", MassFractionUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 g/g", MassFractionUnit.GramPerGram, 4.2)] + [InlineData("en-US", "4.2 g/kg", MassFractionUnit.GramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 hg/g", MassFractionUnit.HectogramPerGram, 4.2)] + [InlineData("en-US", "4.2 hg/kg", MassFractionUnit.HectogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kg/g", MassFractionUnit.KilogramPerGram, 4.2)] + [InlineData("en-US", "4.2 kg/kg", MassFractionUnit.KilogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µg/g", MassFractionUnit.MicrogramPerGram, 4.2)] + [InlineData("en-US", "4.2 µg/kg", MassFractionUnit.MicrogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mg/g", MassFractionUnit.MilligramPerGram, 4.2)] + [InlineData("en-US", "4.2 mg/kg", MassFractionUnit.MilligramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ng/g", MassFractionUnit.NanogramPerGram, 4.2)] + [InlineData("en-US", "4.2 ng/kg", MassFractionUnit.NanogramPerKilogram, 4.2)] + [InlineData("en-US", "4.2 ppb", MassFractionUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", MassFractionUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", MassFractionUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", MassFractionUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", MassFractionUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 % (w/w)", MassFractionUnit.Percent, 4.2)] + public void TryParse(string culture, string quantityString, MassFractionUnit expectedUnit, double expectedValue) { - { - Assert.True(MassFraction.TryParse("1 cg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerGram, CentigramsPerGramTolerance); - Assert.Equal(MassFractionUnit.CentigramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 cg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerKilogram, CentigramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.CentigramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 dag/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerGram, DecagramsPerGramTolerance); - Assert.Equal(MassFractionUnit.DecagramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 dag/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerKilogram, DecagramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.DecagramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 dg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerGram, DecigramsPerGramTolerance); - Assert.Equal(MassFractionUnit.DecigramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 dg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerKilogram, DecigramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.DecigramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(MassFractionUnit.DecimalFraction, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 g/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerGram, GramsPerGramTolerance); - Assert.Equal(MassFractionUnit.GramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 g/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerKilogram, GramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.GramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 hg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerGram, HectogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.HectogramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 hg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerKilogram, HectogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.HectogramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 kg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerGram, KilogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.KilogramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 kg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilogram, KilogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.KilogramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 µg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerGram, MicrogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.MicrogramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 µg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerKilogram, MicrogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.MicrogramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 mg/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerGram, MilligramsPerGramTolerance); - Assert.Equal(MassFractionUnit.MilligramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 mg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerKilogram, MilligramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.MilligramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ng/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerGram, NanogramsPerGramTolerance); - Assert.Equal(MassFractionUnit.NanogramPerGram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ng/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerKilogram, NanogramsPerKilogramTolerance); - Assert.Equal(MassFractionUnit.NanogramPerKilogram, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ppb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(MassFractionUnit.PartPerBillion, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ppm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(MassFractionUnit.PartPerMillion, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ‰", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(MassFractionUnit.PartPerThousand, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 ppt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(MassFractionUnit.PartPerTrillion, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 %", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(MassFractionUnit.Percent, parsed.Unit); - } - - { - Assert.True(MassFraction.TryParse("1 % (w/w)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(MassFractionUnit.Percent, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MassFraction.TryParse(quantityString, out MassFraction parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -949,6 +682,50 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MassFractionUnit.CentigramPerGram, "cg/g")] + [InlineData("en-US", MassFractionUnit.CentigramPerKilogram, "cg/kg")] + [InlineData("en-US", MassFractionUnit.DecagramPerGram, "dag/g")] + [InlineData("en-US", MassFractionUnit.DecagramPerKilogram, "dag/kg")] + [InlineData("en-US", MassFractionUnit.DecigramPerGram, "dg/g")] + [InlineData("en-US", MassFractionUnit.DecigramPerKilogram, "dg/kg")] + [InlineData("en-US", MassFractionUnit.DecimalFraction, "")] + [InlineData("en-US", MassFractionUnit.GramPerGram, "g/g")] + [InlineData("en-US", MassFractionUnit.GramPerKilogram, "g/kg")] + [InlineData("en-US", MassFractionUnit.HectogramPerGram, "hg/g")] + [InlineData("en-US", MassFractionUnit.HectogramPerKilogram, "hg/kg")] + [InlineData("en-US", MassFractionUnit.KilogramPerGram, "kg/g")] + [InlineData("en-US", MassFractionUnit.KilogramPerKilogram, "kg/kg")] + [InlineData("en-US", MassFractionUnit.MicrogramPerGram, "µg/g")] + [InlineData("en-US", MassFractionUnit.MicrogramPerKilogram, "µg/kg")] + [InlineData("en-US", MassFractionUnit.MilligramPerGram, "mg/g")] + [InlineData("en-US", MassFractionUnit.MilligramPerKilogram, "mg/kg")] + [InlineData("en-US", MassFractionUnit.NanogramPerGram, "ng/g")] + [InlineData("en-US", MassFractionUnit.NanogramPerKilogram, "ng/kg")] + [InlineData("en-US", MassFractionUnit.PartPerBillion, "ppb")] + [InlineData("en-US", MassFractionUnit.PartPerMillion, "ppm")] + [InlineData("en-US", MassFractionUnit.PartPerThousand, "‰")] + [InlineData("en-US", MassFractionUnit.PartPerTrillion, "ppt")] + [InlineData("en-US", MassFractionUnit.Percent, "%")] + public void GetAbbreviationForCulture(string culture, MassFractionUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MassFraction.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MassFraction.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MassFraction.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassFractionUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index 6ca2cb58ed..be704147f6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -432,378 +432,78 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 g·m²", MassMomentOfInertiaUnit.GramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot, 4.2)] + [InlineData("en-US", "4.2 lb·in²", MassMomentOfInertiaUnit.PoundSquareInch, 4.2)] + [InlineData("en-US", "4.2 slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot, 4.2)] + [InlineData("en-US", "4.2 slug·in²", MassMomentOfInertiaUnit.SlugSquareInch, 4.2)] + [InlineData("en-US", "4.2 t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 t·m²", MassMomentOfInertiaUnit.TonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 t·mm²", MassMomentOfInertiaUnit.TonneSquareMillimeter, 4.2)] + public void Parse(string culture, string quantityString, MassMomentOfInertiaUnit expectedUnit, double expectedValue) { - try - { - var parsed = MassMomentOfInertia.Parse("1 g·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramSquareCentimeters, GramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 g·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramSquareDecimeters, GramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 g·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramSquareMeters, GramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 g·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramSquareMillimeters, GramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kg·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramSquareCentimeters, KilogramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kg·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramSquareDecimeters, KilogramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kg·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramSquareMeters, KilogramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kg·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramSquareMillimeters, KilogramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kt·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareCentimeters, KilotonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kt·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareDecimeters, KilotonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kt·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareMeters, KilotonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 kt·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareMillimeters, KilotonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 Mt·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareCentimeters, MegatonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 Mt·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareDecimeters, MegatonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 Mt·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareMeters, MegatonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 Mt·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareMillimeters, MegatonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 mg·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramSquareCentimeters, MilligramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 mg·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramSquareDecimeters, MilligramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 mg·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramSquareMeters, MilligramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 mg·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 lb·ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundSquareFeet, PoundSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 lb·in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundSquareInches, PoundSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 slug·ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugSquareFeet, SlugSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 slug·in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SlugSquareInches, SlugSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 t·cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneSquareCentimeters, TonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 t·dm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneSquareDecimeters, TonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 t·m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneSquareMeters, TonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MassMomentOfInertia.Parse("1 t·mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneSquareMillimeters, TonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MassMomentOfInertia.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 g·m²", MassMomentOfInertiaUnit.GramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter, 4.2)] + [InlineData("en-US", "4.2 mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot, 4.2)] + [InlineData("en-US", "4.2 lb·in²", MassMomentOfInertiaUnit.PoundSquareInch, 4.2)] + [InlineData("en-US", "4.2 slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot, 4.2)] + [InlineData("en-US", "4.2 slug·in²", MassMomentOfInertiaUnit.SlugSquareInch, 4.2)] + [InlineData("en-US", "4.2 t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 t·m²", MassMomentOfInertiaUnit.TonneSquareMeter, 4.2)] + [InlineData("en-US", "4.2 t·mm²", MassMomentOfInertiaUnit.TonneSquareMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, MassMomentOfInertiaUnit expectedUnit, double expectedValue) { - { - Assert.True(MassMomentOfInertia.TryParse("1 g·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramSquareCentimeters, GramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 g·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramSquareDecimeters, GramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 g·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramSquareMeters, GramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 g·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramSquareMillimeters, GramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kg·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramSquareCentimeters, KilogramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kg·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramSquareDecimeters, KilogramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kg·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramSquareMeters, KilogramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kg·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramSquareMillimeters, KilogramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kt·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareCentimeters, KilotonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kt·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareDecimeters, KilotonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kt·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareMeters, KilotonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 kt·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilotonneSquareMillimeters, KilotonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 Mt·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareCentimeters, MegatonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 Mt·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareDecimeters, MegatonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 Mt·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareMeters, MegatonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 Mt·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegatonneSquareMillimeters, MegatonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 mg·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramSquareCentimeters, MilligramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 mg·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramSquareDecimeters, MilligramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 mg·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramSquareMeters, MilligramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 mg·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMillimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 lb·ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundSquareFeet, PoundSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareFoot, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 lb·in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundSquareInches, PoundSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 slug·ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugSquareFeet, SlugSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 slug·in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SlugSquareInches, SlugSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 t·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneSquareCentimeters, TonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 t·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneSquareDecimeters, TonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareDecimeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 t·m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneSquareMeters, TonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMeter, parsed.Unit); - } - - { - Assert.True(MassMomentOfInertia.TryParse("1 t·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneSquareMillimeters, TonneSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MassMomentOfInertia.TryParse(quantityString, out MassMomentOfInertia parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1096,6 +796,54 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MassMo Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MassMomentOfInertiaUnit.GramSquareCentimeter, "g·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.GramSquareDecimeter, "g·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.GramSquareMeter, "g·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.GramSquareMillimeter, "g·mm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilogramSquareCentimeter, "kg·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilogramSquareDecimeter, "kg·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilogramSquareMeter, "kg·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilogramSquareMillimeter, "kg·mm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilotonneSquareCentimeter, "kt·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilotonneSquareDecimeter, "kt·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilotonneSquareMeter, "kt·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.KilotonneSquareMillimeter, "kt·mm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MegatonneSquareCentimeter, "Mt·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MegatonneSquareDecimeter, "Mt·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MegatonneSquareMeter, "Mt·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MegatonneSquareMillimeter, "Mt·mm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MilligramSquareCentimeter, "mg·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MilligramSquareDecimeter, "mg·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MilligramSquareMeter, "mg·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.MilligramSquareMillimeter, "mg·mm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.PoundSquareFoot, "lb·ft²")] + [InlineData("en-US", MassMomentOfInertiaUnit.PoundSquareInch, "lb·in²")] + [InlineData("en-US", MassMomentOfInertiaUnit.SlugSquareFoot, "slug·ft²")] + [InlineData("en-US", MassMomentOfInertiaUnit.SlugSquareInch, "slug·in²")] + [InlineData("en-US", MassMomentOfInertiaUnit.TonneSquareCentimeter, "t·cm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.TonneSquareDecimeter, "t·dm²")] + [InlineData("en-US", MassMomentOfInertiaUnit.TonneSquareMeter, "t·m²")] + [InlineData("en-US", MassMomentOfInertiaUnit.TonneSquareMillimeter, "t·mm²")] + public void GetAbbreviationForCulture(string culture, MassMomentOfInertiaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MassMomentOfInertia.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MassMomentOfInertia.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MassMomentOfInertia.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassMomentOfInertiaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index 4ada84e073..c1c57b7196 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -426,965 +426,182 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg", MassUnit.Centigram, 4.2)] + [InlineData("en-US", "4.2 dag", MassUnit.Decagram, 4.2)] + [InlineData("en-US", "4.2 dg", MassUnit.Decigram, 4.2)] + [InlineData("en-US", "4.2 em", MassUnit.EarthMass, 4.2)] + [InlineData("en-US", "4.2 fg", MassUnit.Femtogram, 4.2)] + [InlineData("en-US", "4.2 gr", MassUnit.Grain, 4.2)] + [InlineData("en-US", "4.2 g", MassUnit.Gram, 4.2)] + [InlineData("en-US", "4.2 hg", MassUnit.Hectogram, 4.2)] + [InlineData("en-US", "4.2 kg", MassUnit.Kilogram, 4.2)] + [InlineData("en-US", "4.2 klb", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 klbs", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 klbm", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 kt", MassUnit.Kilotonne, 4.2)] + [InlineData("en-US", "4.2 long tn", MassUnit.LongTon, 4.2)] + [InlineData("en-US", "4.2 Mlb", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mlbs", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mlbm", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mt", MassUnit.Megatonne, 4.2)] + [InlineData("en-US", "4.2 µg", MassUnit.Microgram, 4.2)] + [InlineData("en-US", "4.2 mg", MassUnit.Milligram, 4.2)] + [InlineData("en-US", "4.2 ng", MassUnit.Nanogram, 4.2)] + [InlineData("en-US", "4.2 oz", MassUnit.Ounce, 4.2)] + [InlineData("en-US", "4.2 pg", MassUnit.Picogram, 4.2)] + [InlineData("en-US", "4.2 lb", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 lbs", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 lbm", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 t (short)", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 short tn", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 ST", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 slug", MassUnit.Slug, 4.2)] + [InlineData("en-US", "4.2 M☉", MassUnit.SolarMass, 4.2)] + [InlineData("en-US", "4.2 M⊙", MassUnit.SolarMass, 4.2)] + [InlineData("en-US", "4.2 st", MassUnit.Stone, 4.2)] + [InlineData("en-US", "4.2 t", MassUnit.Tonne, 4.2)] + [InlineData("ru-RU", "4,2 сг", MassUnit.Centigram, 4.2)] + [InlineData("ru-RU", "4,2 даг", MassUnit.Decagram, 4.2)] + [InlineData("ru-RU", "4,2 дг", MassUnit.Decigram, 4.2)] + [InlineData("ru-RU", "4,2 фг", MassUnit.Femtogram, 4.2)] + [InlineData("ru-RU", "4,2 г", MassUnit.Gram, 4.2)] + [InlineData("ru-RU", "4,2 гг", MassUnit.Hectogram, 4.2)] + [InlineData("ru-RU", "4,2 кг", MassUnit.Kilogram, 4.2)] + [InlineData("ru-RU", "4,2 кфунт", MassUnit.Kilopound, 4.2)] + [InlineData("ru-RU", "4,2 кт", MassUnit.Kilotonne, 4.2)] + [InlineData("ru-RU", "4,2 тонна большая", MassUnit.LongTon, 4.2)] + [InlineData("ru-RU", "4,2 Мфунт", MassUnit.Megapound, 4.2)] + [InlineData("ru-RU", "4,2 Мт", MassUnit.Megatonne, 4.2)] + [InlineData("ru-RU", "4,2 мкг", MassUnit.Microgram, 4.2)] + [InlineData("ru-RU", "4,2 мг", MassUnit.Milligram, 4.2)] + [InlineData("ru-RU", "4,2 нг", MassUnit.Nanogram, 4.2)] + [InlineData("ru-RU", "4,2 пг", MassUnit.Picogram, 4.2)] + [InlineData("ru-RU", "4,2 фунт", MassUnit.Pound, 4.2)] + [InlineData("ru-RU", "4,2 тонна малая", MassUnit.ShortTon, 4.2)] + [InlineData("ru-RU", "4,2 т", MassUnit.Tonne, 4.2)] + [InlineData("zh-CN", "4.2 厘克", MassUnit.Centigram, 4.2)] + [InlineData("zh-CN", "4.2 十克", MassUnit.Decagram, 4.2)] + [InlineData("zh-CN", "4.2 分克", MassUnit.Decigram, 4.2)] + [InlineData("zh-CN", "4.2 飞克", MassUnit.Femtogram, 4.2)] + [InlineData("zh-CN", "4.2 克", MassUnit.Gram, 4.2)] + [InlineData("zh-CN", "4.2 百克", MassUnit.Hectogram, 4.2)] + [InlineData("zh-CN", "4.2 千克", MassUnit.Kilogram, 4.2)] + [InlineData("zh-CN", "4.2 千磅", MassUnit.Kilopound, 4.2)] + [InlineData("zh-CN", "4.2 千吨", MassUnit.Kilotonne, 4.2)] + [InlineData("zh-CN", "4.2 长吨", MassUnit.LongTon, 4.2)] + [InlineData("zh-CN", "4.2 兆磅", MassUnit.Megapound, 4.2)] + [InlineData("zh-CN", "4.2 兆吨", MassUnit.Megatonne, 4.2)] + [InlineData("zh-CN", "4.2 微克", MassUnit.Microgram, 4.2)] + [InlineData("zh-CN", "4.2 毫克", MassUnit.Milligram, 4.2)] + [InlineData("zh-CN", "4.2 纳克", MassUnit.Nanogram, 4.2)] + [InlineData("zh-CN", "4.2 盎司", MassUnit.Ounce, 4.2)] + [InlineData("zh-CN", "4.2 皮克", MassUnit.Picogram, 4.2)] + [InlineData("zh-CN", "4.2 磅", MassUnit.Pound, 4.2)] + [InlineData("zh-CN", "4.2 短吨", MassUnit.ShortTon, 4.2)] + [InlineData("zh-CN", "4.2 吨", MassUnit.Tonne, 4.2)] + public void Parse(string culture, string quantityString, MassUnit expectedUnit, double expectedValue) { - try - { - var parsed = Mass.Parse("1 cg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 сг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 厘克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 dag", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 даг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 十克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 dg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 дг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 分克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 em", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.EarthMasses, EarthMassesTolerance); - Assert.Equal(MassUnit.EarthMass, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 fg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 фг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 飞克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 gr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Grains, GrainsTolerance); - Assert.Equal(MassUnit.Grain, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 г", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 hg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 гг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 百克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 кг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 千克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 klb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 klbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 klbm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 кфунт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 千磅", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 kt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 кт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 千吨", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 cwt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LongHundredweight, LongHundredweightTolerance); - Assert.Equal(MassUnit.LongHundredweight, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 long tn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 тонна большая", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 长吨", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Mlb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Mlbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Mlbm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Мфунт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 兆磅", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Mt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 Мт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 兆吨", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 µg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 мкг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 微克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 mg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 мг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 毫克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 ng", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 нг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 纳克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 oz", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Ounces, OuncesTolerance); - Assert.Equal(MassUnit.Ounce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 盎司", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Ounces, OuncesTolerance); - Assert.Equal(MassUnit.Ounce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 pg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 пг", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 皮克", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 lb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 lbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 lbm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 фунт", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 磅", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 cwt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortHundredweight, ShortHundredweightTolerance); - Assert.Equal(MassUnit.ShortHundredweight, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 t (short)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 short tn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 тонна малая", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 短吨", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 slug", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Slugs, SlugsTolerance); - Assert.Equal(MassUnit.Slug, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 M☉", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SolarMasses, SolarMassesTolerance); - Assert.Equal(MassUnit.SolarMass, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 M⊙", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SolarMasses, SolarMassesTolerance); - Assert.Equal(MassUnit.SolarMass, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 st", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Stone, StoneTolerance); - Assert.Equal(MassUnit.Stone, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 т", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Mass.Parse("1 吨", CultureInfo.GetCultureInfo("zh-CN")); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Mass.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "1 cwt")] // [LongHundredweight, ShortHundredweight] + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) { - { - Assert.True(Mass.TryParse("1 cg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 сг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 厘克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centigrams, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 dag", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 даг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 十克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decagrams, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 dg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 дг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 分克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decigrams, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 em", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.EarthMasses, EarthMassesTolerance); - Assert.Equal(MassUnit.EarthMass, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 fg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 фг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 飞克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtograms, FemtogramsTolerance); - Assert.Equal(MassUnit.Femtogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 gr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grains, GrainsTolerance); - Assert.Equal(MassUnit.Grain, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 г", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Grams, GramsTolerance); - Assert.Equal(MassUnit.Gram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 hg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 гг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 百克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectograms, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 кг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 千克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilograms, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 klb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 klbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 klbm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 кфунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 千磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopounds, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 kt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 кт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 千吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilotonnes, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 long tn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 тонна большая", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 长吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LongTons, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Mlb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Mlbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Mlbm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Мфунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 兆磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megapounds, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Mt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 Мт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 兆吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Megatonnes, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 µg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 мкг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 微克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micrograms, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 mg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 мг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 毫克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milligrams, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 ng", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 нг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 纳克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanograms, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 oz", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ounces, OuncesTolerance); - Assert.Equal(MassUnit.Ounce, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 盎司", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Ounces, OuncesTolerance); - Assert.Equal(MassUnit.Ounce, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 pg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 пг", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 皮克", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picograms, PicogramsTolerance); - Assert.Equal(MassUnit.Picogram, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 lb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 lbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 lbm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 фунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pounds, PoundsTolerance); - Assert.Equal(MassUnit.Pound, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 t (short)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 short tn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 тонна малая", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 短吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ShortTons, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 slug", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Slugs, SlugsTolerance); - Assert.Equal(MassUnit.Slug, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 M☉", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SolarMasses, SolarMassesTolerance); - Assert.Equal(MassUnit.SolarMass, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 M⊙", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SolarMasses, SolarMassesTolerance); - Assert.Equal(MassUnit.SolarMass, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } - - { - Assert.True(Mass.TryParse("1 т", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } + Assert.Throws(() => Mass.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Mass.TryParse("1 吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Tonnes, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 cg", MassUnit.Centigram, 4.2)] + [InlineData("en-US", "4.2 dag", MassUnit.Decagram, 4.2)] + [InlineData("en-US", "4.2 dg", MassUnit.Decigram, 4.2)] + [InlineData("en-US", "4.2 em", MassUnit.EarthMass, 4.2)] + [InlineData("en-US", "4.2 fg", MassUnit.Femtogram, 4.2)] + [InlineData("en-US", "4.2 gr", MassUnit.Grain, 4.2)] + [InlineData("en-US", "4.2 g", MassUnit.Gram, 4.2)] + [InlineData("en-US", "4.2 hg", MassUnit.Hectogram, 4.2)] + [InlineData("en-US", "4.2 kg", MassUnit.Kilogram, 4.2)] + [InlineData("en-US", "4.2 klb", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 klbs", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 klbm", MassUnit.Kilopound, 4.2)] + [InlineData("en-US", "4.2 kt", MassUnit.Kilotonne, 4.2)] + [InlineData("en-US", "4.2 long tn", MassUnit.LongTon, 4.2)] + [InlineData("en-US", "4.2 Mlb", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mlbs", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mlbm", MassUnit.Megapound, 4.2)] + [InlineData("en-US", "4.2 Mt", MassUnit.Megatonne, 4.2)] + [InlineData("en-US", "4.2 µg", MassUnit.Microgram, 4.2)] + [InlineData("en-US", "4.2 mg", MassUnit.Milligram, 4.2)] + [InlineData("en-US", "4.2 ng", MassUnit.Nanogram, 4.2)] + [InlineData("en-US", "4.2 oz", MassUnit.Ounce, 4.2)] + [InlineData("en-US", "4.2 pg", MassUnit.Picogram, 4.2)] + [InlineData("en-US", "4.2 lb", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 lbs", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 lbm", MassUnit.Pound, 4.2)] + [InlineData("en-US", "4.2 t (short)", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 short tn", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 ST", MassUnit.ShortTon, 4.2)] + [InlineData("en-US", "4.2 slug", MassUnit.Slug, 4.2)] + [InlineData("en-US", "4.2 M☉", MassUnit.SolarMass, 4.2)] + [InlineData("en-US", "4.2 M⊙", MassUnit.SolarMass, 4.2)] + [InlineData("en-US", "4.2 st", MassUnit.Stone, 4.2)] + [InlineData("en-US", "4.2 t", MassUnit.Tonne, 4.2)] + [InlineData("ru-RU", "4,2 сг", MassUnit.Centigram, 4.2)] + [InlineData("ru-RU", "4,2 даг", MassUnit.Decagram, 4.2)] + [InlineData("ru-RU", "4,2 дг", MassUnit.Decigram, 4.2)] + [InlineData("ru-RU", "4,2 фг", MassUnit.Femtogram, 4.2)] + [InlineData("ru-RU", "4,2 г", MassUnit.Gram, 4.2)] + [InlineData("ru-RU", "4,2 гг", MassUnit.Hectogram, 4.2)] + [InlineData("ru-RU", "4,2 кг", MassUnit.Kilogram, 4.2)] + [InlineData("ru-RU", "4,2 кфунт", MassUnit.Kilopound, 4.2)] + [InlineData("ru-RU", "4,2 кт", MassUnit.Kilotonne, 4.2)] + [InlineData("ru-RU", "4,2 тонна большая", MassUnit.LongTon, 4.2)] + [InlineData("ru-RU", "4,2 Мфунт", MassUnit.Megapound, 4.2)] + [InlineData("ru-RU", "4,2 Мт", MassUnit.Megatonne, 4.2)] + [InlineData("ru-RU", "4,2 мкг", MassUnit.Microgram, 4.2)] + [InlineData("ru-RU", "4,2 мг", MassUnit.Milligram, 4.2)] + [InlineData("ru-RU", "4,2 нг", MassUnit.Nanogram, 4.2)] + [InlineData("ru-RU", "4,2 пг", MassUnit.Picogram, 4.2)] + [InlineData("ru-RU", "4,2 фунт", MassUnit.Pound, 4.2)] + [InlineData("ru-RU", "4,2 тонна малая", MassUnit.ShortTon, 4.2)] + [InlineData("ru-RU", "4,2 т", MassUnit.Tonne, 4.2)] + [InlineData("zh-CN", "4.2 厘克", MassUnit.Centigram, 4.2)] + [InlineData("zh-CN", "4.2 十克", MassUnit.Decagram, 4.2)] + [InlineData("zh-CN", "4.2 分克", MassUnit.Decigram, 4.2)] + [InlineData("zh-CN", "4.2 飞克", MassUnit.Femtogram, 4.2)] + [InlineData("zh-CN", "4.2 克", MassUnit.Gram, 4.2)] + [InlineData("zh-CN", "4.2 百克", MassUnit.Hectogram, 4.2)] + [InlineData("zh-CN", "4.2 千克", MassUnit.Kilogram, 4.2)] + [InlineData("zh-CN", "4.2 千磅", MassUnit.Kilopound, 4.2)] + [InlineData("zh-CN", "4.2 千吨", MassUnit.Kilotonne, 4.2)] + [InlineData("zh-CN", "4.2 长吨", MassUnit.LongTon, 4.2)] + [InlineData("zh-CN", "4.2 兆磅", MassUnit.Megapound, 4.2)] + [InlineData("zh-CN", "4.2 兆吨", MassUnit.Megatonne, 4.2)] + [InlineData("zh-CN", "4.2 微克", MassUnit.Microgram, 4.2)] + [InlineData("zh-CN", "4.2 毫克", MassUnit.Milligram, 4.2)] + [InlineData("zh-CN", "4.2 纳克", MassUnit.Nanogram, 4.2)] + [InlineData("zh-CN", "4.2 盎司", MassUnit.Ounce, 4.2)] + [InlineData("zh-CN", "4.2 皮克", MassUnit.Picogram, 4.2)] + [InlineData("zh-CN", "4.2 磅", MassUnit.Pound, 4.2)] + [InlineData("zh-CN", "4.2 短吨", MassUnit.ShortTon, 4.2)] + [InlineData("zh-CN", "4.2 吨", MassUnit.Tonne, 4.2)] + public void TryParse(string culture, string quantityString, MassUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(Mass.TryParse(quantityString, out Mass parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("en-US", "1 cwt")] // [LongHundredweight, ShortHundredweight] + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.False(Mass.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] @@ -1895,6 +1112,92 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi Assert.False(Mass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } + [Theory] + [InlineData("en-US", MassUnit.Centigram, "cg")] + [InlineData("en-US", MassUnit.Decagram, "dag")] + [InlineData("en-US", MassUnit.Decigram, "dg")] + [InlineData("en-US", MassUnit.EarthMass, "em")] + [InlineData("en-US", MassUnit.Femtogram, "fg")] + [InlineData("en-US", MassUnit.Grain, "gr")] + [InlineData("en-US", MassUnit.Gram, "g")] + [InlineData("en-US", MassUnit.Hectogram, "hg")] + [InlineData("en-US", MassUnit.Kilogram, "kg")] + [InlineData("en-US", MassUnit.Kilopound, "klb")] + [InlineData("en-US", MassUnit.Kilotonne, "kt")] + [InlineData("en-US", MassUnit.LongHundredweight, "cwt")] + [InlineData("en-US", MassUnit.LongTon, "long tn")] + [InlineData("en-US", MassUnit.Megapound, "Mlb")] + [InlineData("en-US", MassUnit.Megatonne, "Mt")] + [InlineData("en-US", MassUnit.Microgram, "µg")] + [InlineData("en-US", MassUnit.Milligram, "mg")] + [InlineData("en-US", MassUnit.Nanogram, "ng")] + [InlineData("en-US", MassUnit.Ounce, "oz")] + [InlineData("en-US", MassUnit.Picogram, "pg")] + [InlineData("en-US", MassUnit.Pound, "lb")] + [InlineData("en-US", MassUnit.ShortHundredweight, "cwt")] + [InlineData("en-US", MassUnit.ShortTon, "t (short)")] + [InlineData("en-US", MassUnit.Slug, "slug")] + [InlineData("en-US", MassUnit.SolarMass, "M☉")] + [InlineData("en-US", MassUnit.Stone, "st")] + [InlineData("en-US", MassUnit.Tonne, "t")] + [InlineData("ru-RU", MassUnit.Centigram, "сг")] + [InlineData("ru-RU", MassUnit.Decagram, "даг")] + [InlineData("ru-RU", MassUnit.Decigram, "дг")] + [InlineData("ru-RU", MassUnit.Femtogram, "фг")] + [InlineData("ru-RU", MassUnit.Gram, "г")] + [InlineData("ru-RU", MassUnit.Hectogram, "гг")] + [InlineData("ru-RU", MassUnit.Kilogram, "кг")] + [InlineData("ru-RU", MassUnit.Kilopound, "кфунт")] + [InlineData("ru-RU", MassUnit.Kilotonne, "кт")] + [InlineData("ru-RU", MassUnit.LongTon, "тонна большая")] + [InlineData("ru-RU", MassUnit.Megapound, "Мфунт")] + [InlineData("ru-RU", MassUnit.Megatonne, "Мт")] + [InlineData("ru-RU", MassUnit.Microgram, "мкг")] + [InlineData("ru-RU", MassUnit.Milligram, "мг")] + [InlineData("ru-RU", MassUnit.Nanogram, "нг")] + [InlineData("ru-RU", MassUnit.Picogram, "пг")] + [InlineData("ru-RU", MassUnit.Pound, "фунт")] + [InlineData("ru-RU", MassUnit.ShortTon, "тонна малая")] + [InlineData("ru-RU", MassUnit.Tonne, "т")] + [InlineData("zh-CN", MassUnit.Centigram, "厘克")] + [InlineData("zh-CN", MassUnit.Decagram, "十克")] + [InlineData("zh-CN", MassUnit.Decigram, "分克")] + [InlineData("zh-CN", MassUnit.Femtogram, "飞克")] + [InlineData("zh-CN", MassUnit.Gram, "克")] + [InlineData("zh-CN", MassUnit.Hectogram, "百克")] + [InlineData("zh-CN", MassUnit.Kilogram, "千克")] + [InlineData("zh-CN", MassUnit.Kilopound, "千磅")] + [InlineData("zh-CN", MassUnit.Kilotonne, "千吨")] + [InlineData("zh-CN", MassUnit.LongTon, "长吨")] + [InlineData("zh-CN", MassUnit.Megapound, "兆磅")] + [InlineData("zh-CN", MassUnit.Megatonne, "兆吨")] + [InlineData("zh-CN", MassUnit.Microgram, "微克")] + [InlineData("zh-CN", MassUnit.Milligram, "毫克")] + [InlineData("zh-CN", MassUnit.Nanogram, "纳克")] + [InlineData("zh-CN", MassUnit.Ounce, "盎司")] + [InlineData("zh-CN", MassUnit.Picogram, "皮克")] + [InlineData("zh-CN", MassUnit.Pound, "磅")] + [InlineData("zh-CN", MassUnit.ShortTon, "短吨")] + [InlineData("zh-CN", MassUnit.Tonne, "吨")] + public void GetAbbreviationForCulture(string culture, MassUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Mass.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Mass.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Mass.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MassUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs index 0b9d548974..e989fb450b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 mmol/kg", MolalityUnit.MillimolePerKilogram, 4.2)] + [InlineData("en-US", "4.2 mol/g", MolalityUnit.MolePerGram, 4.2)] + [InlineData("en-US", "4.2 mol/kg", MolalityUnit.MolePerKilogram, 4.2)] + public void Parse(string culture, string quantityString, MolalityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Molality.Parse("1 mmol/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimolesPerKilogram, MillimolesPerKilogramTolerance); - Assert.Equal(MolalityUnit.MillimolePerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molality.Parse("1 mol/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MolesPerGram, MolesPerGramTolerance); - Assert.Equal(MolalityUnit.MolePerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molality.Parse("1 mol/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MolesPerKilogram, MolesPerKilogramTolerance); - Assert.Equal(MolalityUnit.MolePerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Molality.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 mmol/kg", MolalityUnit.MillimolePerKilogram, 4.2)] + [InlineData("en-US", "4.2 mol/g", MolalityUnit.MolePerGram, 4.2)] + [InlineData("en-US", "4.2 mol/kg", MolalityUnit.MolePerKilogram, 4.2)] + public void TryParse(string culture, string quantityString, MolalityUnit expectedUnit, double expectedValue) { - { - Assert.True(Molality.TryParse("1 mmol/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimolesPerKilogram, MillimolesPerKilogramTolerance); - Assert.Equal(MolalityUnit.MillimolePerKilogram, parsed.Unit); - } - - { - Assert.True(Molality.TryParse("1 mol/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MolesPerGram, MolesPerGramTolerance); - Assert.Equal(MolalityUnit.MolePerGram, parsed.Unit); - } - - { - Assert.True(Molality.TryParse("1 mol/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MolesPerKilogram, MolesPerKilogramTolerance); - Assert.Equal(MolalityUnit.MolePerKilogram, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Molality.TryParse(quantityString, out Molality parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Molali Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolalityUnit.MillimolePerKilogram, "mmol/kg")] + [InlineData("en-US", MolalityUnit.MolePerGram, "mol/g")] + [InlineData("en-US", MolalityUnit.MolePerKilogram, "mol/kg")] + public void GetAbbreviationForCulture(string culture, MolalityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Molality.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Molality.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Molality.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolalityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 20a3a9fee2..f1f0775307 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 J/mol", MolarEnergyUnit.JoulePerMole, 4.2)] + [InlineData("en-US", "4.2 kJ/mol", MolarEnergyUnit.KilojoulePerMole, 4.2)] + [InlineData("en-US", "4.2 MJ/mol", MolarEnergyUnit.MegajoulePerMole, 4.2)] + public void Parse(string culture, string quantityString, MolarEnergyUnit expectedUnit, double expectedValue) { - try - { - var parsed = MolarEnergy.Parse("1 J/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerMole, JoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.JoulePerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarEnergy.Parse("1 kJ/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerMole, KilojoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.KilojoulePerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarEnergy.Parse("1 MJ/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerMole, MegajoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.MegajoulePerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MolarEnergy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 J/mol", MolarEnergyUnit.JoulePerMole, 4.2)] + [InlineData("en-US", "4.2 kJ/mol", MolarEnergyUnit.KilojoulePerMole, 4.2)] + [InlineData("en-US", "4.2 MJ/mol", MolarEnergyUnit.MegajoulePerMole, 4.2)] + public void TryParse(string culture, string quantityString, MolarEnergyUnit expectedUnit, double expectedValue) { - { - Assert.True(MolarEnergy.TryParse("1 J/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerMole, JoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.JoulePerMole, parsed.Unit); - } - - { - Assert.True(MolarEnergy.TryParse("1 kJ/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerMole, KilojoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.KilojoulePerMole, parsed.Unit); - } - - { - Assert.True(MolarEnergy.TryParse("1 MJ/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerMole, MegajoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.MegajoulePerMole, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MolarEnergy.TryParse(quantityString, out MolarEnergy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarE Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolarEnergyUnit.JoulePerMole, "J/mol")] + [InlineData("en-US", MolarEnergyUnit.KilojoulePerMole, "kJ/mol")] + [InlineData("en-US", MolarEnergyUnit.MegajoulePerMole, "MJ/mol")] + public void GetAbbreviationForCulture(string culture, MolarEnergyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MolarEnergy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MolarEnergy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MolarEnergy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolarEnergyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 8b95b1e4f7..c3513b1b63 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 J/(mol·K)", MolarEntropyUnit.JoulePerMoleKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/(mol·K)", MolarEntropyUnit.KilojoulePerMoleKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/(mol·K)", MolarEntropyUnit.MegajoulePerMoleKelvin, 4.2)] + public void Parse(string culture, string quantityString, MolarEntropyUnit expectedUnit, double expectedValue) { - try - { - var parsed = MolarEntropy.Parse("1 J/(mol·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.JoulePerMoleKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarEntropy.Parse("1 kJ/(mol·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerMoleKelvin, KilojoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.KilojoulePerMoleKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarEntropy.Parse("1 MJ/(mol·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerMoleKelvin, MegajoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MolarEntropy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 J/(mol·K)", MolarEntropyUnit.JoulePerMoleKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/(mol·K)", MolarEntropyUnit.KilojoulePerMoleKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/(mol·K)", MolarEntropyUnit.MegajoulePerMoleKelvin, 4.2)] + public void TryParse(string culture, string quantityString, MolarEntropyUnit expectedUnit, double expectedValue) { - { - Assert.True(MolarEntropy.TryParse("1 J/(mol·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.JoulePerMoleKelvin, parsed.Unit); - } - - { - Assert.True(MolarEntropy.TryParse("1 kJ/(mol·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerMoleKelvin, KilojoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.KilojoulePerMoleKelvin, parsed.Unit); - } - - { - Assert.True(MolarEntropy.TryParse("1 MJ/(mol·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerMoleKelvin, MegajoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MolarEntropy.TryParse(quantityString, out MolarEntropy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarE Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolarEntropyUnit.JoulePerMoleKelvin, "J/(mol·K)")] + [InlineData("en-US", MolarEntropyUnit.KilojoulePerMoleKelvin, "kJ/(mol·K)")] + [InlineData("en-US", MolarEntropyUnit.MegajoulePerMoleKelvin, "MJ/(mol·K)")] + public void GetAbbreviationForCulture(string culture, MolarEntropyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MolarEntropy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MolarEntropy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MolarEntropy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolarEntropyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index 2567141034..851774cb04 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kkmol/h", MolarFlowUnit.KilomolePerHour, 4.2)] + [InlineData("en-US", "4.2 kmol/min", MolarFlowUnit.KilomolePerMinute, 4.2)] + [InlineData("en-US", "4.2 kmol/s", MolarFlowUnit.KilomolePerSecond, 4.2)] + [InlineData("en-US", "4.2 kmol/h", MolarFlowUnit.MolePerHour, 4.2)] + [InlineData("en-US", "4.2 mol/min", MolarFlowUnit.MolePerMinute, 4.2)] + [InlineData("en-US", "4.2 mol/s", MolarFlowUnit.MolePerSecond, 4.2)] + [InlineData("en-US", "4.2 lbmol/h", MolarFlowUnit.PoundMolePerHour, 4.2)] + [InlineData("en-US", "4.2 lbmol/min", MolarFlowUnit.PoundMolePerMinute, 4.2)] + [InlineData("en-US", "4.2 lbmol/s", MolarFlowUnit.PoundMolePerSecond, 4.2)] + public void Parse(string culture, string quantityString, MolarFlowUnit expectedUnit, double expectedValue) { - try - { - 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 */ } - - 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 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.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.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.PoundMolesPerSecond, PoundMolesPerSecondTolerance); - Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MolarFlow.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kkmol/h", MolarFlowUnit.KilomolePerHour, 4.2)] + [InlineData("en-US", "4.2 kmol/min", MolarFlowUnit.KilomolePerMinute, 4.2)] + [InlineData("en-US", "4.2 kmol/s", MolarFlowUnit.KilomolePerSecond, 4.2)] + [InlineData("en-US", "4.2 kmol/h", MolarFlowUnit.MolePerHour, 4.2)] + [InlineData("en-US", "4.2 mol/min", MolarFlowUnit.MolePerMinute, 4.2)] + [InlineData("en-US", "4.2 mol/s", MolarFlowUnit.MolePerSecond, 4.2)] + [InlineData("en-US", "4.2 lbmol/h", MolarFlowUnit.PoundMolePerHour, 4.2)] + [InlineData("en-US", "4.2 lbmol/min", MolarFlowUnit.PoundMolePerMinute, 4.2)] + [InlineData("en-US", "4.2 lbmol/s", MolarFlowUnit.PoundMolePerSecond, 4.2)] + public void TryParse(string culture, string quantityString, MolarFlowUnit expectedUnit, double expectedValue) { - { - 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); - } - - { - 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 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.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.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.PoundMolesPerSecond, PoundMolesPerSecondTolerance); - Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MolarFlow.TryParse(quantityString, out MolarFlow parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarF Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolarFlowUnit.KilomolePerHour, "kkmol/h")] + [InlineData("en-US", MolarFlowUnit.KilomolePerMinute, "kmol/min")] + [InlineData("en-US", MolarFlowUnit.KilomolePerSecond, "kmol/s")] + [InlineData("en-US", MolarFlowUnit.MolePerHour, "kmol/h")] + [InlineData("en-US", MolarFlowUnit.MolePerMinute, "mol/min")] + [InlineData("en-US", MolarFlowUnit.MolePerSecond, "mol/s")] + [InlineData("en-US", MolarFlowUnit.PoundMolePerHour, "lbmol/h")] + [InlineData("en-US", MolarFlowUnit.PoundMolePerMinute, "lbmol/min")] + [InlineData("en-US", MolarFlowUnit.PoundMolePerSecond, "lbmol/s")] + public void GetAbbreviationForCulture(string culture, MolarFlowUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MolarFlow.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MolarFlow.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MolarFlow.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolarFlowUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 3e5610caf6..21de2772a4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -342,339 +342,72 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cg/mol", MolarMassUnit.CentigramPerMole, 4.2)] + [InlineData("en-US", "4.2 dag/mol", MolarMassUnit.DecagramPerMole, 4.2)] + [InlineData("en-US", "4.2 dg/mol", MolarMassUnit.DecigramPerMole, 4.2)] + [InlineData("en-US", "4.2 g/mol", MolarMassUnit.GramPerMole, 4.2)] + [InlineData("en-US", "4.2 hg/mol", MolarMassUnit.HectogramPerMole, 4.2)] + [InlineData("en-US", "4.2 kg/kmol", MolarMassUnit.KilogramPerKilomole, 4.2)] + [InlineData("en-US", "4.2 kg/mol", MolarMassUnit.KilogramPerMole, 4.2)] + [InlineData("en-US", "4.2 klb/mol", MolarMassUnit.KilopoundPerMole, 4.2)] + [InlineData("en-US", "4.2 Mlb/mol", MolarMassUnit.MegapoundPerMole, 4.2)] + [InlineData("en-US", "4.2 µg/mol", MolarMassUnit.MicrogramPerMole, 4.2)] + [InlineData("en-US", "4.2 mg/mol", MolarMassUnit.MilligramPerMole, 4.2)] + [InlineData("en-US", "4.2 ng/mol", MolarMassUnit.NanogramPerMole, 4.2)] + [InlineData("en-US", "4.2 lb/mol", MolarMassUnit.PoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 сг/моль", MolarMassUnit.CentigramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 даг/моль", MolarMassUnit.DecagramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 дг/моль", MolarMassUnit.DecigramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 г/моль", MolarMassUnit.GramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 гг/моль", MolarMassUnit.HectogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 кг/моль", MolarMassUnit.KilogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 кфунт/моль", MolarMassUnit.KilopoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 Мфунт/моль", MolarMassUnit.MegapoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 мкг/моль", MolarMassUnit.MicrogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 мг/моль", MolarMassUnit.MilligramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 нг/моль", MolarMassUnit.NanogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 фунт/моль", MolarMassUnit.PoundPerMole, 4.2)] + public void Parse(string culture, string quantityString, MolarMassUnit expectedUnit, double expectedValue) { - try - { - var parsed = MolarMass.Parse("1 cg/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMole, CentigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 сг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMole, CentigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 dag/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerMole, DecagramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 даг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecagramsPerMole, DecagramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 dg/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMole, DecigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 дг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMole, DecigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 g/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerMole, GramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.GramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 г/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.GramsPerMole, GramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.GramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 hg/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerMole, HectogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 гг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectogramsPerMole, HectogramsPerMoleTolerance); - 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")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMole, KilogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 кг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMole, KilogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 klb/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerMole, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 кфунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerMole, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 Mlb/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMole, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 Мфунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMole, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 µg/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMole, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 мкг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMole, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 mg/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMole, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 мг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMole, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 ng/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMole, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 нг/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMole, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 lb/mol", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerMole, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = MolarMass.Parse("1 фунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsPerMole, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = MolarMass.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cg/mol", MolarMassUnit.CentigramPerMole, 4.2)] + [InlineData("en-US", "4.2 dag/mol", MolarMassUnit.DecagramPerMole, 4.2)] + [InlineData("en-US", "4.2 dg/mol", MolarMassUnit.DecigramPerMole, 4.2)] + [InlineData("en-US", "4.2 g/mol", MolarMassUnit.GramPerMole, 4.2)] + [InlineData("en-US", "4.2 hg/mol", MolarMassUnit.HectogramPerMole, 4.2)] + [InlineData("en-US", "4.2 kg/kmol", MolarMassUnit.KilogramPerKilomole, 4.2)] + [InlineData("en-US", "4.2 kg/mol", MolarMassUnit.KilogramPerMole, 4.2)] + [InlineData("en-US", "4.2 klb/mol", MolarMassUnit.KilopoundPerMole, 4.2)] + [InlineData("en-US", "4.2 Mlb/mol", MolarMassUnit.MegapoundPerMole, 4.2)] + [InlineData("en-US", "4.2 µg/mol", MolarMassUnit.MicrogramPerMole, 4.2)] + [InlineData("en-US", "4.2 mg/mol", MolarMassUnit.MilligramPerMole, 4.2)] + [InlineData("en-US", "4.2 ng/mol", MolarMassUnit.NanogramPerMole, 4.2)] + [InlineData("en-US", "4.2 lb/mol", MolarMassUnit.PoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 сг/моль", MolarMassUnit.CentigramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 даг/моль", MolarMassUnit.DecagramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 дг/моль", MolarMassUnit.DecigramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 г/моль", MolarMassUnit.GramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 гг/моль", MolarMassUnit.HectogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 кг/моль", MolarMassUnit.KilogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 кфунт/моль", MolarMassUnit.KilopoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 Мфунт/моль", MolarMassUnit.MegapoundPerMole, 4.2)] + [InlineData("ru-RU", "4,2 мкг/моль", MolarMassUnit.MicrogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 мг/моль", MolarMassUnit.MilligramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 нг/моль", MolarMassUnit.NanogramPerMole, 4.2)] + [InlineData("ru-RU", "4,2 фунт/моль", MolarMassUnit.PoundPerMole, 4.2)] + public void TryParse(string culture, string quantityString, MolarMassUnit expectedUnit, double expectedValue) { - { - Assert.True(MolarMass.TryParse("1 cg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMole, CentigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 сг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentigramsPerMole, CentigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 dag/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerMole, DecagramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 даг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecagramsPerMole, DecagramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 dg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMole, DecigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 дг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecigramsPerMole, DecigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 g/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMole, GramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.GramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 г/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerMole, GramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.GramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 hg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerMole, HectogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 гг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectogramsPerMole, HectogramsPerMoleTolerance); - 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); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 кг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerMole, KilogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 klb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerMole, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 кфунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsPerMole, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 Mlb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMole, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 Мфунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsPerMole, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 µg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMole, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 мкг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrogramsPerMole, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 mg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMole, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 мг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilligramsPerMole, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 ng/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMole, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 нг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanogramsPerMole, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 lb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerMole, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, parsed.Unit); - } - - { - Assert.True(MolarMass.TryParse("1 фунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerMole, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(MolarMass.TryParse(quantityString, out MolarMass parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -895,6 +628,51 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarM Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolarMassUnit.CentigramPerMole, "cg/mol")] + [InlineData("en-US", MolarMassUnit.DecagramPerMole, "dag/mol")] + [InlineData("en-US", MolarMassUnit.DecigramPerMole, "dg/mol")] + [InlineData("en-US", MolarMassUnit.GramPerMole, "g/mol")] + [InlineData("en-US", MolarMassUnit.HectogramPerMole, "hg/mol")] + [InlineData("en-US", MolarMassUnit.KilogramPerKilomole, "kg/kmol")] + [InlineData("en-US", MolarMassUnit.KilogramPerMole, "kg/mol")] + [InlineData("en-US", MolarMassUnit.KilopoundPerMole, "klb/mol")] + [InlineData("en-US", MolarMassUnit.MegapoundPerMole, "Mlb/mol")] + [InlineData("en-US", MolarMassUnit.MicrogramPerMole, "µg/mol")] + [InlineData("en-US", MolarMassUnit.MilligramPerMole, "mg/mol")] + [InlineData("en-US", MolarMassUnit.NanogramPerMole, "ng/mol")] + [InlineData("en-US", MolarMassUnit.PoundPerMole, "lb/mol")] + [InlineData("ru-RU", MolarMassUnit.CentigramPerMole, "сг/моль")] + [InlineData("ru-RU", MolarMassUnit.DecagramPerMole, "даг/моль")] + [InlineData("ru-RU", MolarMassUnit.DecigramPerMole, "дг/моль")] + [InlineData("ru-RU", MolarMassUnit.GramPerMole, "г/моль")] + [InlineData("ru-RU", MolarMassUnit.HectogramPerMole, "гг/моль")] + [InlineData("ru-RU", MolarMassUnit.KilogramPerMole, "кг/моль")] + [InlineData("ru-RU", MolarMassUnit.KilopoundPerMole, "кфунт/моль")] + [InlineData("ru-RU", MolarMassUnit.MegapoundPerMole, "Мфунт/моль")] + [InlineData("ru-RU", MolarMassUnit.MicrogramPerMole, "мкг/моль")] + [InlineData("ru-RU", MolarMassUnit.MilligramPerMole, "мг/моль")] + [InlineData("ru-RU", MolarMassUnit.NanogramPerMole, "нг/моль")] + [InlineData("ru-RU", MolarMassUnit.PoundPerMole, "фунт/моль")] + public void GetAbbreviationForCulture(string culture, MolarMassUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = MolarMass.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(MolarMass.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = MolarMass.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolarMassUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index 0202de1125..d1f7897d05 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -330,261 +330,60 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cmol/l", MolarityUnit.CentimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 cM", MolarityUnit.CentimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 dmol/l", MolarityUnit.DecimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 dM", MolarityUnit.DecimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 fmol/l", MolarityUnit.FemtomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 fM", MolarityUnit.FemtomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 kmol/m³", MolarityUnit.KilomolePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µmol/l", MolarityUnit.MicromolePerLiter, 4.2)] + [InlineData("en-US", "4.2 µM", MolarityUnit.MicromolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mmol/l", MolarityUnit.MillimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mM", MolarityUnit.MillimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mol/m³", MolarityUnit.MolePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mol/l", MolarityUnit.MolePerLiter, 4.2)] + [InlineData("en-US", "4.2 M", MolarityUnit.MolePerLiter, 4.2)] + [InlineData("en-US", "4.2 nmol/l", MolarityUnit.NanomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 nM", MolarityUnit.NanomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 pmol/l", MolarityUnit.PicomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 pM", MolarityUnit.PicomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot, 4.2)] + public void Parse(string culture, string quantityString, MolarityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Molarity.Parse("1 cmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimolesPerLiter, CentimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 cM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimolesPerLiter, CentimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 dmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimolesPerLiter, DecimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 dM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimolesPerLiter, DecimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 fmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtomolesPerLiter, FemtomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 fM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtomolesPerLiter, FemtomolesPerLiterTolerance); - 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")); - AssertEx.EqualTolerance(1, parsed.MicromolesPerLiter, MicromolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 µM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicromolesPerLiter, MicromolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 mmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimolesPerLiter, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 mM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimolesPerLiter, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 mol/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - Assert.Equal(MolarityUnit.MolePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 mol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MolesPerLiter, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 M", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MolesPerLiter, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 nmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanomolesPerLiter, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 nM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanomolesPerLiter, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 pmol/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicomolesPerLiter, PicomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Molarity.Parse("1 pM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicomolesPerLiter, PicomolesPerLiterTolerance); - 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 */ } - + using var _ = new CultureScope(culture); + var parsed = Molarity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cmol/l", MolarityUnit.CentimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 cM", MolarityUnit.CentimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 dmol/l", MolarityUnit.DecimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 dM", MolarityUnit.DecimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 fmol/l", MolarityUnit.FemtomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 fM", MolarityUnit.FemtomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 kmol/m³", MolarityUnit.KilomolePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µmol/l", MolarityUnit.MicromolePerLiter, 4.2)] + [InlineData("en-US", "4.2 µM", MolarityUnit.MicromolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mmol/l", MolarityUnit.MillimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mM", MolarityUnit.MillimolePerLiter, 4.2)] + [InlineData("en-US", "4.2 mol/m³", MolarityUnit.MolePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mol/l", MolarityUnit.MolePerLiter, 4.2)] + [InlineData("en-US", "4.2 M", MolarityUnit.MolePerLiter, 4.2)] + [InlineData("en-US", "4.2 nmol/l", MolarityUnit.NanomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 nM", MolarityUnit.NanomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 pmol/l", MolarityUnit.PicomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 pM", MolarityUnit.PicomolePerLiter, 4.2)] + [InlineData("en-US", "4.2 lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot, 4.2)] + public void TryParse(string culture, string quantityString, MolarityUnit expectedUnit, double expectedValue) { - { - Assert.True(Molarity.TryParse("1 cmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimolesPerLiter, CentimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 cM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimolesPerLiter, CentimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 dmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimolesPerLiter, DecimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 dM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimolesPerLiter, DecimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 fmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtomolesPerLiter, FemtomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 fM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtomolesPerLiter, FemtomolesPerLiterTolerance); - 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); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 µM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicromolesPerLiter, MicromolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 mmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimolesPerLiter, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 mM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimolesPerLiter, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 mol/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - Assert.Equal(MolarityUnit.MolePerCubicMeter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 mol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MolesPerLiter, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 M", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MolesPerLiter, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 nmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanomolesPerLiter, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 nM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanomolesPerLiter, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 pmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicomolesPerLiter, PicomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsed.Unit); - } - - { - Assert.True(Molarity.TryParse("1 pM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicomolesPerLiter, PicomolesPerLiterTolerance); - 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); - } - + using var _ = new CultureScope(culture); + Assert.True(Molarity.TryParse(quantityString, out Molarity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -805,6 +604,37 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Molari Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", MolarityUnit.CentimolePerLiter, "cmol/l")] + [InlineData("en-US", MolarityUnit.DecimolePerLiter, "dmol/l")] + [InlineData("en-US", MolarityUnit.FemtomolePerLiter, "fmol/l")] + [InlineData("en-US", MolarityUnit.KilomolePerCubicMeter, "kmol/m³")] + [InlineData("en-US", MolarityUnit.MicromolePerLiter, "µmol/l")] + [InlineData("en-US", MolarityUnit.MillimolePerLiter, "mmol/l")] + [InlineData("en-US", MolarityUnit.MolePerCubicMeter, "mol/m³")] + [InlineData("en-US", MolarityUnit.MolePerLiter, "mol/l")] + [InlineData("en-US", MolarityUnit.NanomolePerLiter, "nmol/l")] + [InlineData("en-US", MolarityUnit.PicomolePerLiter, "pmol/l")] + [InlineData("en-US", MolarityUnit.PoundMolePerCubicFoot, "lbmol/ft³")] + public void GetAbbreviationForCulture(string culture, MolarityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Molarity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Molarity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Molarity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(MolarityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index 6d3373fb9d..6a66077485 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 H/m", PermeabilityUnit.HenryPerMeter, 4.2)] + public void Parse(string culture, string quantityString, PermeabilityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Permeability.Parse("1 H/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HenriesPerMeter, HenriesPerMeterTolerance); - Assert.Equal(PermeabilityUnit.HenryPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Permeability.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 H/m", PermeabilityUnit.HenryPerMeter, 4.2)] + public void TryParse(string culture, string quantityString, PermeabilityUnit expectedUnit, double expectedValue) { - { - Assert.True(Permeability.TryParse("1 H/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HenriesPerMeter, HenriesPerMeterTolerance); - Assert.Equal(PermeabilityUnit.HenryPerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Permeability.TryParse(quantityString, out Permeability parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Permea Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PermeabilityUnit.HenryPerMeter, "H/m")] + public void GetAbbreviationForCulture(string culture, PermeabilityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Permeability.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Permeability.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Permeability.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PermeabilityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index e2553d7a78..89daa8a963 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -270,27 +270,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 F/m", PermittivityUnit.FaradPerMeter, 4.2)] + public void Parse(string culture, string quantityString, PermittivityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Permittivity.Parse("1 F/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FaradsPerMeter, FaradsPerMeterTolerance); - Assert.Equal(PermittivityUnit.FaradPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Permittivity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 F/m", PermittivityUnit.FaradPerMeter, 4.2)] + public void TryParse(string culture, string quantityString, PermittivityUnit expectedUnit, double expectedValue) { - { - Assert.True(Permittivity.TryParse("1 F/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FaradsPerMeter, FaradsPerMeterTolerance); - Assert.Equal(PermittivityUnit.FaradPerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Permittivity.TryParse(quantityString, out Permittivity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -367,6 +364,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Permit Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PermittivityUnit.FaradPerMeter, "F/m")] + public void GetAbbreviationForCulture(string culture, PermittivityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Permittivity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Permittivity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Permittivity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PermittivityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index dcc0572cb2..ca7a44064b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -294,79 +294,32 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 D", PorousMediumPermeabilityUnit.Darcy, 4.2)] + [InlineData("en-US", "4.2 µD", PorousMediumPermeabilityUnit.Microdarcy, 4.2)] + [InlineData("en-US", "4.2 mD", PorousMediumPermeabilityUnit.Millidarcy, 4.2)] + [InlineData("en-US", "4.2 cm²", PorousMediumPermeabilityUnit.SquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 m²", PorousMediumPermeabilityUnit.SquareMeter, 4.2)] + public void Parse(string culture, string quantityString, PorousMediumPermeabilityUnit expectedUnit, double expectedValue) { - try - { - var parsed = PorousMediumPermeability.Parse("1 D", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Darcys, DarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Darcy, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PorousMediumPermeability.Parse("1 µD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microdarcys, MicrodarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Microdarcy, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PorousMediumPermeability.Parse("1 mD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millidarcys, MillidarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Millidarcy, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PorousMediumPermeability.Parse("1 cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.SquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PorousMediumPermeability.Parse("1 m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.SquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = PorousMediumPermeability.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 D", PorousMediumPermeabilityUnit.Darcy, 4.2)] + [InlineData("en-US", "4.2 µD", PorousMediumPermeabilityUnit.Microdarcy, 4.2)] + [InlineData("en-US", "4.2 mD", PorousMediumPermeabilityUnit.Millidarcy, 4.2)] + [InlineData("en-US", "4.2 cm²", PorousMediumPermeabilityUnit.SquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 m²", PorousMediumPermeabilityUnit.SquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, PorousMediumPermeabilityUnit expectedUnit, double expectedValue) { - { - Assert.True(PorousMediumPermeability.TryParse("1 D", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Darcys, DarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Darcy, parsed.Unit); - } - - { - Assert.True(PorousMediumPermeability.TryParse("1 µD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microdarcys, MicrodarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Microdarcy, parsed.Unit); - } - - { - Assert.True(PorousMediumPermeability.TryParse("1 mD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millidarcys, MillidarcysTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.Millidarcy, parsed.Unit); - } - - { - Assert.True(PorousMediumPermeability.TryParse("1 cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeters, SquareCentimetersTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.SquareCentimeter, parsed.Unit); - } - - { - Assert.True(PorousMediumPermeability.TryParse("1 m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeters, SquareMetersTolerance); - Assert.Equal(PorousMediumPermeabilityUnit.SquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(PorousMediumPermeability.TryParse(quantityString, out PorousMediumPermeability parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -475,6 +428,31 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Porous Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PorousMediumPermeabilityUnit.Darcy, "D")] + [InlineData("en-US", PorousMediumPermeabilityUnit.Microdarcy, "µD")] + [InlineData("en-US", PorousMediumPermeabilityUnit.Millidarcy, "mD")] + [InlineData("en-US", PorousMediumPermeabilityUnit.SquareCentimeter, "cm²")] + [InlineData("en-US", PorousMediumPermeabilityUnit.SquareMeter, "m²")] + public void GetAbbreviationForCulture(string culture, PorousMediumPermeabilityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = PorousMediumPermeability.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(PorousMediumPermeability.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = PorousMediumPermeability.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PorousMediumPermeabilityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index 843b5eae13..9b80bfd613 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -528,538 +528,110 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 daW/ft³", PowerDensityUnit.DecawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 daW/in³", PowerDensityUnit.DecawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 daW/m³", PowerDensityUnit.DecawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 daW/l", PowerDensityUnit.DecawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 dW/in³", PowerDensityUnit.DeciwattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 dW/m³", PowerDensityUnit.DeciwattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 dW/l", PowerDensityUnit.DeciwattPerLiter, 4.2)] + [InlineData("en-US", "4.2 GW/ft³", PowerDensityUnit.GigawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 GW/in³", PowerDensityUnit.GigawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 GW/m³", PowerDensityUnit.GigawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 GW/l", PowerDensityUnit.GigawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 kW/ft³", PowerDensityUnit.KilowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kW/in³", PowerDensityUnit.KilowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 kW/m³", PowerDensityUnit.KilowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kW/l", PowerDensityUnit.KilowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 MW/ft³", PowerDensityUnit.MegawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 MW/in³", PowerDensityUnit.MegawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 MW/m³", PowerDensityUnit.MegawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MW/l", PowerDensityUnit.MegawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 µW/in³", PowerDensityUnit.MicrowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 µW/m³", PowerDensityUnit.MicrowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µW/l", PowerDensityUnit.MicrowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 mW/in³", PowerDensityUnit.MilliwattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 mW/m³", PowerDensityUnit.MilliwattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mW/l", PowerDensityUnit.MilliwattPerLiter, 4.2)] + [InlineData("en-US", "4.2 nW/ft³", PowerDensityUnit.NanowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 nW/in³", PowerDensityUnit.NanowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 nW/m³", PowerDensityUnit.NanowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 nW/l", PowerDensityUnit.NanowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 pW/ft³", PowerDensityUnit.PicowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 pW/in³", PowerDensityUnit.PicowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 pW/m³", PowerDensityUnit.PicowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 pW/l", PowerDensityUnit.PicowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 TW/ft³", PowerDensityUnit.TerawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 TW/in³", PowerDensityUnit.TerawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 TW/m³", PowerDensityUnit.TerawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TW/l", PowerDensityUnit.TerawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 W/ft³", PowerDensityUnit.WattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 W/in³", PowerDensityUnit.WattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 W/m³", PowerDensityUnit.WattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 W/l", PowerDensityUnit.WattPerLiter, 4.2)] + public void Parse(string culture, string quantityString, PowerDensityUnit expectedUnit, double expectedValue) { - try - { - var parsed = PowerDensity.Parse("1 daW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicFoot, DecawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 daW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicInch, DecawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 daW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicMeter, DecawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 daW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecawattsPerLiter, DecawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 dW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicFoot, DeciwattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 dW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicInch, DeciwattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 dW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicMeter, DeciwattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 dW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerLiter, DeciwattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 GW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicFoot, GigawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 GW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicInch, GigawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 GW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicMeter, GigawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 GW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattsPerLiter, GigawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 kW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicFoot, KilowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 kW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicInch, KilowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 kW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicMeter, KilowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 kW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattsPerLiter, KilowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 MW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerCubicFoot, MegawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 MW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerCubicInch, MegawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 MW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerCubicMeter, MegawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 MW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattsPerLiter, MegawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 µW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicFoot, MicrowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 µW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicInch, MicrowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 µW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicMeter, MicrowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 µW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerLiter, MicrowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 mW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerCubicFoot, MilliwattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 mW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerCubicInch, MilliwattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 mW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerCubicMeter, MilliwattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 mW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattsPerLiter, MilliwattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 nW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicFoot, NanowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 nW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicInch, NanowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 nW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicMeter, NanowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 nW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattsPerLiter, NanowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 pW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicFoot, PicowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 pW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicInch, PicowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 pW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicMeter, PicowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 pW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattsPerLiter, PicowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 TW/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicFoot, TerawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 TW/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicInch, TerawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 TW/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicMeter, TerawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 TW/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattsPerLiter, TerawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 W/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicFoot, WattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 W/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicInch, WattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 W/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicMeter, WattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerDensity.Parse("1 W/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerLiter, WattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.WattPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = PowerDensity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 daW/ft³", PowerDensityUnit.DecawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 daW/in³", PowerDensityUnit.DecawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 daW/m³", PowerDensityUnit.DecawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 daW/l", PowerDensityUnit.DecawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 dW/in³", PowerDensityUnit.DeciwattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 dW/m³", PowerDensityUnit.DeciwattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 dW/l", PowerDensityUnit.DeciwattPerLiter, 4.2)] + [InlineData("en-US", "4.2 GW/ft³", PowerDensityUnit.GigawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 GW/in³", PowerDensityUnit.GigawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 GW/m³", PowerDensityUnit.GigawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 GW/l", PowerDensityUnit.GigawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 kW/ft³", PowerDensityUnit.KilowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kW/in³", PowerDensityUnit.KilowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 kW/m³", PowerDensityUnit.KilowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kW/l", PowerDensityUnit.KilowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 MW/ft³", PowerDensityUnit.MegawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 MW/in³", PowerDensityUnit.MegawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 MW/m³", PowerDensityUnit.MegawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 MW/l", PowerDensityUnit.MegawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 µW/in³", PowerDensityUnit.MicrowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 µW/m³", PowerDensityUnit.MicrowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 µW/l", PowerDensityUnit.MicrowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 mW/in³", PowerDensityUnit.MilliwattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 mW/m³", PowerDensityUnit.MilliwattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 mW/l", PowerDensityUnit.MilliwattPerLiter, 4.2)] + [InlineData("en-US", "4.2 nW/ft³", PowerDensityUnit.NanowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 nW/in³", PowerDensityUnit.NanowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 nW/m³", PowerDensityUnit.NanowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 nW/l", PowerDensityUnit.NanowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 pW/ft³", PowerDensityUnit.PicowattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 pW/in³", PowerDensityUnit.PicowattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 pW/m³", PowerDensityUnit.PicowattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 pW/l", PowerDensityUnit.PicowattPerLiter, 4.2)] + [InlineData("en-US", "4.2 TW/ft³", PowerDensityUnit.TerawattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 TW/in³", PowerDensityUnit.TerawattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 TW/m³", PowerDensityUnit.TerawattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 TW/l", PowerDensityUnit.TerawattPerLiter, 4.2)] + [InlineData("en-US", "4.2 W/ft³", PowerDensityUnit.WattPerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 W/in³", PowerDensityUnit.WattPerCubicInch, 4.2)] + [InlineData("en-US", "4.2 W/m³", PowerDensityUnit.WattPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 W/l", PowerDensityUnit.WattPerLiter, 4.2)] + public void TryParse(string culture, string quantityString, PowerDensityUnit expectedUnit, double expectedValue) { - { - Assert.True(PowerDensity.TryParse("1 daW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicFoot, DecawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 daW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicInch, DecawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 daW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecawattsPerCubicMeter, DecawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 daW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecawattsPerLiter, DecawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 dW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicFoot, DeciwattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 dW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicInch, DeciwattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 dW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerCubicMeter, DeciwattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 dW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciwattsPerLiter, DeciwattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 GW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicFoot, GigawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 GW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicInch, GigawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 GW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerCubicMeter, GigawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 GW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattsPerLiter, GigawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 kW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicFoot, KilowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 kW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicInch, KilowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 kW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerCubicMeter, KilowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 kW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattsPerLiter, KilowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 µW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicFoot, MicrowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 µW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicInch, MicrowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 µW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerCubicMeter, MicrowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 µW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattsPerLiter, MicrowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 nW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicFoot, NanowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 nW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicInch, NanowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 nW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerCubicMeter, NanowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 nW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattsPerLiter, NanowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 pW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicFoot, PicowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 pW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicInch, PicowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 pW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerCubicMeter, PicowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 pW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattsPerLiter, PicowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 TW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicFoot, TerawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 TW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicInch, TerawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 TW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattsPerCubicMeter, TerawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 TW/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattsPerLiter, TerawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerLiter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 W/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicFoot, WattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicFoot, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 W/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicInch, WattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicInch, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 W/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerCubicMeter, WattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicMeter, parsed.Unit); - } - - { - Assert.True(PowerDensity.TryParse("1 W/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerLiter, WattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.WattPerLiter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(PowerDensity.TryParse(quantityString, out PowerDensity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1480,6 +1052,70 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerD Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PowerDensityUnit.DecawattPerCubicFoot, "daW/ft³")] + [InlineData("en-US", PowerDensityUnit.DecawattPerCubicInch, "daW/in³")] + [InlineData("en-US", PowerDensityUnit.DecawattPerCubicMeter, "daW/m³")] + [InlineData("en-US", PowerDensityUnit.DecawattPerLiter, "daW/l")] + [InlineData("en-US", PowerDensityUnit.DeciwattPerCubicFoot, "dW/ft³")] + [InlineData("en-US", PowerDensityUnit.DeciwattPerCubicInch, "dW/in³")] + [InlineData("en-US", PowerDensityUnit.DeciwattPerCubicMeter, "dW/m³")] + [InlineData("en-US", PowerDensityUnit.DeciwattPerLiter, "dW/l")] + [InlineData("en-US", PowerDensityUnit.GigawattPerCubicFoot, "GW/ft³")] + [InlineData("en-US", PowerDensityUnit.GigawattPerCubicInch, "GW/in³")] + [InlineData("en-US", PowerDensityUnit.GigawattPerCubicMeter, "GW/m³")] + [InlineData("en-US", PowerDensityUnit.GigawattPerLiter, "GW/l")] + [InlineData("en-US", PowerDensityUnit.KilowattPerCubicFoot, "kW/ft³")] + [InlineData("en-US", PowerDensityUnit.KilowattPerCubicInch, "kW/in³")] + [InlineData("en-US", PowerDensityUnit.KilowattPerCubicMeter, "kW/m³")] + [InlineData("en-US", PowerDensityUnit.KilowattPerLiter, "kW/l")] + [InlineData("en-US", PowerDensityUnit.MegawattPerCubicFoot, "MW/ft³")] + [InlineData("en-US", PowerDensityUnit.MegawattPerCubicInch, "MW/in³")] + [InlineData("en-US", PowerDensityUnit.MegawattPerCubicMeter, "MW/m³")] + [InlineData("en-US", PowerDensityUnit.MegawattPerLiter, "MW/l")] + [InlineData("en-US", PowerDensityUnit.MicrowattPerCubicFoot, "µW/ft³")] + [InlineData("en-US", PowerDensityUnit.MicrowattPerCubicInch, "µW/in³")] + [InlineData("en-US", PowerDensityUnit.MicrowattPerCubicMeter, "µW/m³")] + [InlineData("en-US", PowerDensityUnit.MicrowattPerLiter, "µW/l")] + [InlineData("en-US", PowerDensityUnit.MilliwattPerCubicFoot, "mW/ft³")] + [InlineData("en-US", PowerDensityUnit.MilliwattPerCubicInch, "mW/in³")] + [InlineData("en-US", PowerDensityUnit.MilliwattPerCubicMeter, "mW/m³")] + [InlineData("en-US", PowerDensityUnit.MilliwattPerLiter, "mW/l")] + [InlineData("en-US", PowerDensityUnit.NanowattPerCubicFoot, "nW/ft³")] + [InlineData("en-US", PowerDensityUnit.NanowattPerCubicInch, "nW/in³")] + [InlineData("en-US", PowerDensityUnit.NanowattPerCubicMeter, "nW/m³")] + [InlineData("en-US", PowerDensityUnit.NanowattPerLiter, "nW/l")] + [InlineData("en-US", PowerDensityUnit.PicowattPerCubicFoot, "pW/ft³")] + [InlineData("en-US", PowerDensityUnit.PicowattPerCubicInch, "pW/in³")] + [InlineData("en-US", PowerDensityUnit.PicowattPerCubicMeter, "pW/m³")] + [InlineData("en-US", PowerDensityUnit.PicowattPerLiter, "pW/l")] + [InlineData("en-US", PowerDensityUnit.TerawattPerCubicFoot, "TW/ft³")] + [InlineData("en-US", PowerDensityUnit.TerawattPerCubicInch, "TW/in³")] + [InlineData("en-US", PowerDensityUnit.TerawattPerCubicMeter, "TW/m³")] + [InlineData("en-US", PowerDensityUnit.TerawattPerLiter, "TW/l")] + [InlineData("en-US", PowerDensityUnit.WattPerCubicFoot, "W/ft³")] + [InlineData("en-US", PowerDensityUnit.WattPerCubicInch, "W/in³")] + [InlineData("en-US", PowerDensityUnit.WattPerCubicMeter, "W/m³")] + [InlineData("en-US", PowerDensityUnit.WattPerLiter, "W/l")] + public void GetAbbreviationForCulture(string culture, PowerDensityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = PowerDensity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(PowerDensity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = PowerDensity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PowerDensityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index 51343a449f..ee2f068dde 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -216,53 +216,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 dBmW", PowerRatioUnit.DecibelMilliwatt, 4.2)] + [InlineData("en-US", "4.2 dBm", PowerRatioUnit.DecibelMilliwatt, 4.2)] + [InlineData("en-US", "4.2 dBW", PowerRatioUnit.DecibelWatt, 4.2)] + public void Parse(string culture, string quantityString, PowerRatioUnit expectedUnit, double expectedValue) { - try - { - var parsed = PowerRatio.Parse("1 dBmW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelMilliwatts, DecibelMilliwattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerRatio.Parse("1 dBm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelMilliwatts, DecibelMilliwattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PowerRatio.Parse("1 dBW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecibelWatts, DecibelWattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = PowerRatio.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 dBmW", PowerRatioUnit.DecibelMilliwatt, 4.2)] + [InlineData("en-US", "4.2 dBm", PowerRatioUnit.DecibelMilliwatt, 4.2)] + [InlineData("en-US", "4.2 dBW", PowerRatioUnit.DecibelWatt, 4.2)] + public void TryParse(string culture, string quantityString, PowerRatioUnit expectedUnit, double expectedValue) { - { - Assert.True(PowerRatio.TryParse("1 dBmW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelMilliwatts, DecibelMilliwattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsed.Unit); - } - - { - Assert.True(PowerRatio.TryParse("1 dBm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelMilliwatts, DecibelMilliwattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsed.Unit); - } - - { - Assert.True(PowerRatio.TryParse("1 dBW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecibelWatts, DecibelWattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelWatt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(PowerRatio.TryParse(quantityString, out PowerRatio parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -355,6 +330,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerR Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PowerRatioUnit.DecibelMilliwatt, "dBmW")] + [InlineData("en-US", PowerRatioUnit.DecibelWatt, "dBW")] + public void GetAbbreviationForCulture(string culture, PowerRatioUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = PowerRatio.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(PowerRatio.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = PowerRatio.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PowerRatioUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index ad6432be58..5ab10f5d8b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -426,368 +426,82 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 hp(S)", PowerUnit.BoilerHorsepower, 4.2)] + [InlineData("en-US", "4.2 Btu/h", PowerUnit.BritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 Btu/hr", PowerUnit.BritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 daW", PowerUnit.Decawatt, 4.2)] + [InlineData("en-US", "4.2 dW", PowerUnit.Deciwatt, 4.2)] + [InlineData("en-US", "4.2 hp(E)", PowerUnit.ElectricalHorsepower, 4.2)] + [InlineData("en-US", "4.2 fW", PowerUnit.Femtowatt, 4.2)] + [InlineData("en-US", "4.2 GJ/h", PowerUnit.GigajoulePerHour, 4.2)] + [InlineData("en-US", "4.2 GW", PowerUnit.Gigawatt, 4.2)] + [InlineData("en-US", "4.2 hp(H)", PowerUnit.HydraulicHorsepower, 4.2)] + [InlineData("en-US", "4.2 J/h", PowerUnit.JoulePerHour, 4.2)] + [InlineData("en-US", "4.2 kBtu/h", PowerUnit.KilobritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 kJ/h", PowerUnit.KilojoulePerHour, 4.2)] + [InlineData("en-US", "4.2 kW", PowerUnit.Kilowatt, 4.2)] + [InlineData("en-US", "4.2 hp(I)", PowerUnit.MechanicalHorsepower, 4.2)] + [InlineData("en-US", "4.2 MBtu/h", PowerUnit.MegabritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 MJ/h", PowerUnit.MegajoulePerHour, 4.2)] + [InlineData("en-US", "4.2 MW", PowerUnit.Megawatt, 4.2)] + [InlineData("en-US", "4.2 hp(M)", PowerUnit.MetricHorsepower, 4.2)] + [InlineData("en-US", "4.2 µW", PowerUnit.Microwatt, 4.2)] + [InlineData("en-US", "4.2 mJ/h", PowerUnit.MillijoulePerHour, 4.2)] + [InlineData("en-US", "4.2 mW", PowerUnit.Milliwatt, 4.2)] + [InlineData("en-US", "4.2 nW", PowerUnit.Nanowatt, 4.2)] + [InlineData("en-US", "4.2 PW", PowerUnit.Petawatt, 4.2)] + [InlineData("en-US", "4.2 pW", PowerUnit.Picowatt, 4.2)] + [InlineData("en-US", "4.2 TW", PowerUnit.Terawatt, 4.2)] + [InlineData("en-US", "4.2 TR", PowerUnit.TonOfRefrigeration, 4.2)] + [InlineData("en-US", "4.2 W", PowerUnit.Watt, 4.2)] + public void Parse(string culture, string quantityString, PowerUnit expectedUnit, double expectedValue) { - try - { - var parsed = Power.Parse("1 hp(S)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BoilerHorsepower, BoilerHorsepowerTolerance); - Assert.Equal(PowerUnit.BoilerHorsepower, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 Btu/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 Btu/hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 daW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decawatts, DecawattsTolerance); - Assert.Equal(PowerUnit.Decawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 dW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Deciwatts, DeciwattsTolerance); - Assert.Equal(PowerUnit.Deciwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 hp(E)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ElectricalHorsepower, ElectricalHorsepowerTolerance); - Assert.Equal(PowerUnit.ElectricalHorsepower, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 fW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Femtowatts, FemtowattsTolerance); - Assert.Equal(PowerUnit.Femtowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 GJ/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigajoulesPerHour, GigajoulesPerHourTolerance); - Assert.Equal(PowerUnit.GigajoulePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 GW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigawatts, GigawattsTolerance); - Assert.Equal(PowerUnit.Gigawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 hp(H)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HydraulicHorsepower, HydraulicHorsepowerTolerance); - Assert.Equal(PowerUnit.HydraulicHorsepower, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 J/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerHour, JoulesPerHourTolerance); - Assert.Equal(PowerUnit.JoulePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 kBtu/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 kBtu/hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 kJ/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerHour, KilojoulesPerHourTolerance); - Assert.Equal(PowerUnit.KilojoulePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 kW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilowatts, KilowattsTolerance); - Assert.Equal(PowerUnit.Kilowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 hp(I)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MechanicalHorsepower, MechanicalHorsepowerTolerance); - Assert.Equal(PowerUnit.MechanicalHorsepower, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 MBtu/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnitsPerHour, MegabritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 MBtu/hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnitsPerHour, MegabritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 MJ/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerHour, MegajoulesPerHourTolerance); - Assert.Equal(PowerUnit.MegajoulePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 MW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megawatts, MegawattsTolerance); - Assert.Equal(PowerUnit.Megawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 hp(M)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricHorsepower, MetricHorsepowerTolerance); - Assert.Equal(PowerUnit.MetricHorsepower, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 µW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microwatts, MicrowattsTolerance); - Assert.Equal(PowerUnit.Microwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 mJ/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillijoulesPerHour, MillijoulesPerHourTolerance); - Assert.Equal(PowerUnit.MillijoulePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 mW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliwatts, MilliwattsTolerance); - Assert.Equal(PowerUnit.Milliwatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 nW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanowatts, NanowattsTolerance); - Assert.Equal(PowerUnit.Nanowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 PW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petawatts, PetawattsTolerance); - Assert.Equal(PowerUnit.Petawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 pW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picowatts, PicowattsTolerance); - Assert.Equal(PowerUnit.Picowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 TW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terawatts, TerawattsTolerance); - Assert.Equal(PowerUnit.Terawatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 TR", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonsOfRefrigeration, TonsOfRefrigerationTolerance); - Assert.Equal(PowerUnit.TonOfRefrigeration, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Power.Parse("1 W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Watts, WattsTolerance); - Assert.Equal(PowerUnit.Watt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Power.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 hp(S)", PowerUnit.BoilerHorsepower, 4.2)] + [InlineData("en-US", "4.2 Btu/h", PowerUnit.BritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 Btu/hr", PowerUnit.BritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 daW", PowerUnit.Decawatt, 4.2)] + [InlineData("en-US", "4.2 dW", PowerUnit.Deciwatt, 4.2)] + [InlineData("en-US", "4.2 hp(E)", PowerUnit.ElectricalHorsepower, 4.2)] + [InlineData("en-US", "4.2 fW", PowerUnit.Femtowatt, 4.2)] + [InlineData("en-US", "4.2 GJ/h", PowerUnit.GigajoulePerHour, 4.2)] + [InlineData("en-US", "4.2 GW", PowerUnit.Gigawatt, 4.2)] + [InlineData("en-US", "4.2 hp(H)", PowerUnit.HydraulicHorsepower, 4.2)] + [InlineData("en-US", "4.2 J/h", PowerUnit.JoulePerHour, 4.2)] + [InlineData("en-US", "4.2 kBtu/h", PowerUnit.KilobritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 kJ/h", PowerUnit.KilojoulePerHour, 4.2)] + [InlineData("en-US", "4.2 kW", PowerUnit.Kilowatt, 4.2)] + [InlineData("en-US", "4.2 hp(I)", PowerUnit.MechanicalHorsepower, 4.2)] + [InlineData("en-US", "4.2 MBtu/h", PowerUnit.MegabritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour, 4.2)] + [InlineData("en-US", "4.2 MJ/h", PowerUnit.MegajoulePerHour, 4.2)] + [InlineData("en-US", "4.2 MW", PowerUnit.Megawatt, 4.2)] + [InlineData("en-US", "4.2 hp(M)", PowerUnit.MetricHorsepower, 4.2)] + [InlineData("en-US", "4.2 µW", PowerUnit.Microwatt, 4.2)] + [InlineData("en-US", "4.2 mJ/h", PowerUnit.MillijoulePerHour, 4.2)] + [InlineData("en-US", "4.2 mW", PowerUnit.Milliwatt, 4.2)] + [InlineData("en-US", "4.2 nW", PowerUnit.Nanowatt, 4.2)] + [InlineData("en-US", "4.2 PW", PowerUnit.Petawatt, 4.2)] + [InlineData("en-US", "4.2 pW", PowerUnit.Picowatt, 4.2)] + [InlineData("en-US", "4.2 TW", PowerUnit.Terawatt, 4.2)] + [InlineData("en-US", "4.2 TR", PowerUnit.TonOfRefrigeration, 4.2)] + [InlineData("en-US", "4.2 W", PowerUnit.Watt, 4.2)] + public void TryParse(string culture, string quantityString, PowerUnit expectedUnit, double expectedValue) { - { - Assert.True(Power.TryParse("1 hp(S)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoilerHorsepower, BoilerHorsepowerTolerance); - Assert.Equal(PowerUnit.BoilerHorsepower, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 Btu/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 Btu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 daW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decawatts, DecawattsTolerance); - Assert.Equal(PowerUnit.Decawatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 dW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciwatts, DeciwattsTolerance); - Assert.Equal(PowerUnit.Deciwatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 hp(E)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ElectricalHorsepower, ElectricalHorsepowerTolerance); - Assert.Equal(PowerUnit.ElectricalHorsepower, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 fW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Femtowatts, FemtowattsTolerance); - Assert.Equal(PowerUnit.Femtowatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 GJ/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigajoulesPerHour, GigajoulesPerHourTolerance); - Assert.Equal(PowerUnit.GigajoulePerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 GW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigawatts, GigawattsTolerance); - Assert.Equal(PowerUnit.Gigawatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 hp(H)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HydraulicHorsepower, HydraulicHorsepowerTolerance); - Assert.Equal(PowerUnit.HydraulicHorsepower, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 J/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerHour, JoulesPerHourTolerance); - Assert.Equal(PowerUnit.JoulePerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 kBtu/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 kBtu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 kJ/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerHour, KilojoulesPerHourTolerance); - Assert.Equal(PowerUnit.KilojoulePerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 kW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilowatts, KilowattsTolerance); - Assert.Equal(PowerUnit.Kilowatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 hp(I)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MechanicalHorsepower, MechanicalHorsepowerTolerance); - Assert.Equal(PowerUnit.MechanicalHorsepower, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 MBtu/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnitsPerHour, MegabritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 MBtu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegabritishThermalUnitsPerHour, MegabritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 hp(M)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricHorsepower, MetricHorsepowerTolerance); - Assert.Equal(PowerUnit.MetricHorsepower, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 µW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microwatts, MicrowattsTolerance); - Assert.Equal(PowerUnit.Microwatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 nW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanowatts, NanowattsTolerance); - Assert.Equal(PowerUnit.Nanowatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 TW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terawatts, TerawattsTolerance); - Assert.Equal(PowerUnit.Terawatt, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 TR", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonsOfRefrigeration, TonsOfRefrigerationTolerance); - Assert.Equal(PowerUnit.TonOfRefrigeration, parsed.Unit); - } - - { - Assert.True(Power.TryParse("1 W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Watts, WattsTolerance); - Assert.Equal(PowerUnit.Watt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Power.TryParse(quantityString, out Power parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1096,6 +810,53 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerU Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PowerUnit.BoilerHorsepower, "hp(S)")] + [InlineData("en-US", PowerUnit.BritishThermalUnitPerHour, "Btu/h")] + [InlineData("en-US", PowerUnit.Decawatt, "daW")] + [InlineData("en-US", PowerUnit.Deciwatt, "dW")] + [InlineData("en-US", PowerUnit.ElectricalHorsepower, "hp(E)")] + [InlineData("en-US", PowerUnit.Femtowatt, "fW")] + [InlineData("en-US", PowerUnit.GigajoulePerHour, "GJ/h")] + [InlineData("en-US", PowerUnit.Gigawatt, "GW")] + [InlineData("en-US", PowerUnit.HydraulicHorsepower, "hp(H)")] + [InlineData("en-US", PowerUnit.JoulePerHour, "J/h")] + [InlineData("en-US", PowerUnit.KilobritishThermalUnitPerHour, "kBtu/h")] + [InlineData("en-US", PowerUnit.KilojoulePerHour, "kJ/h")] + [InlineData("en-US", PowerUnit.Kilowatt, "kW")] + [InlineData("en-US", PowerUnit.MechanicalHorsepower, "hp(I)")] + [InlineData("en-US", PowerUnit.MegabritishThermalUnitPerHour, "MBtu/h")] + [InlineData("en-US", PowerUnit.MegajoulePerHour, "MJ/h")] + [InlineData("en-US", PowerUnit.Megawatt, "MW")] + [InlineData("en-US", PowerUnit.MetricHorsepower, "hp(M)")] + [InlineData("en-US", PowerUnit.Microwatt, "µW")] + [InlineData("en-US", PowerUnit.MillijoulePerHour, "mJ/h")] + [InlineData("en-US", PowerUnit.Milliwatt, "mW")] + [InlineData("en-US", PowerUnit.Nanowatt, "nW")] + [InlineData("en-US", PowerUnit.Petawatt, "PW")] + [InlineData("en-US", PowerUnit.Picowatt, "pW")] + [InlineData("en-US", PowerUnit.Terawatt, "TW")] + [InlineData("en-US", PowerUnit.TonOfRefrigeration, "TR")] + [InlineData("en-US", PowerUnit.Watt, "W")] + public void GetAbbreviationForCulture(string culture, PowerUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Power.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Power.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Power.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PowerUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index af87cc5e8a..704c32fec3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -372,638 +372,118 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 atm/s", PressureChangeRateUnit.AtmospherePerSecond, 4.2)] + [InlineData("en-US", "4.2 bar/min", PressureChangeRateUnit.BarPerMinute, 4.2)] + [InlineData("en-US", "4.2 bar/s", PressureChangeRateUnit.BarPerSecond, 4.2)] + [InlineData("en-US", "4.2 kPa/min", PressureChangeRateUnit.KilopascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 kPa/s", PressureChangeRateUnit.KilopascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 MPa/min", PressureChangeRateUnit.MegapascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 MPa/s", PressureChangeRateUnit.MegapascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 mbar/min", PressureChangeRateUnit.MillibarPerMinute, 4.2)] + [InlineData("en-US", "4.2 mbar/s", PressureChangeRateUnit.MillibarPerSecond, 4.2)] + [InlineData("en-US", "4.2 mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pa/min", PressureChangeRateUnit.PascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 Pa/s", PressureChangeRateUnit.PascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 атм/с", PressureChangeRateUnit.AtmospherePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 бар/мин", PressureChangeRateUnit.BarPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 бар/с", PressureChangeRateUnit.BarPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 кПа/мин", PressureChangeRateUnit.KilopascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 кПа/с", PressureChangeRateUnit.KilopascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 МПа/мин", PressureChangeRateUnit.MegapascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 МПа/с", PressureChangeRateUnit.MegapascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мбар/мин", PressureChangeRateUnit.MillibarPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мбар/с", PressureChangeRateUnit.MillibarPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Па/мин", PressureChangeRateUnit.PascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Па/с", PressureChangeRateUnit.PascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + public void Parse(string culture, string quantityString, PressureChangeRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = PressureChangeRate.Parse("1 atm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AtmospheresPerSecond, AtmospheresPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 атм/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.AtmospheresPerSecond, AtmospheresPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 bar/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BarsPerMinute, BarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 бар/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.BarsPerMinute, BarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 bar/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BarsPerSecond, BarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 бар/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.BarsPerSecond, BarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kPa/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerMinute, KilopascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 кПа/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerMinute, KilopascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kPa/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerSecond, KilopascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 кПа/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerSecond, KilopascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 ksi/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kipf/in²/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 ksi/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kipf/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 ksi/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kipf/in²/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 ksi/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 kipf/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 MPa/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerMinute, MegapascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 МПа/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerMinute, MegapascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 MPa/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerSecond, MegapascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 МПа/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerSecond, MegapascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Mpsi/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Mlb/in²/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Мpsi/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Мlb/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Mpsi/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Mlb/in²/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Мpsi/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Мlb/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 mbar/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillibarsPerMinute, MillibarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 мбар/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillibarsPerMinute, MillibarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 mbar/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillibarsPerSecond, MillibarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 мбар/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillibarsPerSecond, MillibarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 mmHg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercuryPerSecond, MillimetersOfMercuryPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 mmHg/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercuryPerSecond, MillimetersOfMercuryPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Pa/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalsPerMinute, PascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Па/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalsPerMinute, PascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Pa/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PascalsPerSecond, PascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 Па/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PascalsPerSecond, PascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 psi/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 lb/in²/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 psi/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 lb/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 psi/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 lb/in²/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 psi/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = PressureChangeRate.Parse("1 lb/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = PressureChangeRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 atm/s", PressureChangeRateUnit.AtmospherePerSecond, 4.2)] + [InlineData("en-US", "4.2 bar/min", PressureChangeRateUnit.BarPerMinute, 4.2)] + [InlineData("en-US", "4.2 bar/s", PressureChangeRateUnit.BarPerSecond, 4.2)] + [InlineData("en-US", "4.2 kPa/min", PressureChangeRateUnit.KilopascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 kPa/s", PressureChangeRateUnit.KilopascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 MPa/min", PressureChangeRateUnit.MegapascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 MPa/s", PressureChangeRateUnit.MegapascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 mbar/min", PressureChangeRateUnit.MillibarPerMinute, 4.2)] + [InlineData("en-US", "4.2 mbar/s", PressureChangeRateUnit.MillibarPerSecond, 4.2)] + [InlineData("en-US", "4.2 mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, 4.2)] + [InlineData("en-US", "4.2 Pa/min", PressureChangeRateUnit.PascalPerMinute, 4.2)] + [InlineData("en-US", "4.2 Pa/s", PressureChangeRateUnit.PascalPerSecond, 4.2)] + [InlineData("en-US", "4.2 psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("en-US", "4.2 psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("en-US", "4.2 lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 атм/с", PressureChangeRateUnit.AtmospherePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 бар/мин", PressureChangeRateUnit.BarPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 бар/с", PressureChangeRateUnit.BarPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 кПа/мин", PressureChangeRateUnit.KilopascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 кПа/с", PressureChangeRateUnit.KilopascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 МПа/мин", PressureChangeRateUnit.MegapascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 МПа/с", PressureChangeRateUnit.MegapascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мбар/мин", PressureChangeRateUnit.MillibarPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мбар/с", PressureChangeRateUnit.MillibarPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Па/мин", PressureChangeRateUnit.PascalPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Па/с", PressureChangeRateUnit.PascalPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, PressureChangeRateUnit expectedUnit, double expectedValue) { - { - Assert.True(PressureChangeRate.TryParse("1 atm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AtmospheresPerSecond, AtmospheresPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 атм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AtmospheresPerSecond, AtmospheresPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 bar/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BarsPerMinute, BarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 бар/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BarsPerMinute, BarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 bar/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BarsPerSecond, BarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 бар/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BarsPerSecond, BarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kPa/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerMinute, KilopascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 кПа/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerMinute, KilopascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kPa/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerSecond, KilopascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 кПа/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopascalsPerSecond, KilopascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 ksi/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kipf/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 ksi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kipf/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerMinute, KilopoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 ksi/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kipf/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 ksi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 kipf/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInchPerSecond, KilopoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 MPa/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerMinute, MegapascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 МПа/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerMinute, MegapascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 MPa/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerSecond, MegapascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 МПа/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapascalsPerSecond, MegapascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Mpsi/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Mlb/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Мpsi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Мlb/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerMinute, MegapoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Mpsi/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Mlb/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Мpsi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Мlb/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundsForcePerSquareInchPerSecond, MegapoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 mbar/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillibarsPerMinute, MillibarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 мбар/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillibarsPerMinute, MillibarsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 mbar/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillibarsPerSecond, MillibarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 мбар/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillibarsPerSecond, MillibarsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 mmHg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercuryPerSecond, MillimetersOfMercuryPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 mmHg/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercuryPerSecond, MillimetersOfMercuryPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Pa/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalsPerMinute, PascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Па/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalsPerMinute, PascalsPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Pa/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalsPerSecond, PascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 Па/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PascalsPerSecond, PascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 psi/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 lb/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 psi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 lb/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerMinute, PoundsForcePerSquareInchPerMinuteTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 psi/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 lb/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 psi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } - - { - Assert.True(PressureChangeRate.TryParse("1 lb/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInchPerSecond, PoundsForcePerSquareInchPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(PressureChangeRate.TryParse(quantityString, out PressureChangeRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1360,6 +840,62 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Pressu Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PressureChangeRateUnit.AtmospherePerSecond, "atm/s")] + [InlineData("en-US", PressureChangeRateUnit.BarPerMinute, "bar/min")] + [InlineData("en-US", PressureChangeRateUnit.BarPerSecond, "bar/s")] + [InlineData("en-US", PressureChangeRateUnit.KilopascalPerMinute, "kPa/min")] + [InlineData("en-US", PressureChangeRateUnit.KilopascalPerSecond, "kPa/s")] + [InlineData("en-US", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, "ksi/min")] + [InlineData("en-US", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, "ksi/s")] + [InlineData("en-US", PressureChangeRateUnit.MegapascalPerMinute, "MPa/min")] + [InlineData("en-US", PressureChangeRateUnit.MegapascalPerSecond, "MPa/s")] + [InlineData("en-US", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, "Mpsi/min")] + [InlineData("en-US", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, "Mpsi/s")] + [InlineData("en-US", PressureChangeRateUnit.MillibarPerMinute, "mbar/min")] + [InlineData("en-US", PressureChangeRateUnit.MillibarPerSecond, "mbar/s")] + [InlineData("en-US", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, "mmHg/s")] + [InlineData("en-US", PressureChangeRateUnit.PascalPerMinute, "Pa/min")] + [InlineData("en-US", PressureChangeRateUnit.PascalPerSecond, "Pa/s")] + [InlineData("en-US", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, "psi/min")] + [InlineData("en-US", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, "psi/s")] + [InlineData("ru-RU", PressureChangeRateUnit.AtmospherePerSecond, "атм/с")] + [InlineData("ru-RU", PressureChangeRateUnit.BarPerMinute, "бар/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.BarPerSecond, "бар/с")] + [InlineData("ru-RU", PressureChangeRateUnit.KilopascalPerMinute, "кПа/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.KilopascalPerSecond, "кПа/с")] + [InlineData("ru-RU", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, "ksi/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, "ksi/с")] + [InlineData("ru-RU", PressureChangeRateUnit.MegapascalPerMinute, "МПа/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.MegapascalPerSecond, "МПа/с")] + [InlineData("ru-RU", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, "Мpsi/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, "Мpsi/с")] + [InlineData("ru-RU", PressureChangeRateUnit.MillibarPerMinute, "мбар/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.MillibarPerSecond, "мбар/с")] + [InlineData("ru-RU", PressureChangeRateUnit.MillimeterOfMercuryPerSecond, "mmHg/с")] + [InlineData("ru-RU", PressureChangeRateUnit.PascalPerMinute, "Па/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.PascalPerSecond, "Па/с")] + [InlineData("ru-RU", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, "psi/мин")] + [InlineData("ru-RU", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, "psi/с")] + public void GetAbbreviationForCulture(string culture, PressureChangeRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = PressureChangeRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(PressureChangeRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = PressureChangeRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PressureChangeRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index 0d9bd30790..d13e2202af 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -552,1215 +552,216 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 atm", PressureUnit.Atmosphere, 4.2)] + [InlineData("en-US", "4.2 bar", PressureUnit.Bar, 4.2)] + [InlineData("en-US", "4.2 cbar", PressureUnit.Centibar, 4.2)] + [InlineData("en-US", "4.2 cmH₂O", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cmH2O", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cm wc", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cm wg", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 daPa", PressureUnit.Decapascal, 4.2)] + [InlineData("en-US", "4.2 dbar", PressureUnit.Decibar, 4.2)] + [InlineData("en-US", "4.2 dyn/cm²", PressureUnit.DynePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 ft of head", PressureUnit.FootOfHead, 4.2)] + [InlineData("en-US", "4.2 GPa", PressureUnit.Gigapascal, 4.2)] + [InlineData("en-US", "4.2 hPa", PressureUnit.Hectopascal, 4.2)] + [InlineData("en-US", "4.2 inHg", PressureUnit.InchOfMercury, 4.2)] + [InlineData("en-US", "4.2 inH2O", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 inch wc", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 wc", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 kbar", PressureUnit.Kilobar, 4.2)] + [InlineData("en-US", "4.2 kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m²", PressureUnit.KilogramForcePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m²", PressureUnit.KilonewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kPa", PressureUnit.Kilopascal, 4.2)] + [InlineData("en-US", "4.2 kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 ksi", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 kipf/in²", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 kipf/mil²", PressureUnit.KilopoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 Mbar", PressureUnit.Megabar, 4.2)] + [InlineData("en-US", "4.2 MN/m²", PressureUnit.MeganewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 MPa", PressureUnit.Megapascal, 4.2)] + [InlineData("en-US", "4.2 m of head", PressureUnit.MeterOfHead, 4.2)] + [InlineData("en-US", "4.2 mH₂O", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mH2O", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 m wc", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 m wg", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 µbar", PressureUnit.Microbar, 4.2)] + [InlineData("en-US", "4.2 µPa", PressureUnit.Micropascal, 4.2)] + [InlineData("en-US", "4.2 mbar", PressureUnit.Millibar, 4.2)] + [InlineData("en-US", "4.2 mmHg", PressureUnit.MillimeterOfMercury, 4.2)] + [InlineData("en-US", "4.2 mmH₂O", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mmH2O", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mm wc", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mm wg", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mPa", PressureUnit.Millipascal, 4.2)] + [InlineData("en-US", "4.2 mtorr", PressureUnit.Millitorr, 4.2)] + [InlineData("en-US", "4.2 N/cm²", PressureUnit.NewtonPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m²", PressureUnit.NewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm²", PressureUnit.NewtonPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Pa", PressureUnit.Pascal, 4.2)] + [InlineData("en-US", "4.2 lb/ft²", PressureUnit.PoundForcePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 psi", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/in²", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/mil²", PressureUnit.PoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 lbs/mil²", PressureUnit.PoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared, 4.2)] + [InlineData("en-US", "4.2 lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared, 4.2)] + [InlineData("en-US", "4.2 at", PressureUnit.TechnicalAtmosphere, 4.2)] + [InlineData("en-US", "4.2 tf/cm²", PressureUnit.TonneForcePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m²", PressureUnit.TonneForcePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm²", PressureUnit.TonneForcePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 torr", PressureUnit.Torr, 4.2)] + [InlineData("ru-RU", "4,2 атм", PressureUnit.Atmosphere, 4.2)] + [InlineData("ru-RU", "4,2 бар", PressureUnit.Bar, 4.2)] + [InlineData("ru-RU", "4,2 сбар", PressureUnit.Centibar, 4.2)] + [InlineData("ru-RU", "4,2 даПа", PressureUnit.Decapascal, 4.2)] + [InlineData("ru-RU", "4,2 дбар", PressureUnit.Decibar, 4.2)] + [InlineData("ru-RU", "4,2 ГПа", PressureUnit.Gigapascal, 4.2)] + [InlineData("ru-RU", "4,2 гПа", PressureUnit.Hectopascal, 4.2)] + [InlineData("ru-RU", "4,2 кбар", PressureUnit.Kilobar, 4.2)] + [InlineData("ru-RU", "4,2 кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/м²", PressureUnit.KilogramForcePerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/см²", PressureUnit.KilonewtonPerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/м²", PressureUnit.KilonewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кПа", PressureUnit.Kilopascal, 4.2)] + [InlineData("ru-RU", "4,2 ksi", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 Мбар", PressureUnit.Megabar, 4.2)] + [InlineData("ru-RU", "4,2 МН/м²", PressureUnit.MeganewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 МПа", PressureUnit.Megapascal, 4.2)] + [InlineData("ru-RU", "4,2 мкбар", PressureUnit.Microbar, 4.2)] + [InlineData("ru-RU", "4,2 мкПа", PressureUnit.Micropascal, 4.2)] + [InlineData("ru-RU", "4,2 мбар", PressureUnit.Millibar, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст.", PressureUnit.MillimeterOfMercury, 4.2)] + [InlineData("ru-RU", "4,2 мПа", PressureUnit.Millipascal, 4.2)] + [InlineData("ru-RU", "4,2 мторр", PressureUnit.Millitorr, 4.2)] + [InlineData("ru-RU", "4,2 Н/см²", PressureUnit.NewtonPerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Н/м²", PressureUnit.NewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 Н/мм²", PressureUnit.NewtonPerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па", PressureUnit.Pascal, 4.2)] + [InlineData("ru-RU", "4,2 psi", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 ат", PressureUnit.TechnicalAtmosphere, 4.2)] + [InlineData("ru-RU", "4,2 торр", PressureUnit.Torr, 4.2)] + public void Parse(string culture, string quantityString, PressureUnit expectedUnit, double expectedValue) { - try - { - var parsed = Pressure.Parse("1 atm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Atmospheres, AtmospheresTolerance); - Assert.Equal(PressureUnit.Atmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 атм", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Atmospheres, AtmospheresTolerance); - Assert.Equal(PressureUnit.Atmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 bar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Bars, BarsTolerance); - Assert.Equal(PressureUnit.Bar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 бар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Bars, BarsTolerance); - Assert.Equal(PressureUnit.Bar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 cbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centibars, CentibarsTolerance); - Assert.Equal(PressureUnit.Centibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 сбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centibars, CentibarsTolerance); - Assert.Equal(PressureUnit.Centibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 cmH₂O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 cmH2O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 cm wc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 cm wg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 daPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decapascals, DecapascalsTolerance); - Assert.Equal(PressureUnit.Decapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 даПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decapascals, DecapascalsTolerance); - Assert.Equal(PressureUnit.Decapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 dbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decibars, DecibarsTolerance); - Assert.Equal(PressureUnit.Decibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 дбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decibars, DecibarsTolerance); - Assert.Equal(PressureUnit.Decibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 dyn/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DynesPerSquareCentimeter, DynesPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.DynePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 ft of head", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetOfHead, FeetOfHeadTolerance); - Assert.Equal(PressureUnit.FootOfHead, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 GPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigapascals, GigapascalsTolerance); - Assert.Equal(PressureUnit.Gigapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 ГПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigapascals, GigapascalsTolerance); - Assert.Equal(PressureUnit.Gigapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 hPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hectopascals, HectopascalsTolerance); - Assert.Equal(PressureUnit.Hectopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 гПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hectopascals, HectopascalsTolerance); - Assert.Equal(PressureUnit.Hectopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 inHg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesOfMercury, InchesOfMercuryTolerance); - Assert.Equal(PressureUnit.InchOfMercury, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 inH2O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 inch wc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 wc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilobars, KilobarsTolerance); - Assert.Equal(PressureUnit.Kilobar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilobars, KilobarsTolerance); - Assert.Equal(PressureUnit.Kilobar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kgf/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кгс/см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kgf/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кгс/м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kgf/mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кгс/мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kN/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кН/см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kN/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кН/м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kN/mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кН/мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilopascals, KilopascalsTolerance); - Assert.Equal(PressureUnit.Kilopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 кПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilopascals, KilopascalsTolerance); - Assert.Equal(PressureUnit.Kilopascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kipf/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 ksi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kipf/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 ksi", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kipf/in²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 kipf/mil²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareMil, KilopoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Mbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megabars, MegabarsTolerance); - Assert.Equal(PressureUnit.Megabar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Мбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megabars, MegabarsTolerance); - Assert.Equal(PressureUnit.Megabar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 MN/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 МН/м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 MPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megapascals, MegapascalsTolerance); - Assert.Equal(PressureUnit.Megapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 МПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megapascals, MegapascalsTolerance); - Assert.Equal(PressureUnit.Megapascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 m of head", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersOfHead, MetersOfHeadTolerance); - Assert.Equal(PressureUnit.MeterOfHead, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mH₂O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mH2O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 m wc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 m wg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 µbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microbars, MicrobarsTolerance); - Assert.Equal(PressureUnit.Microbar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мкбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microbars, MicrobarsTolerance); - Assert.Equal(PressureUnit.Microbar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 µPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Micropascals, MicropascalsTolerance); - Assert.Equal(PressureUnit.Micropascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мкПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Micropascals, MicropascalsTolerance); - Assert.Equal(PressureUnit.Micropascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mbar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millibars, MillibarsTolerance); - Assert.Equal(PressureUnit.Millibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мбар", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millibars, MillibarsTolerance); - Assert.Equal(PressureUnit.Millibar, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mmHg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercury, MillimetersOfMercuryTolerance); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мм рт.ст.", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercury, MillimetersOfMercuryTolerance); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mmH₂O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mmH2O", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mm wc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mm wg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mPa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millipascals, MillipascalsTolerance); - Assert.Equal(PressureUnit.Millipascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мПа", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millipascals, MillipascalsTolerance); - Assert.Equal(PressureUnit.Millipascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 mtorr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millitorrs, MillitorrsTolerance); - Assert.Equal(PressureUnit.Millitorr, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 мторр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millitorrs, MillitorrsTolerance); - Assert.Equal(PressureUnit.Millitorr, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 N/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Н/см²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 N/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Н/м²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 N/mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Н/мм²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Pa", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Pascals, PascalsTolerance); - Assert.Equal(PressureUnit.Pascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 Па", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Pascals, PascalsTolerance); - Assert.Equal(PressureUnit.Pascal, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lb/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareFoot, PoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 psi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lb/in²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 psi", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lb/in²", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lb/mil²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareMil, PoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lbs/mil²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareMil, PoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lbm/(in·s²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerInchSecondSquared, PoundsPerInchSecondSquaredTolerance); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 lb/(in·s²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsPerInchSecondSquared, PoundsPerInchSecondSquaredTolerance); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 at", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TechnicalAtmospheres, TechnicalAtmospheresTolerance); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 ат", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.TechnicalAtmospheres, TechnicalAtmospheresTolerance); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 tf/cm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareCentimeter, TonnesForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 tf/m²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareMeter, TonnesForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 tf/mm²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareMillimeter, TonnesForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 torr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Torrs, TorrsTolerance); - Assert.Equal(PressureUnit.Torr, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Pressure.Parse("1 торр", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Torrs, TorrsTolerance); - Assert.Equal(PressureUnit.Torr, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Pressure.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 atm", PressureUnit.Atmosphere, 4.2)] + [InlineData("en-US", "4.2 bar", PressureUnit.Bar, 4.2)] + [InlineData("en-US", "4.2 cbar", PressureUnit.Centibar, 4.2)] + [InlineData("en-US", "4.2 cmH₂O", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cmH2O", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cm wc", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 cm wg", PressureUnit.CentimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 daPa", PressureUnit.Decapascal, 4.2)] + [InlineData("en-US", "4.2 dbar", PressureUnit.Decibar, 4.2)] + [InlineData("en-US", "4.2 dyn/cm²", PressureUnit.DynePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 ft of head", PressureUnit.FootOfHead, 4.2)] + [InlineData("en-US", "4.2 GPa", PressureUnit.Gigapascal, 4.2)] + [InlineData("en-US", "4.2 hPa", PressureUnit.Hectopascal, 4.2)] + [InlineData("en-US", "4.2 inHg", PressureUnit.InchOfMercury, 4.2)] + [InlineData("en-US", "4.2 inH2O", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 inch wc", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 wc", PressureUnit.InchOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 kbar", PressureUnit.Kilobar, 4.2)] + [InlineData("en-US", "4.2 kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m²", PressureUnit.KilogramForcePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m²", PressureUnit.KilonewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 kPa", PressureUnit.Kilopascal, 4.2)] + [InlineData("en-US", "4.2 kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 ksi", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 kipf/in²", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 kipf/mil²", PressureUnit.KilopoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 Mbar", PressureUnit.Megabar, 4.2)] + [InlineData("en-US", "4.2 MN/m²", PressureUnit.MeganewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 MPa", PressureUnit.Megapascal, 4.2)] + [InlineData("en-US", "4.2 m of head", PressureUnit.MeterOfHead, 4.2)] + [InlineData("en-US", "4.2 mH₂O", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mH2O", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 m wc", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 m wg", PressureUnit.MeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 µbar", PressureUnit.Microbar, 4.2)] + [InlineData("en-US", "4.2 µPa", PressureUnit.Micropascal, 4.2)] + [InlineData("en-US", "4.2 mbar", PressureUnit.Millibar, 4.2)] + [InlineData("en-US", "4.2 mmHg", PressureUnit.MillimeterOfMercury, 4.2)] + [InlineData("en-US", "4.2 mmH₂O", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mmH2O", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mm wc", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mm wg", PressureUnit.MillimeterOfWaterColumn, 4.2)] + [InlineData("en-US", "4.2 mPa", PressureUnit.Millipascal, 4.2)] + [InlineData("en-US", "4.2 mtorr", PressureUnit.Millitorr, 4.2)] + [InlineData("en-US", "4.2 N/cm²", PressureUnit.NewtonPerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m²", PressureUnit.NewtonPerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm²", PressureUnit.NewtonPerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 Pa", PressureUnit.Pascal, 4.2)] + [InlineData("en-US", "4.2 lb/ft²", PressureUnit.PoundForcePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 psi", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/in²", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("en-US", "4.2 lb/mil²", PressureUnit.PoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 lbs/mil²", PressureUnit.PoundForcePerSquareMil, 4.2)] + [InlineData("en-US", "4.2 lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared, 4.2)] + [InlineData("en-US", "4.2 lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared, 4.2)] + [InlineData("en-US", "4.2 at", PressureUnit.TechnicalAtmosphere, 4.2)] + [InlineData("en-US", "4.2 tf/cm²", PressureUnit.TonneForcePerSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m²", PressureUnit.TonneForcePerSquareMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm²", PressureUnit.TonneForcePerSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 torr", PressureUnit.Torr, 4.2)] + [InlineData("ru-RU", "4,2 атм", PressureUnit.Atmosphere, 4.2)] + [InlineData("ru-RU", "4,2 бар", PressureUnit.Bar, 4.2)] + [InlineData("ru-RU", "4,2 сбар", PressureUnit.Centibar, 4.2)] + [InlineData("ru-RU", "4,2 даПа", PressureUnit.Decapascal, 4.2)] + [InlineData("ru-RU", "4,2 дбар", PressureUnit.Decibar, 4.2)] + [InlineData("ru-RU", "4,2 ГПа", PressureUnit.Gigapascal, 4.2)] + [InlineData("ru-RU", "4,2 гПа", PressureUnit.Hectopascal, 4.2)] + [InlineData("ru-RU", "4,2 кбар", PressureUnit.Kilobar, 4.2)] + [InlineData("ru-RU", "4,2 кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/м²", PressureUnit.KilogramForcePerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/см²", PressureUnit.KilonewtonPerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/м²", PressureUnit.KilonewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кПа", PressureUnit.Kilopascal, 4.2)] + [InlineData("ru-RU", "4,2 ksi", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 kipf/in²", PressureUnit.KilopoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 Мбар", PressureUnit.Megabar, 4.2)] + [InlineData("ru-RU", "4,2 МН/м²", PressureUnit.MeganewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 МПа", PressureUnit.Megapascal, 4.2)] + [InlineData("ru-RU", "4,2 мкбар", PressureUnit.Microbar, 4.2)] + [InlineData("ru-RU", "4,2 мкПа", PressureUnit.Micropascal, 4.2)] + [InlineData("ru-RU", "4,2 мбар", PressureUnit.Millibar, 4.2)] + [InlineData("ru-RU", "4,2 мм рт.ст.", PressureUnit.MillimeterOfMercury, 4.2)] + [InlineData("ru-RU", "4,2 мПа", PressureUnit.Millipascal, 4.2)] + [InlineData("ru-RU", "4,2 мторр", PressureUnit.Millitorr, 4.2)] + [InlineData("ru-RU", "4,2 Н/см²", PressureUnit.NewtonPerSquareCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 Н/м²", PressureUnit.NewtonPerSquareMeter, 4.2)] + [InlineData("ru-RU", "4,2 Н/мм²", PressureUnit.NewtonPerSquareMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 Па", PressureUnit.Pascal, 4.2)] + [InlineData("ru-RU", "4,2 psi", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 lb/in²", PressureUnit.PoundForcePerSquareInch, 4.2)] + [InlineData("ru-RU", "4,2 ат", PressureUnit.TechnicalAtmosphere, 4.2)] + [InlineData("ru-RU", "4,2 торр", PressureUnit.Torr, 4.2)] + public void TryParse(string culture, string quantityString, PressureUnit expectedUnit, double expectedValue) { - { - Assert.True(Pressure.TryParse("1 atm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Atmospheres, AtmospheresTolerance); - Assert.Equal(PressureUnit.Atmosphere, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 атм", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Atmospheres, AtmospheresTolerance); - Assert.Equal(PressureUnit.Atmosphere, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 bar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Bars, BarsTolerance); - Assert.Equal(PressureUnit.Bar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 бар", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Bars, BarsTolerance); - Assert.Equal(PressureUnit.Bar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 cbar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centibars, CentibarsTolerance); - Assert.Equal(PressureUnit.Centibar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 сбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centibars, CentibarsTolerance); - Assert.Equal(PressureUnit.Centibar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 cmH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 cmH2O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 cm wc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 cm wg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersOfWaterColumn, CentimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 daPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decapascals, DecapascalsTolerance); - Assert.Equal(PressureUnit.Decapascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 даПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decapascals, DecapascalsTolerance); - Assert.Equal(PressureUnit.Decapascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 dbar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decibars, DecibarsTolerance); - Assert.Equal(PressureUnit.Decibar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 дбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decibars, DecibarsTolerance); - Assert.Equal(PressureUnit.Decibar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 dyn/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DynesPerSquareCentimeter, DynesPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.DynePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 ft of head", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetOfHead, FeetOfHeadTolerance); - Assert.Equal(PressureUnit.FootOfHead, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 GPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigapascals, GigapascalsTolerance); - Assert.Equal(PressureUnit.Gigapascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 hPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectopascals, HectopascalsTolerance); - Assert.Equal(PressureUnit.Hectopascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 inHg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesOfMercury, InchesOfMercuryTolerance); - Assert.Equal(PressureUnit.InchOfMercury, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 inH2O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 inch wc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 wc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesOfWaterColumn, InchesOfWaterColumnTolerance); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kbar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilobars, KilobarsTolerance); - Assert.Equal(PressureUnit.Kilobar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilobars, KilobarsTolerance); - Assert.Equal(PressureUnit.Kilobar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kgf/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кгс/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kgf/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кгс/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kgf/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кгс/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kN/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кН/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kN/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кН/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kN/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кН/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopascals, KilopascalsTolerance); - Assert.Equal(PressureUnit.Kilopascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 кПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilopascals, KilopascalsTolerance); - Assert.Equal(PressureUnit.Kilopascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kipf/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareFoot, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 ksi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kipf/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 ksi", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kipf/in²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 kipf/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerSquareMil, KilopoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareMil, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 MN/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 МН/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 m of head", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersOfHead, MetersOfHeadTolerance); - Assert.Equal(PressureUnit.MeterOfHead, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mH2O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 m wc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 m wg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersOfWaterColumn, MetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 µbar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microbars, MicrobarsTolerance); - Assert.Equal(PressureUnit.Microbar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 мкбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microbars, MicrobarsTolerance); - Assert.Equal(PressureUnit.Microbar, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 µPa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micropascals, MicropascalsTolerance); - Assert.Equal(PressureUnit.Micropascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 мкПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Micropascals, MicropascalsTolerance); - Assert.Equal(PressureUnit.Micropascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mmHg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercury, MillimetersOfMercuryTolerance); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 мм рт.ст.", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfMercury, MillimetersOfMercuryTolerance); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mmH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mmH2O", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mm wc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mm wg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersOfWaterColumn, MillimetersOfWaterColumnTolerance); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 mtorr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millitorrs, MillitorrsTolerance); - Assert.Equal(PressureUnit.Millitorr, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 мторр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millitorrs, MillitorrsTolerance); - Assert.Equal(PressureUnit.Millitorr, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 N/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 Н/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 N/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 Н/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 N/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 Н/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 Pa", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pascals, PascalsTolerance); - Assert.Equal(PressureUnit.Pascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 Па", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Pascals, PascalsTolerance); - Assert.Equal(PressureUnit.Pascal, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lb/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareFoot, PoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareFoot, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 psi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lb/in²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 psi", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lb/in²", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lb/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareMil, PoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lbs/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerSquareMil, PoundsForcePerSquareMilTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lbm/(in·s²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerInchSecondSquared, PoundsPerInchSecondSquaredTolerance); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 lb/(in·s²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsPerInchSecondSquared, PoundsPerInchSecondSquaredTolerance); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 at", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TechnicalAtmospheres, TechnicalAtmospheresTolerance); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 ат", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TechnicalAtmospheres, TechnicalAtmospheresTolerance); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 tf/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareCentimeter, TonnesForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareCentimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 tf/m²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareMeter, TonnesForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 tf/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerSquareMillimeter, TonnesForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMillimeter, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 torr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Torrs, TorrsTolerance); - Assert.Equal(PressureUnit.Torr, parsed.Unit); - } - - { - Assert.True(Pressure.TryParse("1 торр", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Torrs, TorrsTolerance); - Assert.Equal(PressureUnit.Torr, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Pressure.TryParse(quantityString, out Pressure parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -2469,6 +1470,106 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Pressu Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", PressureUnit.Atmosphere, "atm")] + [InlineData("en-US", PressureUnit.Bar, "bar")] + [InlineData("en-US", PressureUnit.Centibar, "cbar")] + [InlineData("en-US", PressureUnit.CentimeterOfWaterColumn, "cmH₂O")] + [InlineData("en-US", PressureUnit.Decapascal, "daPa")] + [InlineData("en-US", PressureUnit.Decibar, "dbar")] + [InlineData("en-US", PressureUnit.DynePerSquareCentimeter, "dyn/cm²")] + [InlineData("en-US", PressureUnit.FootOfHead, "ft of head")] + [InlineData("en-US", PressureUnit.Gigapascal, "GPa")] + [InlineData("en-US", PressureUnit.Hectopascal, "hPa")] + [InlineData("en-US", PressureUnit.InchOfMercury, "inHg")] + [InlineData("en-US", PressureUnit.InchOfWaterColumn, "inH2O")] + [InlineData("en-US", PressureUnit.Kilobar, "kbar")] + [InlineData("en-US", PressureUnit.KilogramForcePerSquareCentimeter, "kgf/cm²")] + [InlineData("en-US", PressureUnit.KilogramForcePerSquareMeter, "kgf/m²")] + [InlineData("en-US", PressureUnit.KilogramForcePerSquareMillimeter, "kgf/mm²")] + [InlineData("en-US", PressureUnit.KilonewtonPerSquareCentimeter, "kN/cm²")] + [InlineData("en-US", PressureUnit.KilonewtonPerSquareMeter, "kN/m²")] + [InlineData("en-US", PressureUnit.KilonewtonPerSquareMillimeter, "kN/mm²")] + [InlineData("en-US", PressureUnit.Kilopascal, "kPa")] + [InlineData("en-US", PressureUnit.KilopoundForcePerSquareFoot, "kipf/ft²")] + [InlineData("en-US", PressureUnit.KilopoundForcePerSquareInch, "ksi")] + [InlineData("en-US", PressureUnit.KilopoundForcePerSquareMil, "kipf/mil²")] + [InlineData("en-US", PressureUnit.Megabar, "Mbar")] + [InlineData("en-US", PressureUnit.MeganewtonPerSquareMeter, "MN/m²")] + [InlineData("en-US", PressureUnit.Megapascal, "MPa")] + [InlineData("en-US", PressureUnit.MeterOfHead, "m of head")] + [InlineData("en-US", PressureUnit.MeterOfWaterColumn, "mH₂O")] + [InlineData("en-US", PressureUnit.Microbar, "µbar")] + [InlineData("en-US", PressureUnit.Micropascal, "µPa")] + [InlineData("en-US", PressureUnit.Millibar, "mbar")] + [InlineData("en-US", PressureUnit.MillimeterOfMercury, "mmHg")] + [InlineData("en-US", PressureUnit.MillimeterOfWaterColumn, "mmH₂O")] + [InlineData("en-US", PressureUnit.Millipascal, "mPa")] + [InlineData("en-US", PressureUnit.Millitorr, "mtorr")] + [InlineData("en-US", PressureUnit.NewtonPerSquareCentimeter, "N/cm²")] + [InlineData("en-US", PressureUnit.NewtonPerSquareMeter, "N/m²")] + [InlineData("en-US", PressureUnit.NewtonPerSquareMillimeter, "N/mm²")] + [InlineData("en-US", PressureUnit.Pascal, "Pa")] + [InlineData("en-US", PressureUnit.PoundForcePerSquareFoot, "lb/ft²")] + [InlineData("en-US", PressureUnit.PoundForcePerSquareInch, "psi")] + [InlineData("en-US", PressureUnit.PoundForcePerSquareMil, "lb/mil²")] + [InlineData("en-US", PressureUnit.PoundPerInchSecondSquared, "lbm/(in·s²)")] + [InlineData("en-US", PressureUnit.TechnicalAtmosphere, "at")] + [InlineData("en-US", PressureUnit.TonneForcePerSquareCentimeter, "tf/cm²")] + [InlineData("en-US", PressureUnit.TonneForcePerSquareMeter, "tf/m²")] + [InlineData("en-US", PressureUnit.TonneForcePerSquareMillimeter, "tf/mm²")] + [InlineData("en-US", PressureUnit.Torr, "torr")] + [InlineData("ru-RU", PressureUnit.Atmosphere, "атм")] + [InlineData("ru-RU", PressureUnit.Bar, "бар")] + [InlineData("ru-RU", PressureUnit.Centibar, "сбар")] + [InlineData("ru-RU", PressureUnit.Decapascal, "даПа")] + [InlineData("ru-RU", PressureUnit.Decibar, "дбар")] + [InlineData("ru-RU", PressureUnit.Gigapascal, "ГПа")] + [InlineData("ru-RU", PressureUnit.Hectopascal, "гПа")] + [InlineData("ru-RU", PressureUnit.Kilobar, "кбар")] + [InlineData("ru-RU", PressureUnit.KilogramForcePerSquareCentimeter, "кгс/см²")] + [InlineData("ru-RU", PressureUnit.KilogramForcePerSquareMeter, "кгс/м²")] + [InlineData("ru-RU", PressureUnit.KilogramForcePerSquareMillimeter, "кгс/мм²")] + [InlineData("ru-RU", PressureUnit.KilonewtonPerSquareCentimeter, "кН/см²")] + [InlineData("ru-RU", PressureUnit.KilonewtonPerSquareMeter, "кН/м²")] + [InlineData("ru-RU", PressureUnit.KilonewtonPerSquareMillimeter, "кН/мм²")] + [InlineData("ru-RU", PressureUnit.Kilopascal, "кПа")] + [InlineData("ru-RU", PressureUnit.KilopoundForcePerSquareInch, "ksi")] + [InlineData("ru-RU", PressureUnit.Megabar, "Мбар")] + [InlineData("ru-RU", PressureUnit.MeganewtonPerSquareMeter, "МН/м²")] + [InlineData("ru-RU", PressureUnit.Megapascal, "МПа")] + [InlineData("ru-RU", PressureUnit.Microbar, "мкбар")] + [InlineData("ru-RU", PressureUnit.Micropascal, "мкПа")] + [InlineData("ru-RU", PressureUnit.Millibar, "мбар")] + [InlineData("ru-RU", PressureUnit.MillimeterOfMercury, "мм рт.ст.")] + [InlineData("ru-RU", PressureUnit.Millipascal, "мПа")] + [InlineData("ru-RU", PressureUnit.Millitorr, "мторр")] + [InlineData("ru-RU", PressureUnit.NewtonPerSquareCentimeter, "Н/см²")] + [InlineData("ru-RU", PressureUnit.NewtonPerSquareMeter, "Н/м²")] + [InlineData("ru-RU", PressureUnit.NewtonPerSquareMillimeter, "Н/мм²")] + [InlineData("ru-RU", PressureUnit.Pascal, "Па")] + [InlineData("ru-RU", PressureUnit.PoundForcePerSquareInch, "psi")] + [InlineData("ru-RU", PressureUnit.TechnicalAtmosphere, "ат")] + [InlineData("ru-RU", PressureUnit.Torr, "торр")] + public void GetAbbreviationForCulture(string culture, PressureUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Pressure.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Pressure.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Pressure.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(PressureUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs index dcf7191f37..be1f7b0f78 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs @@ -324,248 +324,58 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 µSv/h", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, 4.2)] + [InlineData("en-US", "4.2 µSv/s", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 mrem/h", RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, 4.2)] + [InlineData("en-US", "4.2 mSv/h", RadiationEquivalentDoseRateUnit.MillisievertPerHour, 4.2)] + [InlineData("en-US", "4.2 mSv/s", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 nSv/h", RadiationEquivalentDoseRateUnit.NanosievertPerHour, 4.2)] + [InlineData("en-US", "4.2 nSv/s", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 rem/h", RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, 4.2)] + [InlineData("en-US", "4.2 Sv/h", RadiationEquivalentDoseRateUnit.SievertPerHour, 4.2)] + [InlineData("en-US", "4.2 Sv/s", RadiationEquivalentDoseRateUnit.SievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв/ч", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв/с", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мЗв/ч", RadiationEquivalentDoseRateUnit.MillisievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мЗв/с", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нЗв/ч", RadiationEquivalentDoseRateUnit.NanosievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 нЗв/с", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Зв/ч", RadiationEquivalentDoseRateUnit.SievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 Зв/с", RadiationEquivalentDoseRateUnit.SievertPerSecond, 4.2)] + public void Parse(string culture, string quantityString, RadiationEquivalentDoseRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 µSv/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerHour, MicrosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 мкЗв/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerHour, MicrosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 µSv/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerSecond, MicrosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 мкЗв/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerSecond, MicrosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 mrem/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliroentgensEquivalentManPerHour, MilliroentgensEquivalentManPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 mSv/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerHour, MillisievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 мЗв/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerHour, MillisievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 mSv/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerSecond, MillisievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 мЗв/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerSecond, MillisievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 nSv/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerHour, NanosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 нЗв/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerHour, NanosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 nSv/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerSecond, NanosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 нЗв/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerSecond, NanosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 rem/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RoentgensEquivalentManPerHour, RoentgensEquivalentManPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 Sv/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SievertsPerHour, SievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 Зв/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SievertsPerHour, SievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 Sv/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SievertsPerSecond, SievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDoseRate.Parse("1 Зв/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.SievertsPerSecond, SievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RadiationEquivalentDoseRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 µSv/h", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, 4.2)] + [InlineData("en-US", "4.2 µSv/s", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 mrem/h", RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, 4.2)] + [InlineData("en-US", "4.2 mSv/h", RadiationEquivalentDoseRateUnit.MillisievertPerHour, 4.2)] + [InlineData("en-US", "4.2 mSv/s", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 nSv/h", RadiationEquivalentDoseRateUnit.NanosievertPerHour, 4.2)] + [InlineData("en-US", "4.2 nSv/s", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, 4.2)] + [InlineData("en-US", "4.2 rem/h", RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, 4.2)] + [InlineData("en-US", "4.2 Sv/h", RadiationEquivalentDoseRateUnit.SievertPerHour, 4.2)] + [InlineData("en-US", "4.2 Sv/s", RadiationEquivalentDoseRateUnit.SievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв/ч", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв/с", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мЗв/ч", RadiationEquivalentDoseRateUnit.MillisievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мЗв/с", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нЗв/ч", RadiationEquivalentDoseRateUnit.NanosievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 нЗв/с", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Зв/ч", RadiationEquivalentDoseRateUnit.SievertPerHour, 4.2)] + [InlineData("ru-RU", "4,2 Зв/с", RadiationEquivalentDoseRateUnit.SievertPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, RadiationEquivalentDoseRateUnit expectedUnit, double expectedValue) { - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 µSv/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerHour, MicrosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 мкЗв/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerHour, MicrosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 µSv/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerSecond, MicrosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 мкЗв/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrosievertsPerSecond, MicrosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 mrem/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliroentgensEquivalentManPerHour, MilliroentgensEquivalentManPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 mSv/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerHour, MillisievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 мЗв/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerHour, MillisievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 mSv/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerSecond, MillisievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 мЗв/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillisievertsPerSecond, MillisievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.MillisievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 nSv/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerHour, NanosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 нЗв/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerHour, NanosievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 nSv/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerSecond, NanosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 нЗв/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanosievertsPerSecond, NanosievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 rem/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RoentgensEquivalentManPerHour, RoentgensEquivalentManPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 Sv/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SievertsPerHour, SievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 Зв/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SievertsPerHour, SievertsPerHourTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerHour, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 Sv/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SievertsPerSecond, SievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerSecond, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDoseRate.TryParse("1 Зв/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SievertsPerSecond, SievertsPerSecondTolerance); - Assert.Equal(RadiationEquivalentDoseRateUnit.SievertPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RadiationEquivalentDoseRate.TryParse(quantityString, out RadiationEquivalentDoseRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -746,6 +556,44 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Radiat Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, "µSv/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, "µSv/s")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, "mrem/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.MillisievertPerHour, "mSv/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, "mSv/s")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.NanosievertPerHour, "nSv/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, "nSv/s")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, "rem/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.SievertPerHour, "Sv/h")] + [InlineData("en-US", RadiationEquivalentDoseRateUnit.SievertPerSecond, "Sv/s")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.MicrosievertPerHour, "мкЗв/ч")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, "мкЗв/с")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.MillisievertPerHour, "мЗв/ч")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.MillisievertPerSecond, "мЗв/с")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.NanosievertPerHour, "нЗв/ч")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.NanosievertPerSecond, "нЗв/с")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.SievertPerHour, "Зв/ч")] + [InlineData("ru-RU", RadiationEquivalentDoseRateUnit.SievertPerSecond, "Зв/с")] + public void GetAbbreviationForCulture(string culture, RadiationEquivalentDoseRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RadiationEquivalentDoseRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RadiationEquivalentDoseRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RadiationEquivalentDoseRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RadiationEquivalentDoseRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs index 7f2cad754f..71a11f8c7c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs @@ -300,144 +300,42 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 µSv", RadiationEquivalentDoseUnit.Microsievert, 4.2)] + [InlineData("en-US", "4.2 mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, 4.2)] + [InlineData("en-US", "4.2 mSv", RadiationEquivalentDoseUnit.Millisievert, 4.2)] + [InlineData("en-US", "4.2 nSv", RadiationEquivalentDoseUnit.Nanosievert, 4.2)] + [InlineData("en-US", "4.2 rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan, 4.2)] + [InlineData("en-US", "4.2 Sv", RadiationEquivalentDoseUnit.Sievert, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв", RadiationEquivalentDoseUnit.Microsievert, 4.2)] + [InlineData("ru-RU", "4,2 мЗв", RadiationEquivalentDoseUnit.Millisievert, 4.2)] + [InlineData("ru-RU", "4,2 нЗв", RadiationEquivalentDoseUnit.Nanosievert, 4.2)] + [InlineData("ru-RU", "4,2 Зв", RadiationEquivalentDoseUnit.Sievert, 4.2)] + public void Parse(string culture, string quantityString, RadiationEquivalentDoseUnit expectedUnit, double expectedValue) { - try - { - var parsed = RadiationEquivalentDose.Parse("1 µSv", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microsieverts, MicrosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 мкЗв", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microsieverts, MicrosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 mrem", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliroentgensEquivalentMan, MilliroentgensEquivalentManTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 mSv", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millisieverts, MillisievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 мЗв", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millisieverts, MillisievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 nSv", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanosieverts, NanosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 нЗв", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanosieverts, NanosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 rem", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RoentgensEquivalentMan, RoentgensEquivalentManTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.RoentgenEquivalentMan, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 Sv", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Sieverts, SievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationEquivalentDose.Parse("1 Зв", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Sieverts, SievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RadiationEquivalentDose.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 µSv", RadiationEquivalentDoseUnit.Microsievert, 4.2)] + [InlineData("en-US", "4.2 mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, 4.2)] + [InlineData("en-US", "4.2 mSv", RadiationEquivalentDoseUnit.Millisievert, 4.2)] + [InlineData("en-US", "4.2 nSv", RadiationEquivalentDoseUnit.Nanosievert, 4.2)] + [InlineData("en-US", "4.2 rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan, 4.2)] + [InlineData("en-US", "4.2 Sv", RadiationEquivalentDoseUnit.Sievert, 4.2)] + [InlineData("ru-RU", "4,2 мкЗв", RadiationEquivalentDoseUnit.Microsievert, 4.2)] + [InlineData("ru-RU", "4,2 мЗв", RadiationEquivalentDoseUnit.Millisievert, 4.2)] + [InlineData("ru-RU", "4,2 нЗв", RadiationEquivalentDoseUnit.Nanosievert, 4.2)] + [InlineData("ru-RU", "4,2 Зв", RadiationEquivalentDoseUnit.Sievert, 4.2)] + public void TryParse(string culture, string quantityString, RadiationEquivalentDoseUnit expectedUnit, double expectedValue) { - { - Assert.True(RadiationEquivalentDose.TryParse("1 µSv", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microsieverts, MicrosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 мкЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microsieverts, MicrosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 mrem", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliroentgensEquivalentMan, MilliroentgensEquivalentManTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 mSv", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millisieverts, MillisievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 мЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millisieverts, MillisievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 nSv", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanosieverts, NanosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 нЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanosieverts, NanosievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 rem", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RoentgensEquivalentMan, RoentgensEquivalentManTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.RoentgenEquivalentMan, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 Sv", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Sieverts, SievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsed.Unit); - } - - { - Assert.True(RadiationEquivalentDose.TryParse("1 Зв", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Sieverts, SievertsTolerance); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RadiationEquivalentDose.TryParse(quantityString, out RadiationEquivalentDose parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -570,6 +468,36 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Radiat Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RadiationEquivalentDoseUnit.Microsievert, "µSv")] + [InlineData("en-US", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, "mrem")] + [InlineData("en-US", RadiationEquivalentDoseUnit.Millisievert, "mSv")] + [InlineData("en-US", RadiationEquivalentDoseUnit.Nanosievert, "nSv")] + [InlineData("en-US", RadiationEquivalentDoseUnit.RoentgenEquivalentMan, "rem")] + [InlineData("en-US", RadiationEquivalentDoseUnit.Sievert, "Sv")] + [InlineData("ru-RU", RadiationEquivalentDoseUnit.Microsievert, "мкЗв")] + [InlineData("ru-RU", RadiationEquivalentDoseUnit.Millisievert, "мЗв")] + [InlineData("ru-RU", RadiationEquivalentDoseUnit.Nanosievert, "нЗв")] + [InlineData("ru-RU", RadiationEquivalentDoseUnit.Sievert, "Зв")] + public void GetAbbreviationForCulture(string culture, RadiationEquivalentDoseUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RadiationEquivalentDose.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RadiationEquivalentDose.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RadiationEquivalentDose.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RadiationEquivalentDoseUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index c043436273..9d668c6f29 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -312,118 +312,38 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 C/kg", RadiationExposureUnit.CoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µR", RadiationExposureUnit.Microroentgen, 4.2)] + [InlineData("en-US", "4.2 mC/kg", RadiationExposureUnit.MillicoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mR", RadiationExposureUnit.Milliroentgen, 4.2)] + [InlineData("en-US", "4.2 nC/kg", RadiationExposureUnit.NanocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 pC/kg", RadiationExposureUnit.PicocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 R", RadiationExposureUnit.Roentgen, 4.2)] + public void Parse(string culture, string quantityString, RadiationExposureUnit expectedUnit, double expectedValue) { - try - { - var parsed = RadiationExposure.Parse("1 C/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CoulombsPerKilogram, CoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 µC/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 µR", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microroentgens, MicroroentgensTolerance); - Assert.Equal(RadiationExposureUnit.Microroentgen, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 mC/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 mR", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliroentgens, MilliroentgensTolerance); - Assert.Equal(RadiationExposureUnit.Milliroentgen, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 nC/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 pC/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RadiationExposure.Parse("1 R", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Roentgens, RoentgensTolerance); - Assert.Equal(RadiationExposureUnit.Roentgen, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RadiationExposure.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 C/kg", RadiationExposureUnit.CoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 µR", RadiationExposureUnit.Microroentgen, 4.2)] + [InlineData("en-US", "4.2 mC/kg", RadiationExposureUnit.MillicoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mR", RadiationExposureUnit.Milliroentgen, 4.2)] + [InlineData("en-US", "4.2 nC/kg", RadiationExposureUnit.NanocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 pC/kg", RadiationExposureUnit.PicocoulombPerKilogram, 4.2)] + [InlineData("en-US", "4.2 R", RadiationExposureUnit.Roentgen, 4.2)] + public void TryParse(string culture, string quantityString, RadiationExposureUnit expectedUnit, double expectedValue) { - { - Assert.True(RadiationExposure.TryParse("1 C/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CoulombsPerKilogram, CoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 µC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 µR", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microroentgens, MicroroentgensTolerance); - Assert.Equal(RadiationExposureUnit.Microroentgen, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 mR", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Milliroentgens, MilliroentgensTolerance); - Assert.Equal(RadiationExposureUnit.Milliroentgen, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 pC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsed.Unit); - } - - { - Assert.True(RadiationExposure.TryParse("1 R", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Roentgens, RoentgensTolerance); - Assert.Equal(RadiationExposureUnit.Roentgen, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RadiationExposure.TryParse(quantityString, out RadiationExposure parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -556,6 +476,34 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Radiat Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RadiationExposureUnit.CoulombPerKilogram, "C/kg")] + [InlineData("en-US", RadiationExposureUnit.MicrocoulombPerKilogram, "µC/kg")] + [InlineData("en-US", RadiationExposureUnit.Microroentgen, "µR")] + [InlineData("en-US", RadiationExposureUnit.MillicoulombPerKilogram, "mC/kg")] + [InlineData("en-US", RadiationExposureUnit.Milliroentgen, "mR")] + [InlineData("en-US", RadiationExposureUnit.NanocoulombPerKilogram, "nC/kg")] + [InlineData("en-US", RadiationExposureUnit.PicocoulombPerKilogram, "pC/kg")] + [InlineData("en-US", RadiationExposureUnit.Roentgen, "R")] + public void GetAbbreviationForCulture(string culture, RadiationExposureUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RadiationExposure.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RadiationExposure.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RadiationExposure.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RadiationExposureUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs index 1bff8979af..3dfcd52d29 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs @@ -438,672 +438,138 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Bq", RadioactivityUnit.Becquerel, 4.2)] + [InlineData("en-US", "4.2 Ci", RadioactivityUnit.Curie, 4.2)] + [InlineData("en-US", "4.2 EBq", RadioactivityUnit.Exabecquerel, 4.2)] + [InlineData("en-US", "4.2 GBq", RadioactivityUnit.Gigabecquerel, 4.2)] + [InlineData("en-US", "4.2 GCi", RadioactivityUnit.Gigacurie, 4.2)] + [InlineData("en-US", "4.2 GRd", RadioactivityUnit.Gigarutherford, 4.2)] + [InlineData("en-US", "4.2 kBq", RadioactivityUnit.Kilobecquerel, 4.2)] + [InlineData("en-US", "4.2 kCi", RadioactivityUnit.Kilocurie, 4.2)] + [InlineData("en-US", "4.2 kRd", RadioactivityUnit.Kilorutherford, 4.2)] + [InlineData("en-US", "4.2 MBq", RadioactivityUnit.Megabecquerel, 4.2)] + [InlineData("en-US", "4.2 MCi", RadioactivityUnit.Megacurie, 4.2)] + [InlineData("en-US", "4.2 MRd", RadioactivityUnit.Megarutherford, 4.2)] + [InlineData("en-US", "4.2 µBq", RadioactivityUnit.Microbecquerel, 4.2)] + [InlineData("en-US", "4.2 µCi", RadioactivityUnit.Microcurie, 4.2)] + [InlineData("en-US", "4.2 µRd", RadioactivityUnit.Microrutherford, 4.2)] + [InlineData("en-US", "4.2 mBq", RadioactivityUnit.Millibecquerel, 4.2)] + [InlineData("en-US", "4.2 mCi", RadioactivityUnit.Millicurie, 4.2)] + [InlineData("en-US", "4.2 mRd", RadioactivityUnit.Millirutherford, 4.2)] + [InlineData("en-US", "4.2 nBq", RadioactivityUnit.Nanobecquerel, 4.2)] + [InlineData("en-US", "4.2 nCi", RadioactivityUnit.Nanocurie, 4.2)] + [InlineData("en-US", "4.2 nRd", RadioactivityUnit.Nanorutherford, 4.2)] + [InlineData("en-US", "4.2 PBq", RadioactivityUnit.Petabecquerel, 4.2)] + [InlineData("en-US", "4.2 pBq", RadioactivityUnit.Picobecquerel, 4.2)] + [InlineData("en-US", "4.2 pCi", RadioactivityUnit.Picocurie, 4.2)] + [InlineData("en-US", "4.2 pRd", RadioactivityUnit.Picorutherford, 4.2)] + [InlineData("en-US", "4.2 Rd", RadioactivityUnit.Rutherford, 4.2)] + [InlineData("en-US", "4.2 TBq", RadioactivityUnit.Terabecquerel, 4.2)] + [InlineData("en-US", "4.2 TCi", RadioactivityUnit.Teracurie, 4.2)] + [InlineData("en-US", "4.2 TRd", RadioactivityUnit.Terarutherford, 4.2)] + [InlineData("ru-RU", "4,2 Бк", RadioactivityUnit.Becquerel, 4.2)] + [InlineData("ru-RU", "4,2 Ки", RadioactivityUnit.Curie, 4.2)] + [InlineData("ru-RU", "4,2 ЭБк", RadioactivityUnit.Exabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ГБк", RadioactivityUnit.Gigabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ГКи", RadioactivityUnit.Gigacurie, 4.2)] + [InlineData("ru-RU", "4,2 ГРд", RadioactivityUnit.Gigarutherford, 4.2)] + [InlineData("ru-RU", "4,2 кБк", RadioactivityUnit.Kilobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 кКи", RadioactivityUnit.Kilocurie, 4.2)] + [InlineData("ru-RU", "4,2 кРд", RadioactivityUnit.Kilorutherford, 4.2)] + [InlineData("ru-RU", "4,2 МБк", RadioactivityUnit.Megabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 МКи", RadioactivityUnit.Megacurie, 4.2)] + [InlineData("ru-RU", "4,2 МРд", RadioactivityUnit.Megarutherford, 4.2)] + [InlineData("ru-RU", "4,2 мкБк", RadioactivityUnit.Microbecquerel, 4.2)] + [InlineData("ru-RU", "4,2 мкКи", RadioactivityUnit.Microcurie, 4.2)] + [InlineData("ru-RU", "4,2 мкРд", RadioactivityUnit.Microrutherford, 4.2)] + [InlineData("ru-RU", "4,2 мБк", RadioactivityUnit.Millibecquerel, 4.2)] + [InlineData("ru-RU", "4,2 мКи", RadioactivityUnit.Millicurie, 4.2)] + [InlineData("ru-RU", "4,2 мРд", RadioactivityUnit.Millirutherford, 4.2)] + [InlineData("ru-RU", "4,2 нБк", RadioactivityUnit.Nanobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 нКи", RadioactivityUnit.Nanocurie, 4.2)] + [InlineData("ru-RU", "4,2 нРд", RadioactivityUnit.Nanorutherford, 4.2)] + [InlineData("ru-RU", "4,2 ПБк", RadioactivityUnit.Petabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 пБк", RadioactivityUnit.Picobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 пКи", RadioactivityUnit.Picocurie, 4.2)] + [InlineData("ru-RU", "4,2 пРд", RadioactivityUnit.Picorutherford, 4.2)] + [InlineData("ru-RU", "4,2 Рд", RadioactivityUnit.Rutherford, 4.2)] + [InlineData("ru-RU", "4,2 ТБк", RadioactivityUnit.Terabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ТКи", RadioactivityUnit.Teracurie, 4.2)] + [InlineData("ru-RU", "4,2 ТРд", RadioactivityUnit.Terarutherford, 4.2)] + public void Parse(string culture, string quantityString, RadioactivityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Radioactivity.Parse("1 Bq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Becquerels, BecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Becquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 Бк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Becquerels, BecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Becquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 Ci", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Curies, CuriesTolerance); - Assert.Equal(RadioactivityUnit.Curie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 Ки", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Curies, CuriesTolerance); - Assert.Equal(RadioactivityUnit.Curie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 EBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Exabecquerels, ExabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ЭБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Exabecquerels, ExabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 GBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigabecquerels, GigabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ГБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigabecquerels, GigabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 GCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigacuries, GigacuriesTolerance); - Assert.Equal(RadioactivityUnit.Gigacurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ГКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigacuries, GigacuriesTolerance); - Assert.Equal(RadioactivityUnit.Gigacurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 GRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigarutherfords, GigarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ГРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Gigarutherfords, GigarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 kBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilobecquerels, KilobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 кБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilobecquerels, KilobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 kCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilocuries, KilocuriesTolerance); - Assert.Equal(RadioactivityUnit.Kilocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 кКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilocuries, KilocuriesTolerance); - Assert.Equal(RadioactivityUnit.Kilocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 kRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilorutherfords, KilorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 кРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kilorutherfords, KilorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 MBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megabecquerels, MegabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Megabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 МБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megabecquerels, MegabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Megabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 MCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megacuries, MegacuriesTolerance); - Assert.Equal(RadioactivityUnit.Megacurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 МКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megacuries, MegacuriesTolerance); - Assert.Equal(RadioactivityUnit.Megacurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 MRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megarutherfords, MegarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Megarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 МРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megarutherfords, MegarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Megarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 µBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microbecquerels, MicrobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мкБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microbecquerels, MicrobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 µCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microcuries, MicrocuriesTolerance); - Assert.Equal(RadioactivityUnit.Microcurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мкКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microcuries, MicrocuriesTolerance); - Assert.Equal(RadioactivityUnit.Microcurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 µRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microrutherfords, MicrorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Microrutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мкРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microrutherfords, MicrorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Microrutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 mBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millibecquerels, MillibecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Millibecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millibecquerels, MillibecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Millibecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 mCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millicuries, MillicuriesTolerance); - Assert.Equal(RadioactivityUnit.Millicurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millicuries, MillicuriesTolerance); - Assert.Equal(RadioactivityUnit.Millicurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 mRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millirutherfords, MillirutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Millirutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 мРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Millirutherfords, MillirutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Millirutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 nBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanobecquerels, NanobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 нБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanobecquerels, NanobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 nCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanocuries, NanocuriesTolerance); - Assert.Equal(RadioactivityUnit.Nanocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 нКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanocuries, NanocuriesTolerance); - Assert.Equal(RadioactivityUnit.Nanocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 nRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanorutherfords, NanorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 нРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanorutherfords, NanorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 PBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Petabecquerels, PetabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Petabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ПБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Petabecquerels, PetabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Petabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 pBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picobecquerels, PicobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Picobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 пБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picobecquerels, PicobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Picobecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 pCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picocuries, PicocuriesTolerance); - Assert.Equal(RadioactivityUnit.Picocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 пКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picocuries, PicocuriesTolerance); - Assert.Equal(RadioactivityUnit.Picocurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 pRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picorutherfords, PicorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Picorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 пРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Picorutherfords, PicorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Picorutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 Rd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Rutherfords, RutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Rutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 Рд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Rutherfords, RutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Rutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 TBq", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terabecquerels, TerabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ТБк", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Terabecquerels, TerabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 TCi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Teracuries, TeracuriesTolerance); - Assert.Equal(RadioactivityUnit.Teracurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ТКи", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Teracuries, TeracuriesTolerance); - Assert.Equal(RadioactivityUnit.Teracurie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 TRd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Terarutherfords, TerarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Terarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Radioactivity.Parse("1 ТРд", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Terarutherfords, TerarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Terarutherford, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Radioactivity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Bq", RadioactivityUnit.Becquerel, 4.2)] + [InlineData("en-US", "4.2 Ci", RadioactivityUnit.Curie, 4.2)] + [InlineData("en-US", "4.2 EBq", RadioactivityUnit.Exabecquerel, 4.2)] + [InlineData("en-US", "4.2 GBq", RadioactivityUnit.Gigabecquerel, 4.2)] + [InlineData("en-US", "4.2 GCi", RadioactivityUnit.Gigacurie, 4.2)] + [InlineData("en-US", "4.2 GRd", RadioactivityUnit.Gigarutherford, 4.2)] + [InlineData("en-US", "4.2 kBq", RadioactivityUnit.Kilobecquerel, 4.2)] + [InlineData("en-US", "4.2 kCi", RadioactivityUnit.Kilocurie, 4.2)] + [InlineData("en-US", "4.2 kRd", RadioactivityUnit.Kilorutherford, 4.2)] + [InlineData("en-US", "4.2 MBq", RadioactivityUnit.Megabecquerel, 4.2)] + [InlineData("en-US", "4.2 MCi", RadioactivityUnit.Megacurie, 4.2)] + [InlineData("en-US", "4.2 MRd", RadioactivityUnit.Megarutherford, 4.2)] + [InlineData("en-US", "4.2 µBq", RadioactivityUnit.Microbecquerel, 4.2)] + [InlineData("en-US", "4.2 µCi", RadioactivityUnit.Microcurie, 4.2)] + [InlineData("en-US", "4.2 µRd", RadioactivityUnit.Microrutherford, 4.2)] + [InlineData("en-US", "4.2 mBq", RadioactivityUnit.Millibecquerel, 4.2)] + [InlineData("en-US", "4.2 mCi", RadioactivityUnit.Millicurie, 4.2)] + [InlineData("en-US", "4.2 mRd", RadioactivityUnit.Millirutherford, 4.2)] + [InlineData("en-US", "4.2 nBq", RadioactivityUnit.Nanobecquerel, 4.2)] + [InlineData("en-US", "4.2 nCi", RadioactivityUnit.Nanocurie, 4.2)] + [InlineData("en-US", "4.2 nRd", RadioactivityUnit.Nanorutherford, 4.2)] + [InlineData("en-US", "4.2 PBq", RadioactivityUnit.Petabecquerel, 4.2)] + [InlineData("en-US", "4.2 pBq", RadioactivityUnit.Picobecquerel, 4.2)] + [InlineData("en-US", "4.2 pCi", RadioactivityUnit.Picocurie, 4.2)] + [InlineData("en-US", "4.2 pRd", RadioactivityUnit.Picorutherford, 4.2)] + [InlineData("en-US", "4.2 Rd", RadioactivityUnit.Rutherford, 4.2)] + [InlineData("en-US", "4.2 TBq", RadioactivityUnit.Terabecquerel, 4.2)] + [InlineData("en-US", "4.2 TCi", RadioactivityUnit.Teracurie, 4.2)] + [InlineData("en-US", "4.2 TRd", RadioactivityUnit.Terarutherford, 4.2)] + [InlineData("ru-RU", "4,2 Бк", RadioactivityUnit.Becquerel, 4.2)] + [InlineData("ru-RU", "4,2 Ки", RadioactivityUnit.Curie, 4.2)] + [InlineData("ru-RU", "4,2 ЭБк", RadioactivityUnit.Exabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ГБк", RadioactivityUnit.Gigabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ГКи", RadioactivityUnit.Gigacurie, 4.2)] + [InlineData("ru-RU", "4,2 ГРд", RadioactivityUnit.Gigarutherford, 4.2)] + [InlineData("ru-RU", "4,2 кБк", RadioactivityUnit.Kilobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 кКи", RadioactivityUnit.Kilocurie, 4.2)] + [InlineData("ru-RU", "4,2 кРд", RadioactivityUnit.Kilorutherford, 4.2)] + [InlineData("ru-RU", "4,2 МБк", RadioactivityUnit.Megabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 МКи", RadioactivityUnit.Megacurie, 4.2)] + [InlineData("ru-RU", "4,2 МРд", RadioactivityUnit.Megarutherford, 4.2)] + [InlineData("ru-RU", "4,2 мкБк", RadioactivityUnit.Microbecquerel, 4.2)] + [InlineData("ru-RU", "4,2 мкКи", RadioactivityUnit.Microcurie, 4.2)] + [InlineData("ru-RU", "4,2 мкРд", RadioactivityUnit.Microrutherford, 4.2)] + [InlineData("ru-RU", "4,2 мБк", RadioactivityUnit.Millibecquerel, 4.2)] + [InlineData("ru-RU", "4,2 мКи", RadioactivityUnit.Millicurie, 4.2)] + [InlineData("ru-RU", "4,2 мРд", RadioactivityUnit.Millirutherford, 4.2)] + [InlineData("ru-RU", "4,2 нБк", RadioactivityUnit.Nanobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 нКи", RadioactivityUnit.Nanocurie, 4.2)] + [InlineData("ru-RU", "4,2 нРд", RadioactivityUnit.Nanorutherford, 4.2)] + [InlineData("ru-RU", "4,2 ПБк", RadioactivityUnit.Petabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 пБк", RadioactivityUnit.Picobecquerel, 4.2)] + [InlineData("ru-RU", "4,2 пКи", RadioactivityUnit.Picocurie, 4.2)] + [InlineData("ru-RU", "4,2 пРд", RadioactivityUnit.Picorutherford, 4.2)] + [InlineData("ru-RU", "4,2 Рд", RadioactivityUnit.Rutherford, 4.2)] + [InlineData("ru-RU", "4,2 ТБк", RadioactivityUnit.Terabecquerel, 4.2)] + [InlineData("ru-RU", "4,2 ТКи", RadioactivityUnit.Teracurie, 4.2)] + [InlineData("ru-RU", "4,2 ТРд", RadioactivityUnit.Terarutherford, 4.2)] + public void TryParse(string culture, string quantityString, RadioactivityUnit expectedUnit, double expectedValue) { - { - Assert.True(Radioactivity.TryParse("1 Bq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Becquerels, BecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Becquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 Бк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Becquerels, BecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Becquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 Ci", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Curies, CuriesTolerance); - Assert.Equal(RadioactivityUnit.Curie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 Ки", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Curies, CuriesTolerance); - Assert.Equal(RadioactivityUnit.Curie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 EBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Exabecquerels, ExabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ЭБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Exabecquerels, ExabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 GBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigabecquerels, GigabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ГБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigabecquerels, GigabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 GCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigacuries, GigacuriesTolerance); - Assert.Equal(RadioactivityUnit.Gigacurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ГКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigacuries, GigacuriesTolerance); - Assert.Equal(RadioactivityUnit.Gigacurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 GRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigarutherfords, GigarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ГРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigarutherfords, GigarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 kBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilobecquerels, KilobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 кБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilobecquerels, KilobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 kCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilocuries, KilocuriesTolerance); - Assert.Equal(RadioactivityUnit.Kilocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 кКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilocuries, KilocuriesTolerance); - Assert.Equal(RadioactivityUnit.Kilocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 kRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilorutherfords, KilorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 кРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilorutherfords, KilorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 µBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microbecquerels, MicrobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 мкБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microbecquerels, MicrobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 µCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microcuries, MicrocuriesTolerance); - Assert.Equal(RadioactivityUnit.Microcurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 мкКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microcuries, MicrocuriesTolerance); - Assert.Equal(RadioactivityUnit.Microcurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 µRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microrutherfords, MicrorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Microrutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 мкРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microrutherfords, MicrorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Microrutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 nBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanobecquerels, NanobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 нБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanobecquerels, NanobecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 nCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanocuries, NanocuriesTolerance); - Assert.Equal(RadioactivityUnit.Nanocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 нКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanocuries, NanocuriesTolerance); - Assert.Equal(RadioactivityUnit.Nanocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 nRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanorutherfords, NanorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 нРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanorutherfords, NanorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 pCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picocuries, PicocuriesTolerance); - Assert.Equal(RadioactivityUnit.Picocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 пКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picocuries, PicocuriesTolerance); - Assert.Equal(RadioactivityUnit.Picocurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 pRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picorutherfords, PicorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Picorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 пРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picorutherfords, PicorutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Picorutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 Rd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Rutherfords, RutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Rutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 Рд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Rutherfords, RutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Rutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 TBq", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terabecquerels, TerabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ТБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terabecquerels, TerabecquerelsTolerance); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 TCi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teracuries, TeracuriesTolerance); - Assert.Equal(RadioactivityUnit.Teracurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ТКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Teracuries, TeracuriesTolerance); - Assert.Equal(RadioactivityUnit.Teracurie, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 TRd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terarutherfords, TerarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Terarutherford, parsed.Unit); - } - - { - Assert.True(Radioactivity.TryParse("1 ТРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Terarutherfords, TerarutherfordsTolerance); - Assert.Equal(RadioactivityUnit.Terarutherford, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Radioactivity.TryParse(quantityString, out Radioactivity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1520,6 +986,84 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Radioa Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RadioactivityUnit.Becquerel, "Bq")] + [InlineData("en-US", RadioactivityUnit.Curie, "Ci")] + [InlineData("en-US", RadioactivityUnit.Exabecquerel, "EBq")] + [InlineData("en-US", RadioactivityUnit.Gigabecquerel, "GBq")] + [InlineData("en-US", RadioactivityUnit.Gigacurie, "GCi")] + [InlineData("en-US", RadioactivityUnit.Gigarutherford, "GRd")] + [InlineData("en-US", RadioactivityUnit.Kilobecquerel, "kBq")] + [InlineData("en-US", RadioactivityUnit.Kilocurie, "kCi")] + [InlineData("en-US", RadioactivityUnit.Kilorutherford, "kRd")] + [InlineData("en-US", RadioactivityUnit.Megabecquerel, "MBq")] + [InlineData("en-US", RadioactivityUnit.Megacurie, "MCi")] + [InlineData("en-US", RadioactivityUnit.Megarutherford, "MRd")] + [InlineData("en-US", RadioactivityUnit.Microbecquerel, "µBq")] + [InlineData("en-US", RadioactivityUnit.Microcurie, "µCi")] + [InlineData("en-US", RadioactivityUnit.Microrutherford, "µRd")] + [InlineData("en-US", RadioactivityUnit.Millibecquerel, "mBq")] + [InlineData("en-US", RadioactivityUnit.Millicurie, "mCi")] + [InlineData("en-US", RadioactivityUnit.Millirutherford, "mRd")] + [InlineData("en-US", RadioactivityUnit.Nanobecquerel, "nBq")] + [InlineData("en-US", RadioactivityUnit.Nanocurie, "nCi")] + [InlineData("en-US", RadioactivityUnit.Nanorutherford, "nRd")] + [InlineData("en-US", RadioactivityUnit.Petabecquerel, "PBq")] + [InlineData("en-US", RadioactivityUnit.Picobecquerel, "pBq")] + [InlineData("en-US", RadioactivityUnit.Picocurie, "pCi")] + [InlineData("en-US", RadioactivityUnit.Picorutherford, "pRd")] + [InlineData("en-US", RadioactivityUnit.Rutherford, "Rd")] + [InlineData("en-US", RadioactivityUnit.Terabecquerel, "TBq")] + [InlineData("en-US", RadioactivityUnit.Teracurie, "TCi")] + [InlineData("en-US", RadioactivityUnit.Terarutherford, "TRd")] + [InlineData("ru-RU", RadioactivityUnit.Becquerel, "Бк")] + [InlineData("ru-RU", RadioactivityUnit.Curie, "Ки")] + [InlineData("ru-RU", RadioactivityUnit.Exabecquerel, "ЭБк")] + [InlineData("ru-RU", RadioactivityUnit.Gigabecquerel, "ГБк")] + [InlineData("ru-RU", RadioactivityUnit.Gigacurie, "ГКи")] + [InlineData("ru-RU", RadioactivityUnit.Gigarutherford, "ГРд")] + [InlineData("ru-RU", RadioactivityUnit.Kilobecquerel, "кБк")] + [InlineData("ru-RU", RadioactivityUnit.Kilocurie, "кКи")] + [InlineData("ru-RU", RadioactivityUnit.Kilorutherford, "кРд")] + [InlineData("ru-RU", RadioactivityUnit.Megabecquerel, "МБк")] + [InlineData("ru-RU", RadioactivityUnit.Megacurie, "МКи")] + [InlineData("ru-RU", RadioactivityUnit.Megarutherford, "МРд")] + [InlineData("ru-RU", RadioactivityUnit.Microbecquerel, "мкБк")] + [InlineData("ru-RU", RadioactivityUnit.Microcurie, "мкКи")] + [InlineData("ru-RU", RadioactivityUnit.Microrutherford, "мкРд")] + [InlineData("ru-RU", RadioactivityUnit.Millibecquerel, "мБк")] + [InlineData("ru-RU", RadioactivityUnit.Millicurie, "мКи")] + [InlineData("ru-RU", RadioactivityUnit.Millirutherford, "мРд")] + [InlineData("ru-RU", RadioactivityUnit.Nanobecquerel, "нБк")] + [InlineData("ru-RU", RadioactivityUnit.Nanocurie, "нКи")] + [InlineData("ru-RU", RadioactivityUnit.Nanorutherford, "нРд")] + [InlineData("ru-RU", RadioactivityUnit.Petabecquerel, "ПБк")] + [InlineData("ru-RU", RadioactivityUnit.Picobecquerel, "пБк")] + [InlineData("ru-RU", RadioactivityUnit.Picocurie, "пКи")] + [InlineData("ru-RU", RadioactivityUnit.Picorutherford, "пРд")] + [InlineData("ru-RU", RadioactivityUnit.Rutherford, "Рд")] + [InlineData("ru-RU", RadioactivityUnit.Terabecquerel, "ТБк")] + [InlineData("ru-RU", RadioactivityUnit.Teracurie, "ТКи")] + [InlineData("ru-RU", RadioactivityUnit.Terarutherford, "ТРд")] + public void GetAbbreviationForCulture(string culture, RadioactivityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Radioactivity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Radioactivity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Radioactivity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RadioactivityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 47f810742e..aed88ff418 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -276,40 +276,26 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 /s", RatioChangeRateUnit.DecimalFractionPerSecond, 4.2)] + [InlineData("en-US", "4.2 %/s", RatioChangeRateUnit.PercentPerSecond, 4.2)] + public void Parse(string culture, string quantityString, RatioChangeRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = RatioChangeRate.Parse("1 /s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); - Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RatioChangeRate.Parse("1 %/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PercentsPerSecond, PercentsPerSecondTolerance); - Assert.Equal(RatioChangeRateUnit.PercentPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RatioChangeRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 /s", RatioChangeRateUnit.DecimalFractionPerSecond, 4.2)] + [InlineData("en-US", "4.2 %/s", RatioChangeRateUnit.PercentPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, RatioChangeRateUnit expectedUnit, double expectedValue) { - { - Assert.True(RatioChangeRate.TryParse("1 /s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); - Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, parsed.Unit); - } - - { - Assert.True(RatioChangeRate.TryParse("1 %/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PercentsPerSecond, PercentsPerSecondTolerance); - Assert.Equal(RatioChangeRateUnit.PercentPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RatioChangeRate.TryParse(quantityString, out RatioChangeRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -394,6 +380,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, RatioC Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RatioChangeRateUnit.DecimalFractionPerSecond, "/s")] + [InlineData("en-US", RatioChangeRateUnit.PercentPerSecond, "%/s")] + public void GetAbbreviationForCulture(string culture, RatioChangeRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RatioChangeRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RatioChangeRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RatioChangeRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RatioChangeRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index 3b7470c5db..744ceefc7a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -240,92 +240,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ", RatioUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 ppb", RatioUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", RatioUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", RatioUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", RatioUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", RatioUnit.Percent, 4.2)] + public void Parse(string culture, string quantityString, RatioUnit expectedUnit, double expectedValue) { - try - { - var parsed = Ratio.Parse("1 ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(RatioUnit.DecimalFraction, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Ratio.Parse("1 ppb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(RatioUnit.PartPerBillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Ratio.Parse("1 ppm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(RatioUnit.PartPerMillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Ratio.Parse("1 ‰", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(RatioUnit.PartPerThousand, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Ratio.Parse("1 ppt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(RatioUnit.PartPerTrillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Ratio.Parse("1 %", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(RatioUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Ratio.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 ", RatioUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 ppb", RatioUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", RatioUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", RatioUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", RatioUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", RatioUnit.Percent, 4.2)] + public void TryParse(string culture, string quantityString, RatioUnit expectedUnit, double expectedValue) { - { - Assert.True(Ratio.TryParse("1 ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(RatioUnit.DecimalFraction, parsed.Unit); - } - - { - Assert.True(Ratio.TryParse("1 ppb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(RatioUnit.PartPerBillion, parsed.Unit); - } - - { - Assert.True(Ratio.TryParse("1 ppm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(RatioUnit.PartPerMillion, parsed.Unit); - } - - { - Assert.True(Ratio.TryParse("1 ‰", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(RatioUnit.PartPerThousand, parsed.Unit); - } - - { - Assert.True(Ratio.TryParse("1 ppt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(RatioUnit.PartPerTrillion, parsed.Unit); - } - - { - Assert.True(Ratio.TryParse("1 %", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(RatioUnit.Percent, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Ratio.TryParse(quantityString, out Ratio parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -442,6 +384,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, RatioU Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RatioUnit.DecimalFraction, "")] + [InlineData("en-US", RatioUnit.PartPerBillion, "ppb")] + [InlineData("en-US", RatioUnit.PartPerMillion, "ppm")] + [InlineData("en-US", RatioUnit.PartPerThousand, "‰")] + [InlineData("en-US", RatioUnit.PartPerTrillion, "ppt")] + [InlineData("en-US", RatioUnit.Percent, "%")] + public void GetAbbreviationForCulture(string culture, RatioUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Ratio.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Ratio.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Ratio.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RatioUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index 75279040e6..c2462462a2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -330,157 +330,44 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft⁻²", ReciprocalAreaUnit.InverseSquareFoot, 4.2)] + [InlineData("en-US", "4.2 in⁻²", ReciprocalAreaUnit.InverseSquareInch, 4.2)] + [InlineData("en-US", "4.2 km⁻²", ReciprocalAreaUnit.InverseSquareKilometer, 4.2)] + [InlineData("en-US", "4.2 m⁻²", ReciprocalAreaUnit.InverseSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi⁻²", ReciprocalAreaUnit.InverseSquareMile, 4.2)] + [InlineData("en-US", "4.2 mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 yd⁻²", ReciprocalAreaUnit.InverseSquareYard, 4.2)] + [InlineData("en-US", "4.2 ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot, 4.2)] + public void Parse(string culture, string quantityString, ReciprocalAreaUnit expectedUnit, double expectedValue) { - try - { - var parsed = ReciprocalArea.Parse("1 cm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareCentimeters, InverseSquareCentimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 dm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareDecimeters, InverseSquareDecimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 ft⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareFeet, InverseSquareFeetTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 in⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareInches, InverseSquareInchesTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 km⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareKilometers, InverseSquareKilometersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 m⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareMeters, InverseSquareMetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 µm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareMicrometers, InverseSquareMicrometersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 mi⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareMiles, InverseSquareMilesTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 mm⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareMillimeters, InverseSquareMillimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 yd⁻²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseSquareYards, InverseSquareYardsTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalArea.Parse("1 ft⁻² (US)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveySquareFeet, InverseUsSurveySquareFeetTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseUsSurveySquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ReciprocalArea.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft⁻²", ReciprocalAreaUnit.InverseSquareFoot, 4.2)] + [InlineData("en-US", "4.2 in⁻²", ReciprocalAreaUnit.InverseSquareInch, 4.2)] + [InlineData("en-US", "4.2 km⁻²", ReciprocalAreaUnit.InverseSquareKilometer, 4.2)] + [InlineData("en-US", "4.2 m⁻²", ReciprocalAreaUnit.InverseSquareMeter, 4.2)] + [InlineData("en-US", "4.2 µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi⁻²", ReciprocalAreaUnit.InverseSquareMile, 4.2)] + [InlineData("en-US", "4.2 mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter, 4.2)] + [InlineData("en-US", "4.2 yd⁻²", ReciprocalAreaUnit.InverseSquareYard, 4.2)] + [InlineData("en-US", "4.2 ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot, 4.2)] + public void TryParse(string culture, string quantityString, ReciprocalAreaUnit expectedUnit, double expectedValue) { - { - Assert.True(ReciprocalArea.TryParse("1 cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareCentimeters, InverseSquareCentimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareCentimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 dm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareDecimeters, InverseSquareDecimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareDecimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 ft⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareFeet, InverseSquareFeetTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareFoot, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 in⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareInches, InverseSquareInchesTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareInch, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 km⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareKilometers, InverseSquareKilometersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareKilometer, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareMeters, InverseSquareMetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMeter, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 µm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareMicrometers, InverseSquareMicrometersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMicrometer, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 mi⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareMiles, InverseSquareMilesTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMile, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareMillimeters, InverseSquareMillimetersTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMillimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 yd⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseSquareYards, InverseSquareYardsTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseSquareYard, parsed.Unit); - } - - { - Assert.True(ReciprocalArea.TryParse("1 ft⁻² (US)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveySquareFeet, InverseUsSurveySquareFeetTolerance); - Assert.Equal(ReciprocalAreaUnit.InverseUsSurveySquareFoot, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ReciprocalArea.TryParse(quantityString, out ReciprocalArea parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -637,6 +524,37 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Recipr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareCentimeter, "cm⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareDecimeter, "dm⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareFoot, "ft⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareInch, "in⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareKilometer, "km⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareMeter, "m⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareMicrometer, "µm⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareMile, "mi⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareMillimeter, "mm⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseSquareYard, "yd⁻²")] + [InlineData("en-US", ReciprocalAreaUnit.InverseUsSurveySquareFoot, "ft⁻² (US)")] + public void GetAbbreviationForCulture(string culture, ReciprocalAreaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ReciprocalArea.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ReciprocalArea.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ReciprocalArea.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ReciprocalAreaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 71527c32b3..81d689bfdb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -324,274 +324,62 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm⁻¹", ReciprocalLengthUnit.InverseCentimeter, 4.2)] + [InlineData("en-US", "4.2 1/cm", ReciprocalLengthUnit.InverseCentimeter, 4.2)] + [InlineData("en-US", "4.2 ft⁻¹", ReciprocalLengthUnit.InverseFoot, 4.2)] + [InlineData("en-US", "4.2 1/ft", ReciprocalLengthUnit.InverseFoot, 4.2)] + [InlineData("en-US", "4.2 in⁻¹", ReciprocalLengthUnit.InverseInch, 4.2)] + [InlineData("en-US", "4.2 1/in", ReciprocalLengthUnit.InverseInch, 4.2)] + [InlineData("en-US", "4.2 m⁻¹", ReciprocalLengthUnit.InverseMeter, 4.2)] + [InlineData("en-US", "4.2 1/m", ReciprocalLengthUnit.InverseMeter, 4.2)] + [InlineData("en-US", "4.2 µin⁻¹", ReciprocalLengthUnit.InverseMicroinch, 4.2)] + [InlineData("en-US", "4.2 1/µin", ReciprocalLengthUnit.InverseMicroinch, 4.2)] + [InlineData("en-US", "4.2 mil⁻¹", ReciprocalLengthUnit.InverseMil, 4.2)] + [InlineData("en-US", "4.2 1/mil", ReciprocalLengthUnit.InverseMil, 4.2)] + [InlineData("en-US", "4.2 mi⁻¹", ReciprocalLengthUnit.InverseMile, 4.2)] + [InlineData("en-US", "4.2 1/mi", ReciprocalLengthUnit.InverseMile, 4.2)] + [InlineData("en-US", "4.2 mm⁻¹", ReciprocalLengthUnit.InverseMillimeter, 4.2)] + [InlineData("en-US", "4.2 1/mm", ReciprocalLengthUnit.InverseMillimeter, 4.2)] + [InlineData("en-US", "4.2 ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 yd⁻¹", ReciprocalLengthUnit.InverseYard, 4.2)] + [InlineData("en-US", "4.2 1/yd", ReciprocalLengthUnit.InverseYard, 4.2)] + public void Parse(string culture, string quantityString, ReciprocalLengthUnit expectedUnit, double expectedValue) { - try - { - var parsed = ReciprocalLength.Parse("1 cm⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseCentimeters, InverseCentimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseCentimeters, InverseCentimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 ft⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseFeet, InverseFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseFeet, InverseFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 in⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseInches, InverseInchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseInches, InverseInchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 m⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMeters, InverseMetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMeters, InverseMetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 µin⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMicroinches, InverseMicroinchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/µin", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMicroinches, InverseMicroinchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 mil⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMils, InverseMilsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/mil", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMils, InverseMilsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 mi⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMiles, InverseMilesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/mi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMiles, InverseMilesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 mm⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMillimeters, InverseMillimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseMillimeters, InverseMillimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 ftUS⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/ftUS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 yd⁻¹", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseYards, InverseYardsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReciprocalLength.Parse("1 1/yd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InverseYards, InverseYardsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ReciprocalLength.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm⁻¹", ReciprocalLengthUnit.InverseCentimeter, 4.2)] + [InlineData("en-US", "4.2 1/cm", ReciprocalLengthUnit.InverseCentimeter, 4.2)] + [InlineData("en-US", "4.2 ft⁻¹", ReciprocalLengthUnit.InverseFoot, 4.2)] + [InlineData("en-US", "4.2 1/ft", ReciprocalLengthUnit.InverseFoot, 4.2)] + [InlineData("en-US", "4.2 in⁻¹", ReciprocalLengthUnit.InverseInch, 4.2)] + [InlineData("en-US", "4.2 1/in", ReciprocalLengthUnit.InverseInch, 4.2)] + [InlineData("en-US", "4.2 m⁻¹", ReciprocalLengthUnit.InverseMeter, 4.2)] + [InlineData("en-US", "4.2 1/m", ReciprocalLengthUnit.InverseMeter, 4.2)] + [InlineData("en-US", "4.2 µin⁻¹", ReciprocalLengthUnit.InverseMicroinch, 4.2)] + [InlineData("en-US", "4.2 1/µin", ReciprocalLengthUnit.InverseMicroinch, 4.2)] + [InlineData("en-US", "4.2 mil⁻¹", ReciprocalLengthUnit.InverseMil, 4.2)] + [InlineData("en-US", "4.2 1/mil", ReciprocalLengthUnit.InverseMil, 4.2)] + [InlineData("en-US", "4.2 mi⁻¹", ReciprocalLengthUnit.InverseMile, 4.2)] + [InlineData("en-US", "4.2 1/mi", ReciprocalLengthUnit.InverseMile, 4.2)] + [InlineData("en-US", "4.2 mm⁻¹", ReciprocalLengthUnit.InverseMillimeter, 4.2)] + [InlineData("en-US", "4.2 1/mm", ReciprocalLengthUnit.InverseMillimeter, 4.2)] + [InlineData("en-US", "4.2 ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 yd⁻¹", ReciprocalLengthUnit.InverseYard, 4.2)] + [InlineData("en-US", "4.2 1/yd", ReciprocalLengthUnit.InverseYard, 4.2)] + public void TryParse(string culture, string quantityString, ReciprocalLengthUnit expectedUnit, double expectedValue) { - { - Assert.True(ReciprocalLength.TryParse("1 cm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseCentimeters, InverseCentimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseCentimeters, InverseCentimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 ft⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseFeet, InverseFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseFeet, InverseFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 in⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseInches, InverseInchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseInches, InverseInchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 m⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMeters, InverseMetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMeters, InverseMetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 µin⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMicroinches, InverseMicroinchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/µin", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMicroinches, InverseMicroinchesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 mil⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMils, InverseMilsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/mil", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMils, InverseMilsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 mi⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMiles, InverseMilesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/mi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMiles, InverseMilesTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 mm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMillimeters, InverseMillimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseMillimeters, InverseMillimetersTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 ftUS⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseUsSurveyFeet, InverseUsSurveyFeetTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 yd⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseYards, InverseYardsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsed.Unit); - } - - { - Assert.True(ReciprocalLength.TryParse("1 1/yd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InverseYards, InverseYardsTolerance); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ReciprocalLength.TryParse(quantityString, out ReciprocalLength parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -820,6 +608,36 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Recipr Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ReciprocalLengthUnit.InverseCentimeter, "cm⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseFoot, "ft⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseInch, "in⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseMeter, "m⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseMicroinch, "µin⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseMil, "mil⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseMile, "mi⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseMillimeter, "mm⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseUsSurveyFoot, "ftUS⁻¹")] + [InlineData("en-US", ReciprocalLengthUnit.InverseYard, "yd⁻¹")] + public void GetAbbreviationForCulture(string culture, ReciprocalLengthUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ReciprocalLength.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ReciprocalLength.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ReciprocalLength.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ReciprocalLengthUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index 0247037b4f..783e880a87 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -210,27 +210,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 %RH", RelativeHumidityUnit.Percent, 4.2)] + public void Parse(string culture, string quantityString, RelativeHumidityUnit expectedUnit, double expectedValue) { - try - { - var parsed = RelativeHumidity.Parse("1 %RH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(RelativeHumidityUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RelativeHumidity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 %RH", RelativeHumidityUnit.Percent, 4.2)] + public void TryParse(string culture, string quantityString, RelativeHumidityUnit expectedUnit, double expectedValue) { - { - Assert.True(RelativeHumidity.TryParse("1 %RH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(RelativeHumidityUnit.Percent, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RelativeHumidity.TryParse(quantityString, out RelativeHumidity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -307,6 +304,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Relati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RelativeHumidityUnit.Percent, "%RH")] + public void GetAbbreviationForCulture(string culture, RelativeHumidityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RelativeHumidity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RelativeHumidity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RelativeHumidity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RelativeHumidityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index 55eb6c6e85..4d200f6852 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -288,79 +288,32 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 °/s²", RotationalAccelerationUnit.DegreePerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond, 4.2)] + [InlineData("en-US", "4.2 r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared, 4.2)] + public void Parse(string culture, string quantityString, RotationalAccelerationUnit expectedUnit, double expectedValue) { - try - { - var parsed = RotationalAcceleration.Parse("1 °/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalAcceleration.Parse("1 deg/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalAcceleration.Parse("1 rad/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.RadianPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalAcceleration.Parse("1 rpm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinutePerSecond, RevolutionsPerMinutePerSecondTolerance); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalAcceleration.Parse("1 r/s²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecondSquared, RevolutionsPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerSecondSquared, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RotationalAcceleration.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 °/s²", RotationalAccelerationUnit.DegreePerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared, 4.2)] + [InlineData("en-US", "4.2 rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond, 4.2)] + [InlineData("en-US", "4.2 r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared, 4.2)] + public void TryParse(string culture, string quantityString, RotationalAccelerationUnit expectedUnit, double expectedValue) { - { - Assert.True(RotationalAcceleration.TryParse("1 °/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsed.Unit); - } - - { - Assert.True(RotationalAcceleration.TryParse("1 deg/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsed.Unit); - } - - { - Assert.True(RotationalAcceleration.TryParse("1 rad/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.RadianPerSecondSquared, parsed.Unit); - } - - { - Assert.True(RotationalAcceleration.TryParse("1 rpm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinutePerSecond, RevolutionsPerMinutePerSecondTolerance); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalAcceleration.TryParse("1 r/s²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecondSquared, RevolutionsPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerSecondSquared, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RotationalAcceleration.TryParse(quantityString, out RotationalAcceleration parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -469,6 +422,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Rotati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RotationalAccelerationUnit.DegreePerSecondSquared, "°/s²")] + [InlineData("en-US", RotationalAccelerationUnit.RadianPerSecondSquared, "rad/s²")] + [InlineData("en-US", RotationalAccelerationUnit.RevolutionPerMinutePerSecond, "rpm/s")] + [InlineData("en-US", RotationalAccelerationUnit.RevolutionPerSecondSquared, "r/s²")] + public void GetAbbreviationForCulture(string culture, RotationalAccelerationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RotationalAcceleration.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RotationalAcceleration.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RotationalAcceleration.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RotationalAccelerationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index de5ed90e7c..b8f8d94ecb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -342,417 +342,84 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 crad/s", RotationalSpeedUnit.CentiradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 drad/s", RotationalSpeedUnit.DeciradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 °/min", RotationalSpeedUnit.DegreePerMinute, 4.2)] + [InlineData("en-US", "4.2 deg/min", RotationalSpeedUnit.DegreePerMinute, 4.2)] + [InlineData("en-US", "4.2 °/s", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 deg/s", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µ°/s", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µrad/s", RotationalSpeedUnit.MicroradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 m°/s", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 mdeg/s", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 mrad/s", RotationalSpeedUnit.MilliradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 n°/s", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 ndeg/s", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 nrad/s", RotationalSpeedUnit.NanoradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 rad/s", RotationalSpeedUnit.RadianPerSecond, 4.2)] + [InlineData("en-US", "4.2 rpm", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("en-US", "4.2 r/min", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("en-US", "4.2 r/s", RotationalSpeedUnit.RevolutionPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 срад/с", RotationalSpeedUnit.CentiradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 драд/с", RotationalSpeedUnit.DeciradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 °/с", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мк°/с", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкрад/с", RotationalSpeedUnit.MicroradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 м°/с", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мрад/с", RotationalSpeedUnit.MilliradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 н°/с", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нрад/с", RotationalSpeedUnit.NanoradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 рад/с", RotationalSpeedUnit.RadianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 об/мин", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 об/с", RotationalSpeedUnit.RevolutionPerSecond, 4.2)] + public void Parse(string culture, string quantityString, RotationalSpeedUnit expectedUnit, double expectedValue) { - try - { - var parsed = RotationalSpeed.Parse("1 crad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentiradiansPerSecond, CentiradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 срад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentiradiansPerSecond, CentiradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 drad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciradiansPerSecond, DeciradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 драд/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DeciradiansPerSecond, DeciradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 °/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerMinute, DegreesPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 deg/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerMinute, DegreesPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 °/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 deg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 °/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 µ°/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 µdeg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 мк°/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 µrad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicroradiansPerSecond, MicroradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 мкрад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicroradiansPerSecond, MicroradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 m°/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 mdeg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 м°/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 mrad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliradiansPerSecond, MilliradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 мрад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilliradiansPerSecond, MilliradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 n°/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 ndeg/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 н°/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 nrad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanoradiansPerSecond, NanoradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 нрад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanoradiansPerSecond, NanoradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 rad/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 рад/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 rpm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 r/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 об/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 r/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecond, RevolutionsPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalSpeed.Parse("1 об/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecond, RevolutionsPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RotationalSpeed.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 crad/s", RotationalSpeedUnit.CentiradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 drad/s", RotationalSpeedUnit.DeciradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 °/min", RotationalSpeedUnit.DegreePerMinute, 4.2)] + [InlineData("en-US", "4.2 deg/min", RotationalSpeedUnit.DegreePerMinute, 4.2)] + [InlineData("en-US", "4.2 °/s", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 deg/s", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µ°/s", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 µrad/s", RotationalSpeedUnit.MicroradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 m°/s", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 mdeg/s", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 mrad/s", RotationalSpeedUnit.MilliradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 n°/s", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 ndeg/s", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("en-US", "4.2 nrad/s", RotationalSpeedUnit.NanoradianPerSecond, 4.2)] + [InlineData("en-US", "4.2 rad/s", RotationalSpeedUnit.RadianPerSecond, 4.2)] + [InlineData("en-US", "4.2 rpm", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("en-US", "4.2 r/min", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("en-US", "4.2 r/s", RotationalSpeedUnit.RevolutionPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 срад/с", RotationalSpeedUnit.CentiradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 драд/с", RotationalSpeedUnit.DeciradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 °/с", RotationalSpeedUnit.DegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мк°/с", RotationalSpeedUnit.MicrodegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкрад/с", RotationalSpeedUnit.MicroradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 м°/с", RotationalSpeedUnit.MillidegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мрад/с", RotationalSpeedUnit.MilliradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 н°/с", RotationalSpeedUnit.NanodegreePerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нрад/с", RotationalSpeedUnit.NanoradianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 рад/с", RotationalSpeedUnit.RadianPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 об/мин", RotationalSpeedUnit.RevolutionPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 об/с", RotationalSpeedUnit.RevolutionPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, RotationalSpeedUnit expectedUnit, double expectedValue) { - { - Assert.True(RotationalSpeed.TryParse("1 crad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentiradiansPerSecond, CentiradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 срад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentiradiansPerSecond, CentiradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 drad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciradiansPerSecond, DeciradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 драд/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciradiansPerSecond, DeciradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 °/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerMinute, DegreesPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 deg/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerMinute, DegreesPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 °/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 deg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 °/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesPerSecond, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 µ°/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 µdeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 мк°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 µrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicroradiansPerSecond, MicroradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 мкрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicroradiansPerSecond, MicroradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 m°/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 mdeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 м°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 mrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliradiansPerSecond, MilliradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 мрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilliradiansPerSecond, MilliradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 n°/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 ndeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 н°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 nrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanoradiansPerSecond, NanoradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 нрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanoradiansPerSecond, NanoradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 rad/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 рад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RadiansPerSecond, RadiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 rpm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 r/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 об/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 r/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecond, RevolutionsPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsed.Unit); - } - - { - Assert.True(RotationalSpeed.TryParse("1 об/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.RevolutionsPerSecond, RevolutionsPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RotationalSpeed.TryParse(quantityString, out RotationalSpeed parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1021,6 +688,51 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Rotati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RotationalSpeedUnit.CentiradianPerSecond, "crad/s")] + [InlineData("en-US", RotationalSpeedUnit.DeciradianPerSecond, "drad/s")] + [InlineData("en-US", RotationalSpeedUnit.DegreePerMinute, "°/min")] + [InlineData("en-US", RotationalSpeedUnit.DegreePerSecond, "°/s")] + [InlineData("en-US", RotationalSpeedUnit.MicrodegreePerSecond, "µ°/s")] + [InlineData("en-US", RotationalSpeedUnit.MicroradianPerSecond, "µrad/s")] + [InlineData("en-US", RotationalSpeedUnit.MillidegreePerSecond, "m°/s")] + [InlineData("en-US", RotationalSpeedUnit.MilliradianPerSecond, "mrad/s")] + [InlineData("en-US", RotationalSpeedUnit.NanodegreePerSecond, "n°/s")] + [InlineData("en-US", RotationalSpeedUnit.NanoradianPerSecond, "nrad/s")] + [InlineData("en-US", RotationalSpeedUnit.RadianPerSecond, "rad/s")] + [InlineData("en-US", RotationalSpeedUnit.RevolutionPerMinute, "rpm")] + [InlineData("en-US", RotationalSpeedUnit.RevolutionPerSecond, "r/s")] + [InlineData("ru-RU", RotationalSpeedUnit.CentiradianPerSecond, "срад/с")] + [InlineData("ru-RU", RotationalSpeedUnit.DeciradianPerSecond, "драд/с")] + [InlineData("ru-RU", RotationalSpeedUnit.DegreePerSecond, "°/с")] + [InlineData("ru-RU", RotationalSpeedUnit.MicrodegreePerSecond, "мк°/с")] + [InlineData("ru-RU", RotationalSpeedUnit.MicroradianPerSecond, "мкрад/с")] + [InlineData("ru-RU", RotationalSpeedUnit.MillidegreePerSecond, "м°/с")] + [InlineData("ru-RU", RotationalSpeedUnit.MilliradianPerSecond, "мрад/с")] + [InlineData("ru-RU", RotationalSpeedUnit.NanodegreePerSecond, "н°/с")] + [InlineData("ru-RU", RotationalSpeedUnit.NanoradianPerSecond, "нрад/с")] + [InlineData("ru-RU", RotationalSpeedUnit.RadianPerSecond, "рад/с")] + [InlineData("ru-RU", RotationalSpeedUnit.RevolutionPerMinute, "об/мин")] + [InlineData("ru-RU", RotationalSpeedUnit.RevolutionPerSecond, "об/с")] + public void GetAbbreviationForCulture(string culture, RotationalSpeedUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RotationalSpeed.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RotationalSpeed.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RotationalSpeed.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RotationalSpeedUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index c239519887..03a1e27fbe 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -294,183 +294,48 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, 4.2)] + public void Parse(string culture, string quantityString, RotationalStiffnessPerLengthUnit expectedUnit, double expectedValue) { - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kN·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kNm/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kipf·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kip·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 k·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kipf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 kip·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 k·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 MN·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 MNm/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 N·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 Nm/rad/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffnessPerLength.Parse("1 lbf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerDegreesPerFeet, PoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RotationalStiffnessPerLength.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, 4.2)] + [InlineData("en-US", "4.2 MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, 4.2)] + public void TryParse(string culture, string quantityString, RotationalStiffnessPerLengthUnit expectedUnit, double expectedValue) { - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kN·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kNm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kipf·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kip·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 k·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kipf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 kip·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 k·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegreesPerFeet, KilopoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 MN·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 MNm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 N·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 Nm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsed.Unit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParse("1 lbf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerDegreesPerFeet, PoundForceFeetPerDegreesPerFeetTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RotationalStiffnessPerLength.TryParse(quantityString, out RotationalStiffnessPerLength parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -643,6 +508,31 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Rotati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, "kN·m/rad/m")] + [InlineData("en-US", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, "kipf·ft/°/ft")] + [InlineData("en-US", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, "MN·m/rad/m")] + [InlineData("en-US", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, "N·m/rad/m")] + [InlineData("en-US", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, "lbf·ft/deg/ft")] + public void GetAbbreviationForCulture(string culture, RotationalStiffnessPerLengthUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RotationalStiffnessPerLength.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RotationalStiffnessPerLength.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RotationalStiffnessPerLength.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RotationalStiffnessPerLengthUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index e5eb99e701..39d6a56f2b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -462,1246 +462,230 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees, 4.2)] + public void Parse(string culture, string quantityString, RotationalStiffnessUnit expectedUnit, double expectedValue) { - try - { - var parsed = RotationalStiffness.Parse("1 cN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerRadian, CentinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 cNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerRadian, CentinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerRadian, DecanewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 daNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerRadian, DecanewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerRadian, DecinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 dNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerRadian, DecinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·m/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerRadian, KilonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerRadian, KilonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kipf·ft/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kip·ft/°g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 k·ft/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kipf·ft/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 kip·ft/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 k·ft/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerDegree, MeganewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerDegree, MeganewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerDegree, MeganewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerDegree, MeganewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·m/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerDegree, MeganewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerDegree, MeganewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerDegree, MeganewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerDegree, MeganewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerRadian, MeganewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 MNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimetersPerRadian, MeganewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerRadian, MicronewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 µNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerRadian, MicronewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMetersPerDegree, MillinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMetersPerDegree, MillinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMetersPerDegree, MillinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMetersPerDegree, MillinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerDegree, MillinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerDegree, MillinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerDegree, MillinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerDegree, MillinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerRadian, MillinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 mNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillinewtonMillimetersPerRadian, MillinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nN·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nNm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nN·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nNm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nNmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nN·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nNmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerRadian, NanonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 nNmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerRadian, NanonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·m/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·m/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·m/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·mm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nmm/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·mm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nmm/°", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 N·mm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerRadian, NewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 Nmm/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerRadian, NewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 lbf·ft/rad", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerRadian, PoundForceFeetPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.PoundForceFeetPerRadian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = RotationalStiffness.Parse("1 lbf·ft/deg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerDegrees, PoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.PoundForceFootPerDegrees, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = RotationalStiffness.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, 4.2)] + [InlineData("en-US", "4.2 MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree, 4.2)] + [InlineData("en-US", "4.2 N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian, 4.2)] + [InlineData("en-US", "4.2 lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees, 4.2)] + public void TryParse(string culture, string quantityString, RotationalStiffnessUnit expectedUnit, double expectedValue) { - { - Assert.True(RotationalStiffness.TryParse("1 cN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMetersPerDegree, CentinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerDegree, CentinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerRadian, CentinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 cNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentinewtonMillimetersPerRadian, CentinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMetersPerDegree, DecanewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerDegree, DecanewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerRadian, DecanewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 daNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecanewtonMillimetersPerRadian, DecanewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMetersPerDegree, DecinewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerDegree, DecinewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerRadian, DecinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 dNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecinewtonMillimetersPerRadian, DecinewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerDegree, KilonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerDegree, KilonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerRadian, KilonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimetersPerRadian, KilonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kipf·ft/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kip·ft/°g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 k·ft/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kipf·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 kip·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 k·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeetPerDegrees, KilopoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 MN·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 MNm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMetersPerDegree, MicronewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerDegree, MicronewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerRadian, MicronewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 µNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicronewtonMillimetersPerRadian, MicronewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMetersPerDegree, NanonewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerDegree, NanonewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerRadian, NanonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 nNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanonewtonMillimetersPerRadian, NanonewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerDegree, NewtonMetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerDegree, NewtonMillimetersPerDegreeTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 N·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerRadian, NewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 Nmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimetersPerRadian, NewtonMillimetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 lbf·ft/rad", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerRadian, PoundForceFeetPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.PoundForceFeetPerRadian, parsed.Unit); - } - - { - Assert.True(RotationalStiffness.TryParse("1 lbf·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceFeetPerDegrees, PoundForceFeetPerDegreesTolerance); - Assert.Equal(RotationalStiffnessUnit.PoundForceFootPerDegrees, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(RotationalStiffness.TryParse(quantityString, out RotationalStiffness parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -2602,6 +1586,59 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Rotati Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", RotationalStiffnessUnit.CentinewtonMeterPerDegree, "cN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, "cN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, "cN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.DecanewtonMeterPerDegree, "daN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, "daN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, "daN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.DecinewtonMeterPerDegree, "dN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, "dN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, "dN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.KilonewtonMeterPerDegree, "kN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.KilonewtonMeterPerRadian, "kN·m/rad")] + [InlineData("en-US", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, "kN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, "kN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.KilopoundForceFootPerDegrees, "kipf·ft/°")] + [InlineData("en-US", RotationalStiffnessUnit.MeganewtonMeterPerDegree, "MN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MeganewtonMeterPerRadian, "MN·m/rad")] + [InlineData("en-US", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, "MN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, "MN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.MicronewtonMeterPerDegree, "µN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, "µN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, "µN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.MillinewtonMeterPerDegree, "mN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, "mN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, "mN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.NanonewtonMeterPerDegree, "nN·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, "nN·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, "nN·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.NewtonMeterPerDegree, "N·m/deg")] + [InlineData("en-US", RotationalStiffnessUnit.NewtonMeterPerRadian, "N·m/rad")] + [InlineData("en-US", RotationalStiffnessUnit.NewtonMillimeterPerDegree, "N·mm/deg")] + [InlineData("en-US", RotationalStiffnessUnit.NewtonMillimeterPerRadian, "N·mm/rad")] + [InlineData("en-US", RotationalStiffnessUnit.PoundForceFeetPerRadian, "lbf·ft/rad")] + [InlineData("en-US", RotationalStiffnessUnit.PoundForceFootPerDegrees, "lbf·ft/deg")] + public void GetAbbreviationForCulture(string culture, RotationalStiffnessUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = RotationalStiffness.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(RotationalStiffness.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = RotationalStiffness.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(RotationalStiffnessUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index bcebfcd1ed..46c05ade74 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -210,27 +210,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ", ScalarUnit.Amount, 4.2)] + public void Parse(string culture, string quantityString, ScalarUnit expectedUnit, double expectedValue) { - try - { - var parsed = Scalar.Parse("1 ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Amount, AmountTolerance); - Assert.Equal(ScalarUnit.Amount, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Scalar.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 ", ScalarUnit.Amount, 4.2)] + public void TryParse(string culture, string quantityString, ScalarUnit expectedUnit, double expectedValue) { - { - Assert.True(Scalar.TryParse("1 ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Amount, AmountTolerance); - Assert.Equal(ScalarUnit.Amount, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Scalar.TryParse(quantityString, out Scalar parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -307,6 +304,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Scalar Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ScalarUnit.Amount, "")] + public void GetAbbreviationForCulture(string culture, ScalarUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Scalar.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Scalar.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Scalar.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ScalarUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index 933cef403c..f62697f344 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -210,27 +210,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 sr", SolidAngleUnit.Steradian, 4.2)] + public void Parse(string culture, string quantityString, SolidAngleUnit expectedUnit, double expectedValue) { - try - { - var parsed = SolidAngle.Parse("1 sr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Steradians, SteradiansTolerance); - Assert.Equal(SolidAngleUnit.Steradian, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SolidAngle.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 sr", SolidAngleUnit.Steradian, 4.2)] + public void TryParse(string culture, string quantityString, SolidAngleUnit expectedUnit, double expectedValue) { - { - Assert.True(SolidAngle.TryParse("1 sr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Steradians, SteradiansTolerance); - Assert.Equal(SolidAngleUnit.Steradian, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SolidAngle.TryParse(quantityString, out SolidAngle parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -307,6 +304,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, SolidA Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SolidAngleUnit.Steradian, "sr")] + public void GetAbbreviationForCulture(string culture, SolidAngleUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SolidAngle.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SolidAngle.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SolidAngle.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SolidAngleUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index e2ccddbb53..a0560e5b83 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -444,404 +444,82 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 btu/lb", SpecificEnergyUnit.BtuPerPound, 4.2)] + [InlineData("en-US", "4.2 cal/g", SpecificEnergyUnit.CaloriePerGram, 4.2)] + [InlineData("en-US", "4.2 GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 GWd/t", SpecificEnergyUnit.GigawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 J/kg", SpecificEnergyUnit.JoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 kcal/g", SpecificEnergyUnit.KilocaloriePerGram, 4.2)] + [InlineData("en-US", "4.2 kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 kWd/t", SpecificEnergyUnit.KilowattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 MJ/t", SpecificEnergyUnit.MegaJoulePerTonne, 4.2)] + [InlineData("en-US", "4.2 MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 MWd/t", SpecificEnergyUnit.MegawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 TWd/t", SpecificEnergyUnit.TerawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 Wd/kg", SpecificEnergyUnit.WattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 Wd/ST", SpecificEnergyUnit.WattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 Wd/t", SpecificEnergyUnit.WattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 Wh/kg", SpecificEnergyUnit.WattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 Wh/lbs", SpecificEnergyUnit.WattHourPerPound, 4.2)] + public void Parse(string culture, string quantityString, SpecificEnergyUnit expectedUnit, double expectedValue) { - try - { - var parsed = SpecificEnergy.Parse("1 btu/lb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtuPerPound, BtuPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.BtuPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 cal/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CaloriesPerGram, CaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.CaloriePerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 GWd/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerKilogram, GigawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 GWd/ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerShortTon, GigawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 GWd/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerTonne, GigawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 GWh/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilogram, GigawattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 GWh/lbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerPound, GigawattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 J/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogram, JoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.JoulePerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kcal/g", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerGram, KilocaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.KilocaloriePerGram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kJ/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilojoulePerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kWd/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerKilogram, KilowattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kWd/ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerShortTon, KilowattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kWd/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerTonne, KilowattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kWh/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 kWh/lbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerPound, KilowattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MJ/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegajoulePerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MJ/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaJoulesPerTonne, MegaJoulesPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.MegaJoulePerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MWd/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerKilogram, MegawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MWd/ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerShortTon, MegawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MWd/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerTonne, MegawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MWh/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 MWh/lbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerPound, MegawattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 TWd/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerKilogram, TerawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 TWd/ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerShortTon, TerawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 TWd/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerTonne, TerawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 Wd/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattDaysPerKilogram, WattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 Wd/ST", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattDaysPerShortTon, WattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerShortTon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 Wd/t", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattDaysPerTonne, WattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerTonne, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 Wh/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattHoursPerKilogram, WattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEnergy.Parse("1 Wh/lbs", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattHoursPerPound, WattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.WattHourPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SpecificEnergy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 btu/lb", SpecificEnergyUnit.BtuPerPound, 4.2)] + [InlineData("en-US", "4.2 cal/g", SpecificEnergyUnit.CaloriePerGram, 4.2)] + [InlineData("en-US", "4.2 GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 GWd/t", SpecificEnergyUnit.GigawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 J/kg", SpecificEnergyUnit.JoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 kcal/g", SpecificEnergyUnit.KilocaloriePerGram, 4.2)] + [InlineData("en-US", "4.2 kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 kWd/t", SpecificEnergyUnit.KilowattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram, 4.2)] + [InlineData("en-US", "4.2 MJ/t", SpecificEnergyUnit.MegaJoulePerTonne, 4.2)] + [InlineData("en-US", "4.2 MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 MWd/t", SpecificEnergyUnit.MegawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound, 4.2)] + [InlineData("en-US", "4.2 TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 TWd/t", SpecificEnergyUnit.TerawattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 Wd/kg", SpecificEnergyUnit.WattDayPerKilogram, 4.2)] + [InlineData("en-US", "4.2 Wd/ST", SpecificEnergyUnit.WattDayPerShortTon, 4.2)] + [InlineData("en-US", "4.2 Wd/t", SpecificEnergyUnit.WattDayPerTonne, 4.2)] + [InlineData("en-US", "4.2 Wh/kg", SpecificEnergyUnit.WattHourPerKilogram, 4.2)] + [InlineData("en-US", "4.2 Wh/lbs", SpecificEnergyUnit.WattHourPerPound, 4.2)] + public void TryParse(string culture, string quantityString, SpecificEnergyUnit expectedUnit, double expectedValue) { - { - Assert.True(SpecificEnergy.TryParse("1 btu/lb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtuPerPound, BtuPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.BtuPerPound, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 cal/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CaloriesPerGram, CaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.CaloriePerGram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 GWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerKilogram, GigawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 GWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerShortTon, GigawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerShortTon, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 GWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattDaysPerTonne, GigawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 GWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilogram, GigawattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 GWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerPound, GigawattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerPound, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 J/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogram, JoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.JoulePerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kcal/g", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerGram, KilocaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.KilocaloriePerGram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kJ/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilojoulePerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerKilogram, KilowattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerShortTon, KilowattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerShortTon, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattDaysPerTonne, KilowattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 kWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilowattHoursPerPound, KilowattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerPound, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MJ/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegajoulePerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MJ/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaJoulesPerTonne, MegaJoulesPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.MegaJoulePerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerKilogram, MegawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerShortTon, MegawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerShortTon, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattDaysPerTonne, MegawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 MWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerPound, MegawattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerPound, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 TWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerKilogram, TerawattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 TWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerShortTon, TerawattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerShortTon, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 TWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TerawattDaysPerTonne, TerawattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 Wd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattDaysPerKilogram, WattDaysPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 Wd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattDaysPerShortTon, WattDaysPerShortTonTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerShortTon, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 Wd/t", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattDaysPerTonne, WattDaysPerTonneTolerance); - Assert.Equal(SpecificEnergyUnit.WattDayPerTonne, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 Wh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHoursPerKilogram, WattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificEnergy.TryParse("1 Wh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattHoursPerPound, WattHoursPerPoundTolerance); - Assert.Equal(SpecificEnergyUnit.WattHourPerPound, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SpecificEnergy.TryParse(quantityString, out SpecificEnergy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1150,6 +828,56 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Specif Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpecificEnergyUnit.BtuPerPound, "btu/lb")] + [InlineData("en-US", SpecificEnergyUnit.CaloriePerGram, "cal/g")] + [InlineData("en-US", SpecificEnergyUnit.GigawattDayPerKilogram, "GWd/kg")] + [InlineData("en-US", SpecificEnergyUnit.GigawattDayPerShortTon, "GWd/ST")] + [InlineData("en-US", SpecificEnergyUnit.GigawattDayPerTonne, "GWd/t")] + [InlineData("en-US", SpecificEnergyUnit.GigawattHourPerKilogram, "GWh/kg")] + [InlineData("en-US", SpecificEnergyUnit.GigawattHourPerPound, "GWh/lbs")] + [InlineData("en-US", SpecificEnergyUnit.JoulePerKilogram, "J/kg")] + [InlineData("en-US", SpecificEnergyUnit.KilocaloriePerGram, "kcal/g")] + [InlineData("en-US", SpecificEnergyUnit.KilojoulePerKilogram, "kJ/kg")] + [InlineData("en-US", SpecificEnergyUnit.KilowattDayPerKilogram, "kWd/kg")] + [InlineData("en-US", SpecificEnergyUnit.KilowattDayPerShortTon, "kWd/ST")] + [InlineData("en-US", SpecificEnergyUnit.KilowattDayPerTonne, "kWd/t")] + [InlineData("en-US", SpecificEnergyUnit.KilowattHourPerKilogram, "kWh/kg")] + [InlineData("en-US", SpecificEnergyUnit.KilowattHourPerPound, "kWh/lbs")] + [InlineData("en-US", SpecificEnergyUnit.MegajoulePerKilogram, "MJ/kg")] + [InlineData("en-US", SpecificEnergyUnit.MegaJoulePerTonne, "MJ/t")] + [InlineData("en-US", SpecificEnergyUnit.MegawattDayPerKilogram, "MWd/kg")] + [InlineData("en-US", SpecificEnergyUnit.MegawattDayPerShortTon, "MWd/ST")] + [InlineData("en-US", SpecificEnergyUnit.MegawattDayPerTonne, "MWd/t")] + [InlineData("en-US", SpecificEnergyUnit.MegawattHourPerKilogram, "MWh/kg")] + [InlineData("en-US", SpecificEnergyUnit.MegawattHourPerPound, "MWh/lbs")] + [InlineData("en-US", SpecificEnergyUnit.TerawattDayPerKilogram, "TWd/kg")] + [InlineData("en-US", SpecificEnergyUnit.TerawattDayPerShortTon, "TWd/ST")] + [InlineData("en-US", SpecificEnergyUnit.TerawattDayPerTonne, "TWd/t")] + [InlineData("en-US", SpecificEnergyUnit.WattDayPerKilogram, "Wd/kg")] + [InlineData("en-US", SpecificEnergyUnit.WattDayPerShortTon, "Wd/ST")] + [InlineData("en-US", SpecificEnergyUnit.WattDayPerTonne, "Wd/t")] + [InlineData("en-US", SpecificEnergyUnit.WattHourPerKilogram, "Wh/kg")] + [InlineData("en-US", SpecificEnergyUnit.WattHourPerPound, "Wh/lbs")] + public void GetAbbreviationForCulture(string culture, SpecificEnergyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SpecificEnergy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SpecificEnergy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SpecificEnergy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpecificEnergyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index ce64e278eb..87325ee874 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -318,144 +318,42 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit, 4.2)] + [InlineData("en-US", "4.2 BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit, 4.2)] + [InlineData("en-US", "4.2 cal/g·K", SpecificEntropyUnit.CaloriePerGramKelvin, 4.2)] + [InlineData("en-US", "4.2 J/kg·°C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/kg·K", SpecificEntropyUnit.JoulePerKilogramKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/g·K", SpecificEntropyUnit.KilocaloriePerGramKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/kg·°C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/kg·K", SpecificEntropyUnit.KilojoulePerKilogramKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/kg·°C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 MJ/kg·K", SpecificEntropyUnit.MegajoulePerKilogramKelvin, 4.2)] + public void Parse(string culture, string quantityString, SpecificEntropyUnit expectedUnit, double expectedValue) { - try - { - var parsed = SpecificEntropy.Parse("1 BTU/(lb·°F)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerPoundFahrenheit, BtusPerPoundFahrenheitTolerance); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 BTU/(lbm·°F)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerPoundFahrenheit, BtusPerPoundFahrenheitTolerance); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 cal/g·K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.CaloriePerGramKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 J/kg·°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 J/kg·K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 kcal/g·K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilocaloriePerGramKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 kJ/kg·°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 kJ/kg·K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 MJ/kg·°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificEntropy.Parse("1 MJ/kg·K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SpecificEntropy.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit, 4.2)] + [InlineData("en-US", "4.2 BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit, 4.2)] + [InlineData("en-US", "4.2 cal/g·K", SpecificEntropyUnit.CaloriePerGramKelvin, 4.2)] + [InlineData("en-US", "4.2 J/kg·°C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/kg·K", SpecificEntropyUnit.JoulePerKilogramKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/g·K", SpecificEntropyUnit.KilocaloriePerGramKelvin, 4.2)] + [InlineData("en-US", "4.2 kJ/kg·°C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/kg·K", SpecificEntropyUnit.KilojoulePerKilogramKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/kg·°C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 MJ/kg·K", SpecificEntropyUnit.MegajoulePerKilogramKelvin, 4.2)] + public void TryParse(string culture, string quantityString, SpecificEntropyUnit expectedUnit, double expectedValue) { - { - Assert.True(SpecificEntropy.TryParse("1 BTU/(lb·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerPoundFahrenheit, BtusPerPoundFahrenheitTolerance); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 BTU/(lbm·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerPoundFahrenheit, BtusPerPoundFahrenheitTolerance); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 cal/g·K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.CaloriePerGramKelvin, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 J/kg·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 J/kg·K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramKelvin, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 kcal/g·K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilocaloriePerGramKelvin, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 kJ/kg·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 kJ/kg·K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramKelvin, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 MJ/kg·°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, parsed.Unit); - } - - { - Assert.True(SpecificEntropy.TryParse("1 MJ/kg·K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SpecificEntropy.TryParse(quantityString, out SpecificEntropy parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -604,6 +502,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Specif Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpecificEntropyUnit.BtuPerPoundFahrenheit, "BTU/(lb·°F)")] + [InlineData("en-US", SpecificEntropyUnit.CaloriePerGramKelvin, "cal/g·K")] + [InlineData("en-US", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, "J/kg·°C")] + [InlineData("en-US", SpecificEntropyUnit.JoulePerKilogramKelvin, "J/kg·K")] + [InlineData("en-US", SpecificEntropyUnit.KilocaloriePerGramKelvin, "kcal/g·K")] + [InlineData("en-US", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, "kJ/kg·°C")] + [InlineData("en-US", SpecificEntropyUnit.KilojoulePerKilogramKelvin, "kJ/kg·K")] + [InlineData("en-US", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, "MJ/kg·°C")] + [InlineData("en-US", SpecificEntropyUnit.MegajoulePerKilogramKelvin, "MJ/kg·K")] + public void GetAbbreviationForCulture(string culture, SpecificEntropyUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SpecificEntropy.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SpecificEntropy.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SpecificEntropy.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpecificEntropyUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index 8136517f8b..29d2f133c3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -288,66 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 g/(kN·s)", SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 kg/(kgf·h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, 4.2)] + [InlineData("en-US", "4.2 kg/(kN·s)", SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, 4.2)] + public void Parse(string culture, string quantityString, SpecificFuelConsumptionUnit expectedUnit, double expectedValue) { - try - { - var parsed = SpecificFuelConsumption.Parse("1 g/(kN·s)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramsPerKilonewtonSecond, GramsPerKilonewtonSecondTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificFuelConsumption.Parse("1 kg/(kgf·h)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilogramForceHour, KilogramsPerKilogramForceHourTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificFuelConsumption.Parse("1 kg/(kN·s)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilonewtonSecond, KilogramsPerKilonewtonSecondTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificFuelConsumption.Parse("1 lb/(lbf·h)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsMassPerPoundForceHour, PoundsMassPerPoundForceHourTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SpecificFuelConsumption.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 g/(kN·s)", SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 kg/(kgf·h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, 4.2)] + [InlineData("en-US", "4.2 kg/(kN·s)", SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, 4.2)] + [InlineData("en-US", "4.2 lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, 4.2)] + public void TryParse(string culture, string quantityString, SpecificFuelConsumptionUnit expectedUnit, double expectedValue) { - { - Assert.True(SpecificFuelConsumption.TryParse("1 g/(kN·s)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramsPerKilonewtonSecond, GramsPerKilonewtonSecondTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, parsed.Unit); - } - - { - Assert.True(SpecificFuelConsumption.TryParse("1 kg/(kgf·h)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilogramForceHour, KilogramsPerKilogramForceHourTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, parsed.Unit); - } - - { - Assert.True(SpecificFuelConsumption.TryParse("1 kg/(kN·s)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsPerKilonewtonSecond, KilogramsPerKilonewtonSecondTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, parsed.Unit); - } - - { - Assert.True(SpecificFuelConsumption.TryParse("1 lb/(lbf·h)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsMassPerPoundForceHour, PoundsMassPerPoundForceHourTolerance); - Assert.Equal(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SpecificFuelConsumption.TryParse(quantityString, out SpecificFuelConsumption parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -448,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Specif Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, "g/(kN·s)")] + [InlineData("en-US", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, "kg/(kgf·h)")] + [InlineData("en-US", SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, "kg/(kN·s)")] + [InlineData("en-US", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, "lb/(lbf·h)")] + public void GetAbbreviationForCulture(string culture, SpecificFuelConsumptionUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SpecificFuelConsumption.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SpecificFuelConsumption.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SpecificFuelConsumption.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpecificFuelConsumptionUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 21fca738a8..d7284056ad 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -282,53 +282,28 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ft³/lb", SpecificVolumeUnit.CubicFootPerPound, 4.2)] + [InlineData("en-US", "4.2 m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram, 4.2)] + public void Parse(string culture, string quantityString, SpecificVolumeUnit expectedUnit, double expectedValue) { - try - { - var parsed = SpecificVolume.Parse("1 ft³/lb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerPound, CubicFeetPerPoundTolerance); - Assert.Equal(SpecificVolumeUnit.CubicFootPerPound, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificVolume.Parse("1 m³/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - Assert.Equal(SpecificVolumeUnit.CubicMeterPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificVolume.Parse("1 mm³/kg", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillicubicMetersPerKilogram, MillicubicMetersPerKilogramTolerance); - Assert.Equal(SpecificVolumeUnit.MillicubicMeterPerKilogram, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SpecificVolume.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 ft³/lb", SpecificVolumeUnit.CubicFootPerPound, 4.2)] + [InlineData("en-US", "4.2 m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram, 4.2)] + [InlineData("en-US", "4.2 mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram, 4.2)] + public void TryParse(string culture, string quantityString, SpecificVolumeUnit expectedUnit, double expectedValue) { - { - Assert.True(SpecificVolume.TryParse("1 ft³/lb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerPound, CubicFeetPerPoundTolerance); - Assert.Equal(SpecificVolumeUnit.CubicFootPerPound, parsed.Unit); - } - - { - Assert.True(SpecificVolume.TryParse("1 m³/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - Assert.Equal(SpecificVolumeUnit.CubicMeterPerKilogram, parsed.Unit); - } - - { - Assert.True(SpecificVolume.TryParse("1 mm³/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillicubicMetersPerKilogram, MillicubicMetersPerKilogramTolerance); - Assert.Equal(SpecificVolumeUnit.MillicubicMeterPerKilogram, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SpecificVolume.TryParse(quantityString, out SpecificVolume parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -421,6 +396,29 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Specif Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpecificVolumeUnit.CubicFootPerPound, "ft³/lb")] + [InlineData("en-US", SpecificVolumeUnit.CubicMeterPerKilogram, "m³/kg")] + [InlineData("en-US", SpecificVolumeUnit.MillicubicMeterPerKilogram, "mm³/kg")] + public void GetAbbreviationForCulture(string culture, SpecificVolumeUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SpecificVolume.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SpecificVolume.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SpecificVolume.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpecificVolumeUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index 8592f82928..59c2d03c7e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -366,235 +366,56 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m³", SpecificWeightUnit.NewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter, 4.2)] + public void Parse(string culture, string quantityString, SpecificWeightUnit expectedUnit, double expectedValue) { - try - { - var parsed = SpecificWeight.Parse("1 kgf/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicCentimeter, KilogramsForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kgf/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicMeter, KilogramsForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kgf/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicMillimeter, KilogramsForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kN/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicCentimeter, KilonewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kN/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicMeter, KilonewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kN/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kipf/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 kipf/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 MN/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.MeganewtonPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 N/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 N/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 N/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 lbf/ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerCubicFoot, PoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 lbf/in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerCubicInch, PoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 tf/cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicCentimeter, TonnesForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 tf/m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicMeter, TonnesForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = SpecificWeight.Parse("1 tf/mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicMillimeter, TonnesForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = SpecificWeight.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 N/m³", SpecificWeightUnit.NewtonPerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot, 4.2)] + [InlineData("en-US", "4.2 lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch, 4.2)] + [InlineData("en-US", "4.2 tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter, 4.2)] + [InlineData("en-US", "4.2 tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter, 4.2)] + public void TryParse(string culture, string quantityString, SpecificWeightUnit expectedUnit, double expectedValue) { - { - Assert.True(SpecificWeight.TryParse("1 kgf/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicCentimeter, KilogramsForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kgf/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicMeter, KilogramsForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kgf/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramsForcePerCubicMillimeter, KilogramsForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kN/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicCentimeter, KilonewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kN/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicMeter, KilonewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kN/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kipf/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicFoot, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 kipf/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicInch, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 MN/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.MeganewtonPerCubicMeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 N/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 N/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 N/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMillimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 lbf/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerCubicFoot, PoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicFoot, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 lbf/in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundsForcePerCubicInch, PoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicInch, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 tf/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicCentimeter, TonnesForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicCentimeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 tf/m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicMeter, TonnesForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMeter, parsed.Unit); - } - - { - Assert.True(SpecificWeight.TryParse("1 tf/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonnesForcePerCubicMillimeter, TonnesForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(SpecificWeight.TryParse(quantityString, out SpecificWeight parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -799,6 +620,43 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Specif Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpecificWeightUnit.KilogramForcePerCubicCentimeter, "kgf/cm³")] + [InlineData("en-US", SpecificWeightUnit.KilogramForcePerCubicMeter, "kgf/m³")] + [InlineData("en-US", SpecificWeightUnit.KilogramForcePerCubicMillimeter, "kgf/mm³")] + [InlineData("en-US", SpecificWeightUnit.KilonewtonPerCubicCentimeter, "kN/cm³")] + [InlineData("en-US", SpecificWeightUnit.KilonewtonPerCubicMeter, "kN/m³")] + [InlineData("en-US", SpecificWeightUnit.KilonewtonPerCubicMillimeter, "kN/mm³")] + [InlineData("en-US", SpecificWeightUnit.KilopoundForcePerCubicFoot, "kipf/ft³")] + [InlineData("en-US", SpecificWeightUnit.KilopoundForcePerCubicInch, "kipf/in³")] + [InlineData("en-US", SpecificWeightUnit.MeganewtonPerCubicMeter, "MN/m³")] + [InlineData("en-US", SpecificWeightUnit.NewtonPerCubicCentimeter, "N/cm³")] + [InlineData("en-US", SpecificWeightUnit.NewtonPerCubicMeter, "N/m³")] + [InlineData("en-US", SpecificWeightUnit.NewtonPerCubicMillimeter, "N/mm³")] + [InlineData("en-US", SpecificWeightUnit.PoundForcePerCubicFoot, "lbf/ft³")] + [InlineData("en-US", SpecificWeightUnit.PoundForcePerCubicInch, "lbf/in³")] + [InlineData("en-US", SpecificWeightUnit.TonneForcePerCubicCentimeter, "tf/cm³")] + [InlineData("en-US", SpecificWeightUnit.TonneForcePerCubicMeter, "tf/m³")] + [InlineData("en-US", SpecificWeightUnit.TonneForcePerCubicMillimeter, "tf/mm³")] + public void GetAbbreviationForCulture(string culture, SpecificWeightUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = SpecificWeight.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(SpecificWeight.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = SpecificWeight.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpecificWeightUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index d6aa17db2c..c6578aaa8f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -462,833 +462,148 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm/h", SpeedUnit.CentimeterPerHour, 4.2)] + [InlineData("en-US", "4.2 cm/min", SpeedUnit.CentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cm/s", SpeedUnit.CentimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dm/min", SpeedUnit.DecimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dm/s", SpeedUnit.DecimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 ft/h", SpeedUnit.FootPerHour, 4.2)] + [InlineData("en-US", "4.2 ft/min", SpeedUnit.FootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft/s", SpeedUnit.FootPerSecond, 4.2)] + [InlineData("en-US", "4.2 in/h", SpeedUnit.InchPerHour, 4.2)] + [InlineData("en-US", "4.2 in/min", SpeedUnit.InchPerMinute, 4.2)] + [InlineData("en-US", "4.2 in/s", SpeedUnit.InchPerSecond, 4.2)] + [InlineData("en-US", "4.2 km/h", SpeedUnit.KilometerPerHour, 4.2)] + [InlineData("en-US", "4.2 km/min", SpeedUnit.KilometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 km/s", SpeedUnit.KilometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 kn", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 kt", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 knot", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 knots", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 M", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 Ma", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 MN", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 MACH", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 m/h", SpeedUnit.MeterPerHour, 4.2)] + [InlineData("en-US", "4.2 m/min", SpeedUnit.MeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 m/s", SpeedUnit.MeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 µm/min", SpeedUnit.MicrometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 µm/s", SpeedUnit.MicrometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 mph", SpeedUnit.MilePerHour, 4.2)] + [InlineData("en-US", "4.2 mm/h", SpeedUnit.MillimeterPerHour, 4.2)] + [InlineData("en-US", "4.2 mm/min", SpeedUnit.MillimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 mm/s", SpeedUnit.MillimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 nm/min", SpeedUnit.NanometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 nm/s", SpeedUnit.NanometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 ftUS/h", SpeedUnit.UsSurveyFootPerHour, 4.2)] + [InlineData("en-US", "4.2 ftUS/min", SpeedUnit.UsSurveyFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ftUS/s", SpeedUnit.UsSurveyFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 yd/h", SpeedUnit.YardPerHour, 4.2)] + [InlineData("en-US", "4.2 yd/min", SpeedUnit.YardPerMinute, 4.2)] + [InlineData("en-US", "4.2 yd/s", SpeedUnit.YardPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см/ч", SpeedUnit.CentimeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 см/мин", SpeedUnit.CentimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 см/с", SpeedUnit.CentimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дм/мин", SpeedUnit.DecimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дм/с", SpeedUnit.DecimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 фут/ч", SpeedUnit.FootPerHour, 4.2)] + [InlineData("ru-RU", "4,2 фут/мин", SpeedUnit.FootPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 фут/с", SpeedUnit.FootPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 км/ч", SpeedUnit.KilometerPerHour, 4.2)] + [InlineData("ru-RU", "4,2 км/мин", SpeedUnit.KilometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 км/с", SpeedUnit.KilometerPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 уз.", SpeedUnit.Knot, 4.2)] + [InlineData("ru-RU", "4,2 мах", SpeedUnit.Mach, 4.2)] + [InlineData("ru-RU", "4,2 м/ч", SpeedUnit.MeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 м/мин", SpeedUnit.MeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м/с", SpeedUnit.MeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкм/мин", SpeedUnit.MicrometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с", SpeedUnit.MicrometerPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 миль/ч", SpeedUnit.MilePerHour, 4.2)] + [InlineData("ru-RU", "4,2 мм/ч", SpeedUnit.MillimeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мм/мин", SpeedUnit.MillimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мм/с", SpeedUnit.MillimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нм/мин", SpeedUnit.NanometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 нм/с", SpeedUnit.NanometerPerSecond, 4.2)] + public void Parse(string culture, string quantityString, SpeedUnit expectedUnit, double expectedValue) { - try - { - var parsed = Speed.Parse("1 cm/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerHour, CentimetersPerHourTolerance); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 см/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerHour, CentimetersPerHourTolerance); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 cm/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerMinute, CentimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 см/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerMinute, CentimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 cm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecond, CentimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 см/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecond, CentimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 dm/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerMinute, DecimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 дм/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerMinute, DecimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 dm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecond, DecimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 дм/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecond, DecimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ft/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetPerHour, FeetPerHourTolerance); - Assert.Equal(SpeedUnit.FootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 фут/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.FeetPerHour, FeetPerHourTolerance); - Assert.Equal(SpeedUnit.FootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ft/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetPerMinute, FeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.FootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 фут/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.FeetPerMinute, FeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.FootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ft/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecond, FeetPerSecondTolerance); - Assert.Equal(SpeedUnit.FootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 фут/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.FeetPerSecond, FeetPerSecondTolerance); - Assert.Equal(SpeedUnit.FootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 in/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesPerHour, InchesPerHourTolerance); - Assert.Equal(SpeedUnit.InchPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 in/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesPerMinute, InchesPerMinuteTolerance); - Assert.Equal(SpeedUnit.InchPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 in/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesPerSecond, InchesPerSecondTolerance); - Assert.Equal(SpeedUnit.InchPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 km/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerHour, KilometersPerHourTolerance); - Assert.Equal(SpeedUnit.KilometerPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 км/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilometersPerHour, KilometersPerHourTolerance); - Assert.Equal(SpeedUnit.KilometerPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 km/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerMinute, KilometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 км/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilometersPerMinute, KilometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 km/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecond, KilometersPerSecondTolerance); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 км/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecond, KilometersPerSecondTolerance); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 kn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 kt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 knot", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 knots", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 уз.", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 M", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 Ma", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 MN", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 MACH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мах", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 m/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersPerHour, MetersPerHourTolerance); - Assert.Equal(SpeedUnit.MeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 м/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MetersPerHour, MetersPerHourTolerance); - Assert.Equal(SpeedUnit.MeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 m/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersPerMinute, MetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 м/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MetersPerMinute, MetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 m/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecond, MetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 м/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MetersPerSecond, MetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 µm/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerMinute, MicrometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мкм/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerMinute, MicrometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 µm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecond, MicrometersPerSecondTolerance); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мкм/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecond, MicrometersPerSecondTolerance); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 mph", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilesPerHour, MilesPerHourTolerance); - Assert.Equal(SpeedUnit.MilePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 миль/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MilesPerHour, MilesPerHourTolerance); - Assert.Equal(SpeedUnit.MilePerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 mm/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerHour, MillimetersPerHourTolerance); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мм/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerHour, MillimetersPerHourTolerance); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 mm/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerMinute, MillimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мм/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerMinute, MillimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 mm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecond, MillimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 мм/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecond, MillimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 nm/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanometersPerMinute, NanometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 нм/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanometersPerMinute, NanometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 nm/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecond, NanometersPerSecondTolerance); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 нм/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecond, NanometersPerSecondTolerance); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ftUS/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerHour, UsSurveyFeetPerHourTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ftUS/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerMinute, UsSurveyFeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 ftUS/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerSecond, UsSurveyFeetPerSecondTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 yd/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.YardsPerHour, YardsPerHourTolerance); - Assert.Equal(SpeedUnit.YardPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 yd/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.YardsPerMinute, YardsPerMinuteTolerance); - Assert.Equal(SpeedUnit.YardPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Speed.Parse("1 yd/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.YardsPerSecond, YardsPerSecondTolerance); - Assert.Equal(SpeedUnit.YardPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Speed.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm/h", SpeedUnit.CentimeterPerHour, 4.2)] + [InlineData("en-US", "4.2 cm/min", SpeedUnit.CentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cm/s", SpeedUnit.CentimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dm/min", SpeedUnit.DecimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dm/s", SpeedUnit.DecimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 ft/h", SpeedUnit.FootPerHour, 4.2)] + [InlineData("en-US", "4.2 ft/min", SpeedUnit.FootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft/s", SpeedUnit.FootPerSecond, 4.2)] + [InlineData("en-US", "4.2 in/h", SpeedUnit.InchPerHour, 4.2)] + [InlineData("en-US", "4.2 in/min", SpeedUnit.InchPerMinute, 4.2)] + [InlineData("en-US", "4.2 in/s", SpeedUnit.InchPerSecond, 4.2)] + [InlineData("en-US", "4.2 km/h", SpeedUnit.KilometerPerHour, 4.2)] + [InlineData("en-US", "4.2 km/min", SpeedUnit.KilometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 km/s", SpeedUnit.KilometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 kn", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 kt", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 knot", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 knots", SpeedUnit.Knot, 4.2)] + [InlineData("en-US", "4.2 M", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 Ma", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 MN", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 MACH", SpeedUnit.Mach, 4.2)] + [InlineData("en-US", "4.2 m/h", SpeedUnit.MeterPerHour, 4.2)] + [InlineData("en-US", "4.2 m/min", SpeedUnit.MeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 m/s", SpeedUnit.MeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 µm/min", SpeedUnit.MicrometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 µm/s", SpeedUnit.MicrometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 mph", SpeedUnit.MilePerHour, 4.2)] + [InlineData("en-US", "4.2 mm/h", SpeedUnit.MillimeterPerHour, 4.2)] + [InlineData("en-US", "4.2 mm/min", SpeedUnit.MillimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 mm/s", SpeedUnit.MillimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 nm/min", SpeedUnit.NanometerPerMinute, 4.2)] + [InlineData("en-US", "4.2 nm/s", SpeedUnit.NanometerPerSecond, 4.2)] + [InlineData("en-US", "4.2 ftUS/h", SpeedUnit.UsSurveyFootPerHour, 4.2)] + [InlineData("en-US", "4.2 ftUS/min", SpeedUnit.UsSurveyFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ftUS/s", SpeedUnit.UsSurveyFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 yd/h", SpeedUnit.YardPerHour, 4.2)] + [InlineData("en-US", "4.2 yd/min", SpeedUnit.YardPerMinute, 4.2)] + [InlineData("en-US", "4.2 yd/s", SpeedUnit.YardPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см/ч", SpeedUnit.CentimeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 см/мин", SpeedUnit.CentimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 см/с", SpeedUnit.CentimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дм/мин", SpeedUnit.DecimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дм/с", SpeedUnit.DecimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 фут/ч", SpeedUnit.FootPerHour, 4.2)] + [InlineData("ru-RU", "4,2 фут/мин", SpeedUnit.FootPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 фут/с", SpeedUnit.FootPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 км/ч", SpeedUnit.KilometerPerHour, 4.2)] + [InlineData("ru-RU", "4,2 км/мин", SpeedUnit.KilometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 км/с", SpeedUnit.KilometerPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 уз.", SpeedUnit.Knot, 4.2)] + [InlineData("ru-RU", "4,2 мах", SpeedUnit.Mach, 4.2)] + [InlineData("ru-RU", "4,2 м/ч", SpeedUnit.MeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 м/мин", SpeedUnit.MeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м/с", SpeedUnit.MeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкм/мин", SpeedUnit.MicrometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мкм/с", SpeedUnit.MicrometerPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 миль/ч", SpeedUnit.MilePerHour, 4.2)] + [InlineData("ru-RU", "4,2 мм/ч", SpeedUnit.MillimeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мм/мин", SpeedUnit.MillimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мм/с", SpeedUnit.MillimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нм/мин", SpeedUnit.NanometerPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 нм/с", SpeedUnit.NanometerPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, SpeedUnit expectedUnit, double expectedValue) { - { - Assert.True(Speed.TryParse("1 cm/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerHour, CentimetersPerHourTolerance); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 см/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerHour, CentimetersPerHourTolerance); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 cm/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerMinute, CentimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 см/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerMinute, CentimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 cm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecond, CentimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 см/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersPerSecond, CentimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 dm/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerMinute, DecimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 дм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerMinute, DecimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 dm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecond, DecimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 дм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersPerSecond, DecimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ft/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerHour, FeetPerHourTolerance); - Assert.Equal(SpeedUnit.FootPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 фут/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerHour, FeetPerHourTolerance); - Assert.Equal(SpeedUnit.FootPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ft/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerMinute, FeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.FootPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 фут/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerMinute, FeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.FootPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecond, FeetPerSecondTolerance); - Assert.Equal(SpeedUnit.FootPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 фут/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetPerSecond, FeetPerSecondTolerance); - Assert.Equal(SpeedUnit.FootPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 in/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerHour, InchesPerHourTolerance); - Assert.Equal(SpeedUnit.InchPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 in/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerMinute, InchesPerMinuteTolerance); - Assert.Equal(SpeedUnit.InchPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 in/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesPerSecond, InchesPerSecondTolerance); - Assert.Equal(SpeedUnit.InchPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 km/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerHour, KilometersPerHourTolerance); - Assert.Equal(SpeedUnit.KilometerPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 км/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerHour, KilometersPerHourTolerance); - Assert.Equal(SpeedUnit.KilometerPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 km/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerMinute, KilometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 км/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerMinute, KilometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 km/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecond, KilometersPerSecondTolerance); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 км/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilometersPerSecond, KilometersPerSecondTolerance); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 kn", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 kt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 knot", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 knots", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 уз.", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Knots, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 M", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 Ma", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 MN", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 MACH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мах", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Mach, MachTolerance); - Assert.Equal(SpeedUnit.Mach, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 m/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerHour, MetersPerHourTolerance); - Assert.Equal(SpeedUnit.MeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 м/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerHour, MetersPerHourTolerance); - Assert.Equal(SpeedUnit.MeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 m/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerMinute, MetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 м/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerMinute, MetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 m/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecond, MetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 м/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersPerSecond, MetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 µm/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerMinute, MicrometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мкм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerMinute, MicrometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 µm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecond, MicrometersPerSecondTolerance); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мкм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrometersPerSecond, MicrometersPerSecondTolerance); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 mph", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilesPerHour, MilesPerHourTolerance); - Assert.Equal(SpeedUnit.MilePerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 миль/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MilesPerHour, MilesPerHourTolerance); - Assert.Equal(SpeedUnit.MilePerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 mm/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerHour, MillimetersPerHourTolerance); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мм/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerHour, MillimetersPerHourTolerance); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 mm/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerMinute, MillimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerMinute, MillimetersPerMinuteTolerance); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 mm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecond, MillimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 мм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersPerSecond, MillimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 nm/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerMinute, NanometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 нм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerMinute, NanometersPerMinuteTolerance); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 nm/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecond, NanometersPerSecondTolerance); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 нм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanometersPerSecond, NanometersPerSecondTolerance); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ftUS/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerHour, UsSurveyFeetPerHourTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ftUS/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerMinute, UsSurveyFeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 ftUS/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsSurveyFeetPerSecond, UsSurveyFeetPerSecondTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerSecond, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 yd/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.YardsPerHour, YardsPerHourTolerance); - Assert.Equal(SpeedUnit.YardPerHour, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 yd/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.YardsPerMinute, YardsPerMinuteTolerance); - Assert.Equal(SpeedUnit.YardPerMinute, parsed.Unit); - } - - { - Assert.True(Speed.TryParse("1 yd/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.YardsPerSecond, YardsPerSecondTolerance); - Assert.Equal(SpeedUnit.YardPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Speed.TryParse(quantityString, out Speed parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1765,6 +1080,83 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, SpeedU Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", SpeedUnit.CentimeterPerHour, "cm/h")] + [InlineData("en-US", SpeedUnit.CentimeterPerMinute, "cm/min")] + [InlineData("en-US", SpeedUnit.CentimeterPerSecond, "cm/s")] + [InlineData("en-US", SpeedUnit.DecimeterPerMinute, "dm/min")] + [InlineData("en-US", SpeedUnit.DecimeterPerSecond, "dm/s")] + [InlineData("en-US", SpeedUnit.FootPerHour, "ft/h")] + [InlineData("en-US", SpeedUnit.FootPerMinute, "ft/min")] + [InlineData("en-US", SpeedUnit.FootPerSecond, "ft/s")] + [InlineData("en-US", SpeedUnit.InchPerHour, "in/h")] + [InlineData("en-US", SpeedUnit.InchPerMinute, "in/min")] + [InlineData("en-US", SpeedUnit.InchPerSecond, "in/s")] + [InlineData("en-US", SpeedUnit.KilometerPerHour, "km/h")] + [InlineData("en-US", SpeedUnit.KilometerPerMinute, "km/min")] + [InlineData("en-US", SpeedUnit.KilometerPerSecond, "km/s")] + [InlineData("en-US", SpeedUnit.Knot, "kn")] + [InlineData("en-US", SpeedUnit.Mach, "M")] + [InlineData("en-US", SpeedUnit.MeterPerHour, "m/h")] + [InlineData("en-US", SpeedUnit.MeterPerMinute, "m/min")] + [InlineData("en-US", SpeedUnit.MeterPerSecond, "m/s")] + [InlineData("en-US", SpeedUnit.MicrometerPerMinute, "µm/min")] + [InlineData("en-US", SpeedUnit.MicrometerPerSecond, "µm/s")] + [InlineData("en-US", SpeedUnit.MilePerHour, "mph")] + [InlineData("en-US", SpeedUnit.MillimeterPerHour, "mm/h")] + [InlineData("en-US", SpeedUnit.MillimeterPerMinute, "mm/min")] + [InlineData("en-US", SpeedUnit.MillimeterPerSecond, "mm/s")] + [InlineData("en-US", SpeedUnit.NanometerPerMinute, "nm/min")] + [InlineData("en-US", SpeedUnit.NanometerPerSecond, "nm/s")] + [InlineData("en-US", SpeedUnit.UsSurveyFootPerHour, "ftUS/h")] + [InlineData("en-US", SpeedUnit.UsSurveyFootPerMinute, "ftUS/min")] + [InlineData("en-US", SpeedUnit.UsSurveyFootPerSecond, "ftUS/s")] + [InlineData("en-US", SpeedUnit.YardPerHour, "yd/h")] + [InlineData("en-US", SpeedUnit.YardPerMinute, "yd/min")] + [InlineData("en-US", SpeedUnit.YardPerSecond, "yd/s")] + [InlineData("ru-RU", SpeedUnit.CentimeterPerHour, "см/ч")] + [InlineData("ru-RU", SpeedUnit.CentimeterPerMinute, "см/мин")] + [InlineData("ru-RU", SpeedUnit.CentimeterPerSecond, "см/с")] + [InlineData("ru-RU", SpeedUnit.DecimeterPerMinute, "дм/мин")] + [InlineData("ru-RU", SpeedUnit.DecimeterPerSecond, "дм/с")] + [InlineData("ru-RU", SpeedUnit.FootPerHour, "фут/ч")] + [InlineData("ru-RU", SpeedUnit.FootPerMinute, "фут/мин")] + [InlineData("ru-RU", SpeedUnit.FootPerSecond, "фут/с")] + [InlineData("ru-RU", SpeedUnit.KilometerPerHour, "км/ч")] + [InlineData("ru-RU", SpeedUnit.KilometerPerMinute, "км/мин")] + [InlineData("ru-RU", SpeedUnit.KilometerPerSecond, "км/с")] + [InlineData("ru-RU", SpeedUnit.Knot, "уз.")] + [InlineData("ru-RU", SpeedUnit.Mach, "мах")] + [InlineData("ru-RU", SpeedUnit.MeterPerHour, "м/ч")] + [InlineData("ru-RU", SpeedUnit.MeterPerMinute, "м/мин")] + [InlineData("ru-RU", SpeedUnit.MeterPerSecond, "м/с")] + [InlineData("ru-RU", SpeedUnit.MicrometerPerMinute, "мкм/мин")] + [InlineData("ru-RU", SpeedUnit.MicrometerPerSecond, "мкм/с")] + [InlineData("ru-RU", SpeedUnit.MilePerHour, "миль/ч")] + [InlineData("ru-RU", SpeedUnit.MillimeterPerHour, "мм/ч")] + [InlineData("ru-RU", SpeedUnit.MillimeterPerMinute, "мм/мин")] + [InlineData("ru-RU", SpeedUnit.MillimeterPerSecond, "мм/с")] + [InlineData("ru-RU", SpeedUnit.NanometerPerMinute, "нм/мин")] + [InlineData("ru-RU", SpeedUnit.NanometerPerSecond, "нм/с")] + public void GetAbbreviationForCulture(string culture, SpeedUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Speed.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Speed.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Speed.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(SpeedUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index dfea248899..690e0edaf4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay, 4.2)] + [InlineData("en-US", "4.2 Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour, 4.2)] + [InlineData("en-US", "4.2 Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 slm", StandardVolumeFlowUnit.StandardLiterPerMinute, 4.2)] + public void Parse(string culture, string quantityString, StandardVolumeFlowUnit expectedUnit, double expectedValue) { - try - { - var parsed = StandardVolumeFlow.Parse("1 sccm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicCentimetersPerMinute, StandardCubicCentimetersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 scfh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerHour, StandardCubicFeetPerHourTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 scfm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerMinute, StandardCubicFeetPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 Sft³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerSecond, StandardCubicFeetPerSecondTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 Sm³/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerDay, StandardCubicMetersPerDayTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 Sm³/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerHour, StandardCubicMetersPerHourTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 Sm³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerMinute, StandardCubicMetersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 Sm³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerSecond, StandardCubicMetersPerSecondTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = StandardVolumeFlow.Parse("1 slm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.StandardLitersPerMinute, StandardLitersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardLiterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = StandardVolumeFlow.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay, 4.2)] + [InlineData("en-US", "4.2 Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour, 4.2)] + [InlineData("en-US", "4.2 Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 slm", StandardVolumeFlowUnit.StandardLiterPerMinute, 4.2)] + public void TryParse(string culture, string quantityString, StandardVolumeFlowUnit expectedUnit, double expectedValue) { - { - Assert.True(StandardVolumeFlow.TryParse("1 sccm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicCentimetersPerMinute, StandardCubicCentimetersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 scfh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerHour, StandardCubicFeetPerHourTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerHour, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 scfm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerMinute, StandardCubicFeetPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerMinute, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 Sft³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicFeetPerSecond, StandardCubicFeetPerSecondTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerSecond, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 Sm³/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerDay, StandardCubicMetersPerDayTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerDay, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 Sm³/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerHour, StandardCubicMetersPerHourTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerHour, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 Sm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerMinute, StandardCubicMetersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 Sm³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardCubicMetersPerSecond, StandardCubicMetersPerSecondTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, parsed.Unit); - } - - { - Assert.True(StandardVolumeFlow.TryParse("1 slm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.StandardLitersPerMinute, StandardLitersPerMinuteTolerance); - Assert.Equal(StandardVolumeFlowUnit.StandardLiterPerMinute, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(StandardVolumeFlow.TryParse(quantityString, out StandardVolumeFlow parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Standa Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, "sccm")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicFootPerHour, "scfh")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicFootPerMinute, "scfm")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicFootPerSecond, "Sft³/s")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicMeterPerDay, "Sm³/d")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicMeterPerHour, "Sm³/h")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicMeterPerMinute, "Sm³/min")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardCubicMeterPerSecond, "Sm³/s")] + [InlineData("en-US", StandardVolumeFlowUnit.StandardLiterPerMinute, "slm")] + public void GetAbbreviationForCulture(string culture, StandardVolumeFlowUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = StandardVolumeFlow.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(StandardVolumeFlow.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = StandardVolumeFlow.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(StandardVolumeFlowUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index eb2583e2ca..a7f6f173df 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -366,235 +366,56 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 °C/h", TemperatureChangeRateUnit.DegreeCelsiusPerHour, 4.2)] + [InlineData("en-US", "4.2 °C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute, 4.2)] + [InlineData("en-US", "4.2 °C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 °F/h", TemperatureChangeRateUnit.DegreeFahrenheitPerHour, 4.2)] + [InlineData("en-US", "4.2 °F/min", TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, 4.2)] + [InlineData("en-US", "4.2 °F/s", TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, 4.2)] + [InlineData("en-US", "4.2 K/h", TemperatureChangeRateUnit.DegreeKelvinPerHour, 4.2)] + [InlineData("en-US", "4.2 K/min", TemperatureChangeRateUnit.DegreeKelvinPerMinute, 4.2)] + [InlineData("en-US", "4.2 K/s", TemperatureChangeRateUnit.DegreeKelvinPerSecond, 4.2)] + [InlineData("en-US", "4.2 h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, 4.2)] + public void Parse(string culture, string quantityString, TemperatureChangeRateUnit expectedUnit, double expectedValue) { - try - { - var parsed = TemperatureChangeRate.Parse("1 c°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 da°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 d°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °C/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerHour, DegreesCelsiusPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °C/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerMinute, DegreesCelsiusPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °F/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerHour, DegreesFahrenheitPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °F/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerMinute, DegreesFahrenheitPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 °F/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerSecond, DegreesFahrenheitPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 K/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerHour, DegreesKelvinPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 K/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerMinute, DegreesKelvinPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 K/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerSecond, DegreesKelvinPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 h°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 k°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 µ°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 m°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureChangeRate.Parse("1 n°C/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = TemperatureChangeRate.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 °C/h", TemperatureChangeRateUnit.DegreeCelsiusPerHour, 4.2)] + [InlineData("en-US", "4.2 °C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute, 4.2)] + [InlineData("en-US", "4.2 °C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 °F/h", TemperatureChangeRateUnit.DegreeFahrenheitPerHour, 4.2)] + [InlineData("en-US", "4.2 °F/min", TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, 4.2)] + [InlineData("en-US", "4.2 °F/s", TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, 4.2)] + [InlineData("en-US", "4.2 K/h", TemperatureChangeRateUnit.DegreeKelvinPerHour, 4.2)] + [InlineData("en-US", "4.2 K/min", TemperatureChangeRateUnit.DegreeKelvinPerMinute, 4.2)] + [InlineData("en-US", "4.2 K/s", TemperatureChangeRateUnit.DegreeKelvinPerSecond, 4.2)] + [InlineData("en-US", "4.2 h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, 4.2)] + [InlineData("en-US", "4.2 n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, TemperatureChangeRateUnit expectedUnit, double expectedValue) { - { - Assert.True(TemperatureChangeRate.TryParse("1 c°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 da°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 d°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °C/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerHour, DegreesCelsiusPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerHour, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °C/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerMinute, DegreesCelsiusPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °F/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerHour, DegreesFahrenheitPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerHour, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °F/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerMinute, DegreesFahrenheitPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 °F/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerSecond, DegreesFahrenheitPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 K/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerHour, DegreesKelvinPerHourTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerHour, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 K/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerMinute, DegreesKelvinPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerMinute, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 K/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesKelvinPerSecond, DegreesKelvinPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeKelvinPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 h°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 k°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 µ°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 m°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, parsed.Unit); - } - - { - Assert.True(TemperatureChangeRate.TryParse("1 n°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(TemperatureChangeRate.TryParse(quantityString, out TemperatureChangeRate parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -799,6 +620,43 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Temper Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, "c°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, "da°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, "d°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeCelsiusPerHour, "°C/h")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeCelsiusPerMinute, "°C/min")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeCelsiusPerSecond, "°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeFahrenheitPerHour, "°F/h")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, "°F/min")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, "°F/s")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeKelvinPerHour, "K/h")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeKelvinPerMinute, "K/min")] + [InlineData("en-US", TemperatureChangeRateUnit.DegreeKelvinPerSecond, "K/s")] + [InlineData("en-US", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, "h°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, "k°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, "µ°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, "m°C/s")] + [InlineData("en-US", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, "n°C/s")] + public void GetAbbreviationForCulture(string culture, TemperatureChangeRateUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = TemperatureChangeRate.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(TemperatureChangeRate.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = TemperatureChangeRate.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TemperatureChangeRateUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index 8f2c376f77..5e5a9fe8e2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ∆°C", TemperatureDeltaUnit.DegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 ∆°De", TemperatureDeltaUnit.DegreeDelisle, 4.2)] + [InlineData("en-US", "4.2 ∆°F", TemperatureDeltaUnit.DegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 ∆°N", TemperatureDeltaUnit.DegreeNewton, 4.2)] + [InlineData("en-US", "4.2 ∆°R", TemperatureDeltaUnit.DegreeRankine, 4.2)] + [InlineData("en-US", "4.2 ∆°Ré", TemperatureDeltaUnit.DegreeReaumur, 4.2)] + [InlineData("en-US", "4.2 ∆°Rø", TemperatureDeltaUnit.DegreeRoemer, 4.2)] + [InlineData("en-US", "4.2 ∆K", TemperatureDeltaUnit.Kelvin, 4.2)] + [InlineData("en-US", "4.2 ∆m°C", TemperatureDeltaUnit.MillidegreeCelsius, 4.2)] + public void Parse(string culture, string quantityString, TemperatureDeltaUnit expectedUnit, double expectedValue) { - try - { - var parsed = TemperatureDelta.Parse("1 ∆°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsius, DegreesCelsiusTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°De", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesDelisle, DegreesDelisleTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeDelisle, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheit, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°N", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesNewton, DegreesNewtonTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeNewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°R", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesRankine, DegreesRankineTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRankine, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°Ré", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesReaumur, DegreesReaumurTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeReaumur, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆°Rø", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesRoemer, DegreesRoemerTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRoemer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kelvins, KelvinsTolerance); - Assert.Equal(TemperatureDeltaUnit.Kelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureDelta.Parse("1 ∆m°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsius, MillidegreesCelsiusTolerance); - Assert.Equal(TemperatureDeltaUnit.MillidegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = TemperatureDelta.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 ∆°C", TemperatureDeltaUnit.DegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 ∆°De", TemperatureDeltaUnit.DegreeDelisle, 4.2)] + [InlineData("en-US", "4.2 ∆°F", TemperatureDeltaUnit.DegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 ∆°N", TemperatureDeltaUnit.DegreeNewton, 4.2)] + [InlineData("en-US", "4.2 ∆°R", TemperatureDeltaUnit.DegreeRankine, 4.2)] + [InlineData("en-US", "4.2 ∆°Ré", TemperatureDeltaUnit.DegreeReaumur, 4.2)] + [InlineData("en-US", "4.2 ∆°Rø", TemperatureDeltaUnit.DegreeRoemer, 4.2)] + [InlineData("en-US", "4.2 ∆K", TemperatureDeltaUnit.Kelvin, 4.2)] + [InlineData("en-US", "4.2 ∆m°C", TemperatureDeltaUnit.MillidegreeCelsius, 4.2)] + public void TryParse(string culture, string quantityString, TemperatureDeltaUnit expectedUnit, double expectedValue) { - { - Assert.True(TemperatureDelta.TryParse("1 ∆°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsius, DegreesCelsiusTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeCelsius, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°De", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesDelisle, DegreesDelisleTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeDelisle, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheit, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeFahrenheit, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°N", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesNewton, DegreesNewtonTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeNewton, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°R", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesRankine, DegreesRankineTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRankine, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°Ré", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesReaumur, DegreesReaumurTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeReaumur, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆°Rø", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesRoemer, DegreesRoemerTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRoemer, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kelvins, KelvinsTolerance); - Assert.Equal(TemperatureDeltaUnit.Kelvin, parsed.Unit); - } - - { - Assert.True(TemperatureDelta.TryParse("1 ∆m°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsius, MillidegreesCelsiusTolerance); - Assert.Equal(TemperatureDeltaUnit.MillidegreeCelsius, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(TemperatureDelta.TryParse(quantityString, out TemperatureDelta parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Temper Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TemperatureDeltaUnit.DegreeCelsius, "∆°C")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeDelisle, "∆°De")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeFahrenheit, "∆°F")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeNewton, "∆°N")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeRankine, "∆°R")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeReaumur, "∆°Ré")] + [InlineData("en-US", TemperatureDeltaUnit.DegreeRoemer, "∆°Rø")] + [InlineData("en-US", TemperatureDeltaUnit.Kelvin, "∆K")] + [InlineData("en-US", TemperatureDeltaUnit.MillidegreeCelsius, "∆m°C")] + public void GetAbbreviationForCulture(string culture, TemperatureDeltaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = TemperatureDelta.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(TemperatureDelta.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = TemperatureDelta.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TemperatureDeltaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index 516a921d2d..eeec8bca9f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -288,66 +288,30 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 ∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer, 4.2)] + [InlineData("en-US", "4.2 ∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter, 4.2)] + [InlineData("en-US", "4.2 ∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot, 4.2)] + [InlineData("en-US", "4.2 ∆°K/m", TemperatureGradientUnit.KelvinPerMeter, 4.2)] + public void Parse(string culture, string quantityString, TemperatureGradientUnit expectedUnit, double expectedValue) { - try - { - var parsed = TemperatureGradient.Parse("1 ∆°C/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerKilometer, DegreesCelsiusPerKilometerTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureGradient.Parse("1 ∆°C/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerMeter, DegreesCelsiusPerMeterTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureGradient.Parse("1 ∆°F/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerFoot, DegreesFahrenheitPerFootTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeFahrenheitPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = TemperatureGradient.Parse("1 ∆°K/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KelvinsPerMeter, KelvinsPerMeterTolerance); - Assert.Equal(TemperatureGradientUnit.KelvinPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = TemperatureGradient.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 ∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer, 4.2)] + [InlineData("en-US", "4.2 ∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter, 4.2)] + [InlineData("en-US", "4.2 ∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot, 4.2)] + [InlineData("en-US", "4.2 ∆°K/m", TemperatureGradientUnit.KelvinPerMeter, 4.2)] + public void TryParse(string culture, string quantityString, TemperatureGradientUnit expectedUnit, double expectedValue) { - { - Assert.True(TemperatureGradient.TryParse("1 ∆°C/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerKilometer, DegreesCelsiusPerKilometerTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerKilometer, parsed.Unit); - } - - { - Assert.True(TemperatureGradient.TryParse("1 ∆°C/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerMeter, DegreesCelsiusPerMeterTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerMeter, parsed.Unit); - } - - { - Assert.True(TemperatureGradient.TryParse("1 ∆°F/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheitPerFoot, DegreesFahrenheitPerFootTolerance); - Assert.Equal(TemperatureGradientUnit.DegreeFahrenheitPerFoot, parsed.Unit); - } - - { - Assert.True(TemperatureGradient.TryParse("1 ∆°K/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KelvinsPerMeter, KelvinsPerMeterTolerance); - Assert.Equal(TemperatureGradientUnit.KelvinPerMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(TemperatureGradient.TryParse(quantityString, out TemperatureGradient parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -448,6 +412,30 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Temper Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TemperatureGradientUnit.DegreeCelsiusPerKilometer, "∆°C/km")] + [InlineData("en-US", TemperatureGradientUnit.DegreeCelsiusPerMeter, "∆°C/m")] + [InlineData("en-US", TemperatureGradientUnit.DegreeFahrenheitPerFoot, "∆°F/ft")] + [InlineData("en-US", TemperatureGradientUnit.KelvinPerMeter, "∆°K/m")] + public void GetAbbreviationForCulture(string culture, TemperatureGradientUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = TemperatureGradient.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(TemperatureGradient.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = TemperatureGradient.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TemperatureGradientUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index 3d33508c97..2f14629e8a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -324,144 +324,42 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 °C", TemperatureUnit.DegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 °De", TemperatureUnit.DegreeDelisle, 4.2)] + [InlineData("en-US", "4.2 °F", TemperatureUnit.DegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 °N", TemperatureUnit.DegreeNewton, 4.2)] + [InlineData("en-US", "4.2 °R", TemperatureUnit.DegreeRankine, 4.2)] + [InlineData("en-US", "4.2 °Ré", TemperatureUnit.DegreeReaumur, 4.2)] + [InlineData("en-US", "4.2 °Rø", TemperatureUnit.DegreeRoemer, 4.2)] + [InlineData("en-US", "4.2 K", TemperatureUnit.Kelvin, 4.2)] + [InlineData("en-US", "4.2 m°C", TemperatureUnit.MillidegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 T⊙", TemperatureUnit.SolarTemperature, 4.2)] + public void Parse(string culture, string quantityString, TemperatureUnit expectedUnit, double expectedValue) { - try - { - var parsed = Temperature.Parse("1 °C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsius, DegreesCelsiusTolerance); - Assert.Equal(TemperatureUnit.DegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °De", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesDelisle, DegreesDelisleTolerance); - Assert.Equal(TemperatureUnit.DegreeDelisle, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheit, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureUnit.DegreeFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °N", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesNewton, DegreesNewtonTolerance); - Assert.Equal(TemperatureUnit.DegreeNewton, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °R", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesRankine, DegreesRankineTolerance); - Assert.Equal(TemperatureUnit.DegreeRankine, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °Ré", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesReaumur, DegreesReaumurTolerance); - Assert.Equal(TemperatureUnit.DegreeReaumur, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 °Rø", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesRoemer, DegreesRoemerTolerance); - Assert.Equal(TemperatureUnit.DegreeRoemer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 K", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kelvins, KelvinsTolerance); - Assert.Equal(TemperatureUnit.Kelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 m°C", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsius, MillidegreesCelsiusTolerance); - Assert.Equal(TemperatureUnit.MillidegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Temperature.Parse("1 T⊙", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SolarTemperatures, SolarTemperaturesTolerance); - Assert.Equal(TemperatureUnit.SolarTemperature, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Temperature.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 °C", TemperatureUnit.DegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 °De", TemperatureUnit.DegreeDelisle, 4.2)] + [InlineData("en-US", "4.2 °F", TemperatureUnit.DegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 °N", TemperatureUnit.DegreeNewton, 4.2)] + [InlineData("en-US", "4.2 °R", TemperatureUnit.DegreeRankine, 4.2)] + [InlineData("en-US", "4.2 °Ré", TemperatureUnit.DegreeReaumur, 4.2)] + [InlineData("en-US", "4.2 °Rø", TemperatureUnit.DegreeRoemer, 4.2)] + [InlineData("en-US", "4.2 K", TemperatureUnit.Kelvin, 4.2)] + [InlineData("en-US", "4.2 m°C", TemperatureUnit.MillidegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 T⊙", TemperatureUnit.SolarTemperature, 4.2)] + public void TryParse(string culture, string quantityString, TemperatureUnit expectedUnit, double expectedValue) { - { - Assert.True(Temperature.TryParse("1 °C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsius, DegreesCelsiusTolerance); - Assert.Equal(TemperatureUnit.DegreeCelsius, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °De", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesDelisle, DegreesDelisleTolerance); - Assert.Equal(TemperatureUnit.DegreeDelisle, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesFahrenheit, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureUnit.DegreeFahrenheit, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °N", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesNewton, DegreesNewtonTolerance); - Assert.Equal(TemperatureUnit.DegreeNewton, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °R", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesRankine, DegreesRankineTolerance); - Assert.Equal(TemperatureUnit.DegreeRankine, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °Ré", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesReaumur, DegreesReaumurTolerance); - Assert.Equal(TemperatureUnit.DegreeReaumur, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 °Rø", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesRoemer, DegreesRoemerTolerance); - Assert.Equal(TemperatureUnit.DegreeRoemer, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 K", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kelvins, KelvinsTolerance); - Assert.Equal(TemperatureUnit.Kelvin, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 m°C", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillidegreesCelsius, MillidegreesCelsiusTolerance); - Assert.Equal(TemperatureUnit.MillidegreeCelsius, parsed.Unit); - } - - { - Assert.True(Temperature.TryParse("1 T⊙", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SolarTemperatures, SolarTemperaturesTolerance); - Assert.Equal(TemperatureUnit.SolarTemperature, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Temperature.TryParse(quantityString, out Temperature parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -610,6 +508,36 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Temper Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TemperatureUnit.DegreeCelsius, "°C")] + [InlineData("en-US", TemperatureUnit.DegreeDelisle, "°De")] + [InlineData("en-US", TemperatureUnit.DegreeFahrenheit, "°F")] + [InlineData("en-US", TemperatureUnit.DegreeNewton, "°N")] + [InlineData("en-US", TemperatureUnit.DegreeRankine, "°R")] + [InlineData("en-US", TemperatureUnit.DegreeReaumur, "°Ré")] + [InlineData("en-US", TemperatureUnit.DegreeRoemer, "°Rø")] + [InlineData("en-US", TemperatureUnit.Kelvin, "K")] + [InlineData("en-US", TemperatureUnit.MillidegreeCelsius, "m°C")] + [InlineData("en-US", TemperatureUnit.SolarTemperature, "T⊙")] + public void GetAbbreviationForCulture(string culture, TemperatureUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Temperature.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Temperature.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Temperature.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TemperatureUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index 66c8fa9908..d5877cfa28 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -276,40 +276,26 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit, 4.2)] + [InlineData("en-US", "4.2 W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin, 4.2)] + public void Parse(string culture, string quantityString, ThermalConductivityUnit expectedUnit, double expectedValue) { - try - { - var parsed = ThermalConductivity.Parse("1 BTU/(h·ft·°F)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance); - Assert.Equal(ThermalConductivityUnit.BtuPerHourFootFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalConductivity.Parse("1 W/(m·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ThermalConductivity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit, 4.2)] + [InlineData("en-US", "4.2 W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin, 4.2)] + public void TryParse(string culture, string quantityString, ThermalConductivityUnit expectedUnit, double expectedValue) { - { - Assert.True(ThermalConductivity.TryParse("1 BTU/(h·ft·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance); - Assert.Equal(ThermalConductivityUnit.BtuPerHourFootFahrenheit, parsed.Unit); - } - - { - Assert.True(ThermalConductivity.TryParse("1 W/(m·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ThermalConductivity.TryParse(quantityString, out ThermalConductivity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -394,6 +380,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Therma Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ThermalConductivityUnit.BtuPerHourFootFahrenheit, "BTU/(h·ft·°F)")] + [InlineData("en-US", ThermalConductivityUnit.WattPerMeterKelvin, "W/(m·K)")] + public void GetAbbreviationForCulture(string culture, ThermalConductivityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ThermalConductivity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ThermalConductivity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ThermalConductivity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ThermalConductivityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs index f575050fea..08b4552983 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs @@ -306,105 +306,36 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, 4.2)] + [InlineData("en-US", "4.2 cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, 4.2)] + [InlineData("en-US", "4.2 cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, 4.2)] + [InlineData("en-US", "4.2 m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, 4.2)] + [InlineData("en-US", "4.2 m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, 4.2)] + [InlineData("en-US", "4.2 m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt, 4.2)] + [InlineData("en-US", "4.2 mm²K/W", ThermalInsulanceUnit.SquareMillimeterKelvinPerWatt, 4.2)] + public void Parse(string culture, string quantityString, ThermalInsulanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ThermalInsulance.Parse("1 Hrft²°F/Btu", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HourSquareFeetDegreesFahrenheitPerBtu, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - Assert.Equal(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 cm²Hr°C/kcal", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeterHourDegreesCelsiusPerKilocalorie, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 cm²K/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareCentimeterKelvinsPerWatt, SquareCentimeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 m²°C/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMeterDegreesCelsiusPerWatt, SquareMeterDegreesCelsiusPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 m²K/kW", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 m²K/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMeterKelvinsPerWatt, SquareMeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalInsulance.Parse("1 mm²K/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.SquareMillimeterKelvinsPerWatt, SquareMillimeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMillimeterKelvinPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ThermalInsulance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, 4.2)] + [InlineData("en-US", "4.2 cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, 4.2)] + [InlineData("en-US", "4.2 cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, 4.2)] + [InlineData("en-US", "4.2 m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, 4.2)] + [InlineData("en-US", "4.2 m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, 4.2)] + [InlineData("en-US", "4.2 m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt, 4.2)] + [InlineData("en-US", "4.2 mm²K/W", ThermalInsulanceUnit.SquareMillimeterKelvinPerWatt, 4.2)] + public void TryParse(string culture, string quantityString, ThermalInsulanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ThermalInsulance.TryParse("1 Hrft²°F/Btu", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HourSquareFeetDegreesFahrenheitPerBtu, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - Assert.Equal(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 cm²Hr°C/kcal", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeterHourDegreesCelsiusPerKilocalorie, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 cm²K/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareCentimeterKelvinsPerWatt, SquareCentimeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 m²°C/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeterDegreesCelsiusPerWatt, SquareMeterDegreesCelsiusPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 m²K/kW", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 m²K/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMeterKelvinsPerWatt, SquareMeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, parsed.Unit); - } - - { - Assert.True(ThermalInsulance.TryParse("1 mm²K/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.SquareMillimeterKelvinsPerWatt, SquareMillimeterKelvinsPerWattTolerance); - Assert.Equal(ThermalInsulanceUnit.SquareMillimeterKelvinPerWatt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ThermalInsulance.TryParse(quantityString, out ThermalInsulance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -529,6 +460,33 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Therma Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, "Hrft²°F/Btu")] + [InlineData("en-US", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, "cm²Hr°C/kcal")] + [InlineData("en-US", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, "cm²K/W")] + [InlineData("en-US", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, "m²°C/W")] + [InlineData("en-US", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, "m²K/kW")] + [InlineData("en-US", ThermalInsulanceUnit.SquareMeterKelvinPerWatt, "m²K/W")] + [InlineData("en-US", ThermalInsulanceUnit.SquareMillimeterKelvinPerWatt, "mm²K/W")] + public void GetAbbreviationForCulture(string culture, ThermalInsulanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ThermalInsulance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ThermalInsulance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ThermalInsulance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ThermalInsulanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs index 5145224e81..fcb444dd56 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs @@ -276,40 +276,26 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 °C/W", ThermalResistanceUnit.DegreeCelsiusPerWatt, 4.2)] + [InlineData("en-US", "4.2 K/W", ThermalResistanceUnit.KelvinPerWatt, 4.2)] + public void Parse(string culture, string quantityString, ThermalResistanceUnit expectedUnit, double expectedValue) { - try - { - var parsed = ThermalResistance.Parse("1 °C/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerWatt, DegreesCelsiusPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.DegreeCelsiusPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ThermalResistance.Parse("1 K/W", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KelvinsPerWatt, KelvinsPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.KelvinPerWatt, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = ThermalResistance.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 °C/W", ThermalResistanceUnit.DegreeCelsiusPerWatt, 4.2)] + [InlineData("en-US", "4.2 K/W", ThermalResistanceUnit.KelvinPerWatt, 4.2)] + public void TryParse(string culture, string quantityString, ThermalResistanceUnit expectedUnit, double expectedValue) { - { - Assert.True(ThermalResistance.TryParse("1 °C/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DegreesCelsiusPerWatt, DegreesCelsiusPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.DegreeCelsiusPerWatt, parsed.Unit); - } - - { - Assert.True(ThermalResistance.TryParse("1 K/W", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KelvinsPerWatt, KelvinsPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.KelvinPerWatt, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(ThermalResistance.TryParse(quantityString, out ThermalResistance parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -394,6 +380,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Therma Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", ThermalResistanceUnit.DegreeCelsiusPerWatt, "°C/W")] + [InlineData("en-US", ThermalResistanceUnit.KelvinPerWatt, "K/W")] + public void GetAbbreviationForCulture(string culture, ThermalResistanceUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = ThermalResistance.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(ThermalResistance.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = ThermalResistance.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(ThermalResistanceUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index 62113617cd..56511c63f2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -414,378 +414,78 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 gf·cm", TorqueUnit.GramForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 gf·m", TorqueUnit.GramForceMeter, 4.2)] + [InlineData("en-US", "4.2 gf·mm", TorqueUnit.GramForceMillimeter, 4.2)] + [InlineData("en-US", "4.2 kgf·cm", TorqueUnit.KilogramForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf·m", TorqueUnit.KilogramForceMeter, 4.2)] + [InlineData("en-US", "4.2 kgf·mm", TorqueUnit.KilogramForceMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN·cm", TorqueUnit.KilonewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN·m", TorqueUnit.KilonewtonMeter, 4.2)] + [InlineData("en-US", "4.2 kN·mm", TorqueUnit.KilonewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf·ft", TorqueUnit.KilopoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 kipf·in", TorqueUnit.KilopoundForceInch, 4.2)] + [InlineData("en-US", "4.2 MN·cm", TorqueUnit.MeganewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 MN·m", TorqueUnit.MeganewtonMeter, 4.2)] + [InlineData("en-US", "4.2 MN·mm", TorqueUnit.MeganewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 Mlbf·ft", TorqueUnit.MegapoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 Mlbf·in", TorqueUnit.MegapoundForceInch, 4.2)] + [InlineData("en-US", "4.2 N·cm", TorqueUnit.NewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 N·m", TorqueUnit.NewtonMeter, 4.2)] + [InlineData("en-US", "4.2 N·mm", TorqueUnit.NewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 pdl·ft", TorqueUnit.PoundalFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·ft", TorqueUnit.PoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·in", TorqueUnit.PoundForceInch, 4.2)] + [InlineData("en-US", "4.2 tf·cm", TorqueUnit.TonneForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf·m", TorqueUnit.TonneForceMeter, 4.2)] + [InlineData("en-US", "4.2 tf·mm", TorqueUnit.TonneForceMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН·м", TorqueUnit.KilonewtonMeter, 4.2)] + [InlineData("ru-RU", "4,2 МН·м", TorqueUnit.MeganewtonMeter, 4.2)] + [InlineData("ru-RU", "4,2 Н·м", TorqueUnit.NewtonMeter, 4.2)] + public void Parse(string culture, string quantityString, TorqueUnit expectedUnit, double expectedValue) { - try - { - var parsed = Torque.Parse("1 gf·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramForceCentimeters, GramForceCentimetersTolerance); - Assert.Equal(TorqueUnit.GramForceCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 gf·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramForceMeters, GramForceMetersTolerance); - Assert.Equal(TorqueUnit.GramForceMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 gf·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GramForceMillimeters, GramForceMillimetersTolerance); - Assert.Equal(TorqueUnit.GramForceMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kgf·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramForceCentimeters, KilogramForceCentimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kgf·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramForceMeters, KilogramForceMetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kgf·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilogramForceMillimeters, KilogramForceMillimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kN·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonCentimeters, KilonewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kN·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMeters, KilonewtonMetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 кН·м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMeters, KilonewtonMetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kN·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimeters, KilonewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kipf·ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeet, KilopoundForceFeetTolerance); - Assert.Equal(TorqueUnit.KilopoundForceFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 kipf·in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilopoundForceInches, KilopoundForceInchesTolerance); - Assert.Equal(TorqueUnit.KilopoundForceInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 MN·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonCentimeters, MeganewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 MN·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMeters, MeganewtonMetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 МН·м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMeters, MeganewtonMetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 MN·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimeters, MeganewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 Mlbf·ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundForceFeet, MegapoundForceFeetTolerance); - Assert.Equal(TorqueUnit.MegapoundForceFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 Mlbf·in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegapoundForceInches, MegapoundForceInchesTolerance); - Assert.Equal(TorqueUnit.MegapoundForceInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 N·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonCentimeters, NewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.NewtonCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 N·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMeters, NewtonMetersTolerance); - Assert.Equal(TorqueUnit.NewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 Н·м", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NewtonMeters, NewtonMetersTolerance); - Assert.Equal(TorqueUnit.NewtonMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 N·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NewtonMillimeters, NewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.NewtonMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 pdl·ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundalFeet, PoundalFeetTolerance); - Assert.Equal(TorqueUnit.PoundalFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 lbf·ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceFeet, PoundForceFeetTolerance); - Assert.Equal(TorqueUnit.PoundForceFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 lbf·in", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PoundForceInches, PoundForceInchesTolerance); - Assert.Equal(TorqueUnit.PoundForceInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 tf·cm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneForceCentimeters, TonneForceCentimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 tf·m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneForceMeters, TonneForceMetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Torque.Parse("1 tf·mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.TonneForceMillimeters, TonneForceMillimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Torque.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 gf·cm", TorqueUnit.GramForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 gf·m", TorqueUnit.GramForceMeter, 4.2)] + [InlineData("en-US", "4.2 gf·mm", TorqueUnit.GramForceMillimeter, 4.2)] + [InlineData("en-US", "4.2 kgf·cm", TorqueUnit.KilogramForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 kgf·m", TorqueUnit.KilogramForceMeter, 4.2)] + [InlineData("en-US", "4.2 kgf·mm", TorqueUnit.KilogramForceMillimeter, 4.2)] + [InlineData("en-US", "4.2 kN·cm", TorqueUnit.KilonewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 kN·m", TorqueUnit.KilonewtonMeter, 4.2)] + [InlineData("en-US", "4.2 kN·mm", TorqueUnit.KilonewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 kipf·ft", TorqueUnit.KilopoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 kipf·in", TorqueUnit.KilopoundForceInch, 4.2)] + [InlineData("en-US", "4.2 MN·cm", TorqueUnit.MeganewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 MN·m", TorqueUnit.MeganewtonMeter, 4.2)] + [InlineData("en-US", "4.2 MN·mm", TorqueUnit.MeganewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 Mlbf·ft", TorqueUnit.MegapoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 Mlbf·in", TorqueUnit.MegapoundForceInch, 4.2)] + [InlineData("en-US", "4.2 N·cm", TorqueUnit.NewtonCentimeter, 4.2)] + [InlineData("en-US", "4.2 N·m", TorqueUnit.NewtonMeter, 4.2)] + [InlineData("en-US", "4.2 N·mm", TorqueUnit.NewtonMillimeter, 4.2)] + [InlineData("en-US", "4.2 pdl·ft", TorqueUnit.PoundalFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·ft", TorqueUnit.PoundForceFoot, 4.2)] + [InlineData("en-US", "4.2 lbf·in", TorqueUnit.PoundForceInch, 4.2)] + [InlineData("en-US", "4.2 tf·cm", TorqueUnit.TonneForceCentimeter, 4.2)] + [InlineData("en-US", "4.2 tf·m", TorqueUnit.TonneForceMeter, 4.2)] + [InlineData("en-US", "4.2 tf·mm", TorqueUnit.TonneForceMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 кН·м", TorqueUnit.KilonewtonMeter, 4.2)] + [InlineData("ru-RU", "4,2 МН·м", TorqueUnit.MeganewtonMeter, 4.2)] + [InlineData("ru-RU", "4,2 Н·м", TorqueUnit.NewtonMeter, 4.2)] + public void TryParse(string culture, string quantityString, TorqueUnit expectedUnit, double expectedValue) { - { - Assert.True(Torque.TryParse("1 gf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramForceCentimeters, GramForceCentimetersTolerance); - Assert.Equal(TorqueUnit.GramForceCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 gf·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramForceMeters, GramForceMetersTolerance); - Assert.Equal(TorqueUnit.GramForceMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 gf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GramForceMillimeters, GramForceMillimetersTolerance); - Assert.Equal(TorqueUnit.GramForceMillimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kgf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramForceCentimeters, KilogramForceCentimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kgf·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramForceMeters, KilogramForceMetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kgf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilogramForceMillimeters, KilogramForceMillimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMillimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kN·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonCentimeters, KilonewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kN·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMeters, KilonewtonMetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 кН·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMeters, KilonewtonMetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kN·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilonewtonMillimeters, KilonewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMillimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kipf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceFeet, KilopoundForceFeetTolerance); - Assert.Equal(TorqueUnit.KilopoundForceFoot, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 kipf·in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilopoundForceInches, KilopoundForceInchesTolerance); - Assert.Equal(TorqueUnit.KilopoundForceInch, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 MN·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonCentimeters, MeganewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 MN·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMeters, MeganewtonMetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 МН·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMeters, MeganewtonMetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 MN·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MeganewtonMillimeters, MeganewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMillimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 Mlbf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundForceFeet, MegapoundForceFeetTolerance); - Assert.Equal(TorqueUnit.MegapoundForceFoot, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 Mlbf·in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegapoundForceInches, MegapoundForceInchesTolerance); - Assert.Equal(TorqueUnit.MegapoundForceInch, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 N·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonCentimeters, NewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.NewtonCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 N·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMeters, NewtonMetersTolerance); - Assert.Equal(TorqueUnit.NewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 Н·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMeters, NewtonMetersTolerance); - Assert.Equal(TorqueUnit.NewtonMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 N·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NewtonMillimeters, NewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.NewtonMillimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 pdl·ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundalFeet, PoundalFeetTolerance); - Assert.Equal(TorqueUnit.PoundalFoot, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 lbf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceFeet, PoundForceFeetTolerance); - Assert.Equal(TorqueUnit.PoundForceFoot, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 lbf·in", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PoundForceInches, PoundForceInchesTolerance); - Assert.Equal(TorqueUnit.PoundForceInch, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 tf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneForceCentimeters, TonneForceCentimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceCentimeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 tf·m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneForceMeters, TonneForceMetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMeter, parsed.Unit); - } - - { - Assert.True(Torque.TryParse("1 tf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.TonneForceMillimeters, TonneForceMillimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMillimeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Torque.TryParse(quantityString, out Torque parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -1066,6 +766,54 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Torque Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TorqueUnit.GramForceCentimeter, "gf·cm")] + [InlineData("en-US", TorqueUnit.GramForceMeter, "gf·m")] + [InlineData("en-US", TorqueUnit.GramForceMillimeter, "gf·mm")] + [InlineData("en-US", TorqueUnit.KilogramForceCentimeter, "kgf·cm")] + [InlineData("en-US", TorqueUnit.KilogramForceMeter, "kgf·m")] + [InlineData("en-US", TorqueUnit.KilogramForceMillimeter, "kgf·mm")] + [InlineData("en-US", TorqueUnit.KilonewtonCentimeter, "kN·cm")] + [InlineData("en-US", TorqueUnit.KilonewtonMeter, "kN·m")] + [InlineData("en-US", TorqueUnit.KilonewtonMillimeter, "kN·mm")] + [InlineData("en-US", TorqueUnit.KilopoundForceFoot, "kipf·ft")] + [InlineData("en-US", TorqueUnit.KilopoundForceInch, "kipf·in")] + [InlineData("en-US", TorqueUnit.MeganewtonCentimeter, "MN·cm")] + [InlineData("en-US", TorqueUnit.MeganewtonMeter, "MN·m")] + [InlineData("en-US", TorqueUnit.MeganewtonMillimeter, "MN·mm")] + [InlineData("en-US", TorqueUnit.MegapoundForceFoot, "Mlbf·ft")] + [InlineData("en-US", TorqueUnit.MegapoundForceInch, "Mlbf·in")] + [InlineData("en-US", TorqueUnit.NewtonCentimeter, "N·cm")] + [InlineData("en-US", TorqueUnit.NewtonMeter, "N·m")] + [InlineData("en-US", TorqueUnit.NewtonMillimeter, "N·mm")] + [InlineData("en-US", TorqueUnit.PoundalFoot, "pdl·ft")] + [InlineData("en-US", TorqueUnit.PoundForceFoot, "lbf·ft")] + [InlineData("en-US", TorqueUnit.PoundForceInch, "lbf·in")] + [InlineData("en-US", TorqueUnit.TonneForceCentimeter, "tf·cm")] + [InlineData("en-US", TorqueUnit.TonneForceMeter, "tf·m")] + [InlineData("en-US", TorqueUnit.TonneForceMillimeter, "tf·mm")] + [InlineData("ru-RU", TorqueUnit.KilonewtonMeter, "кН·м")] + [InlineData("ru-RU", TorqueUnit.MeganewtonMeter, "МН·м")] + [InlineData("ru-RU", TorqueUnit.NewtonMeter, "Н·м")] + public void GetAbbreviationForCulture(string culture, TorqueUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Torque.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Torque.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Torque.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TorqueUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index d92778d5af..c6c0975f6a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -210,27 +210,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 NTU", TurbidityUnit.NTU, 4.2)] + public void Parse(string culture, string quantityString, TurbidityUnit expectedUnit, double expectedValue) { - try - { - var parsed = Turbidity.Parse("1 NTU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NTU, NTUTolerance); - Assert.Equal(TurbidityUnit.NTU, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = Turbidity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 NTU", TurbidityUnit.NTU, 4.2)] + public void TryParse(string culture, string quantityString, TurbidityUnit expectedUnit, double expectedValue) { - { - Assert.True(Turbidity.TryParse("1 NTU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NTU, NTUTolerance); - Assert.Equal(TurbidityUnit.NTU, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(Turbidity.TryParse(quantityString, out Turbidity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -307,6 +304,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Turbid Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", TurbidityUnit.NTU, "NTU")] + public void GetAbbreviationForCulture(string culture, TurbidityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Turbidity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Turbidity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Turbidity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(TurbidityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index 88e570b758..6b53bc1b76 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -210,27 +210,24 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 IU", VitaminAUnit.InternationalUnit, 4.2)] + public void Parse(string culture, string quantityString, VitaminAUnit expectedUnit, double expectedValue) { - try - { - var parsed = VitaminA.Parse("1 IU", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InternationalUnits, InternationalUnitsTolerance); - Assert.Equal(VitaminAUnit.InternationalUnit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = VitaminA.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 IU", VitaminAUnit.InternationalUnit, 4.2)] + public void TryParse(string culture, string quantityString, VitaminAUnit expectedUnit, double expectedValue) { - { - Assert.True(VitaminA.TryParse("1 IU", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InternationalUnits, InternationalUnitsTolerance); - Assert.Equal(VitaminAUnit.InternationalUnit, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(VitaminA.TryParse(quantityString, out VitaminA parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -307,6 +304,27 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Vitami Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VitaminAUnit.InternationalUnit, "IU")] + public void GetAbbreviationForCulture(string culture, VitaminAUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VitaminA.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VitaminA.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VitaminA.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VitaminAUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index 47abef74d6..bfb9b46189 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -324,287 +324,64 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cl/l", VolumeConcentrationUnit.CentiliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 cl/ml", VolumeConcentrationUnit.CentiliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dl/l", VolumeConcentrationUnit.DeciliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 dl/ml", VolumeConcentrationUnit.DeciliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ", VolumeConcentrationUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 l/l", VolumeConcentrationUnit.LiterPerLiter, 4.2)] + [InlineData("en-US", "4.2 l/ml", VolumeConcentrationUnit.LiterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 µl/l", VolumeConcentrationUnit.MicroliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 µl/ml", VolumeConcentrationUnit.MicroliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ml/l", VolumeConcentrationUnit.MilliliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 ml/ml", VolumeConcentrationUnit.MilliliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 nl/l", VolumeConcentrationUnit.NanoliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 nl/ml", VolumeConcentrationUnit.NanoliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ppb", VolumeConcentrationUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", VolumeConcentrationUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", VolumeConcentrationUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", VolumeConcentrationUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", VolumeConcentrationUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 % (v/v)", VolumeConcentrationUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 pl/l", VolumeConcentrationUnit.PicoliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 pl/ml", VolumeConcentrationUnit.PicoliterPerMilliliter, 4.2)] + public void Parse(string culture, string quantityString, VolumeConcentrationUnit expectedUnit, double expectedValue) { - try - { - var parsed = VolumeConcentration.Parse("1 cl/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerLiter, CentilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.CentiliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 cl/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMilliliter, CentilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.CentiliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 dl/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerLiter, DecilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.DeciliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 dl/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMilliliter, DecilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.DeciliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(VolumeConcentrationUnit.DecimalFraction, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 l/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerLiter, LitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.LiterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 l/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerMilliliter, LitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.LiterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 µl/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerLiter, MicrolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.MicroliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 µl/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMilliliter, MicrolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.MicroliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ml/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerLiter, MillilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.MilliliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ml/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerMilliliter, MillilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.MilliliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 nl/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerLiter, NanolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.NanoliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 nl/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMilliliter, NanolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.NanoliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ppb", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerBillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ppm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerMillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ‰", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerThousand, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 ppt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerTrillion, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 %", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(VolumeConcentrationUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 % (v/v)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(VolumeConcentrationUnit.Percent, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 pl/l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicolitersPerLiter, PicolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.PicoliterPerLiter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeConcentration.Parse("1 pl/ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicolitersPerMilliliter, PicolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.PicoliterPerMilliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = VolumeConcentration.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cl/l", VolumeConcentrationUnit.CentiliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 cl/ml", VolumeConcentrationUnit.CentiliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 dl/l", VolumeConcentrationUnit.DeciliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 dl/ml", VolumeConcentrationUnit.DeciliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ", VolumeConcentrationUnit.DecimalFraction, 4.2)] + [InlineData("en-US", "4.2 l/l", VolumeConcentrationUnit.LiterPerLiter, 4.2)] + [InlineData("en-US", "4.2 l/ml", VolumeConcentrationUnit.LiterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 µl/l", VolumeConcentrationUnit.MicroliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 µl/ml", VolumeConcentrationUnit.MicroliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ml/l", VolumeConcentrationUnit.MilliliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 ml/ml", VolumeConcentrationUnit.MilliliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 nl/l", VolumeConcentrationUnit.NanoliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 nl/ml", VolumeConcentrationUnit.NanoliterPerMilliliter, 4.2)] + [InlineData("en-US", "4.2 ppb", VolumeConcentrationUnit.PartPerBillion, 4.2)] + [InlineData("en-US", "4.2 ppm", VolumeConcentrationUnit.PartPerMillion, 4.2)] + [InlineData("en-US", "4.2 ‰", VolumeConcentrationUnit.PartPerThousand, 4.2)] + [InlineData("en-US", "4.2 ppt", VolumeConcentrationUnit.PartPerTrillion, 4.2)] + [InlineData("en-US", "4.2 %", VolumeConcentrationUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 % (v/v)", VolumeConcentrationUnit.Percent, 4.2)] + [InlineData("en-US", "4.2 pl/l", VolumeConcentrationUnit.PicoliterPerLiter, 4.2)] + [InlineData("en-US", "4.2 pl/ml", VolumeConcentrationUnit.PicoliterPerMilliliter, 4.2)] + public void TryParse(string culture, string quantityString, VolumeConcentrationUnit expectedUnit, double expectedValue) { - { - Assert.True(VolumeConcentration.TryParse("1 cl/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerLiter, CentilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.CentiliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 cl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMilliliter, CentilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.CentiliterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 dl/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerLiter, DecilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.DeciliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 dl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMilliliter, DecilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.DeciliterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimalFractions, DecimalFractionsTolerance); - Assert.Equal(VolumeConcentrationUnit.DecimalFraction, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 l/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerLiter, LitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.LiterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 l/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMilliliter, LitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.LiterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 µl/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerLiter, MicrolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.MicroliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 µl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMilliliter, MicrolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.MicroliterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ml/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillilitersPerLiter, MillilitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.MilliliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ml/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillilitersPerMilliliter, MillilitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.MilliliterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 nl/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerLiter, NanolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.NanoliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 nl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMilliliter, NanolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.NanoliterPerMilliliter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ppb", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerBillion, PartsPerBillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerBillion, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ppm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerMillion, PartsPerMillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerMillion, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ‰", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerThousand, PartsPerThousandTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerThousand, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 ppt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PartsPerTrillion, PartsPerTrillionTolerance); - Assert.Equal(VolumeConcentrationUnit.PartPerTrillion, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 %", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(VolumeConcentrationUnit.Percent, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 % (v/v)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Percent, PercentTolerance); - Assert.Equal(VolumeConcentrationUnit.Percent, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 pl/l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicolitersPerLiter, PicolitersPerLiterTolerance); - Assert.Equal(VolumeConcentrationUnit.PicoliterPerLiter, parsed.Unit); - } - - { - Assert.True(VolumeConcentration.TryParse("1 pl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicolitersPerMilliliter, PicolitersPerMilliliterTolerance); - Assert.Equal(VolumeConcentrationUnit.PicoliterPerMilliliter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(VolumeConcentration.TryParse(quantityString, out VolumeConcentration parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -841,6 +618,46 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Volume Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VolumeConcentrationUnit.CentiliterPerLiter, "cl/l")] + [InlineData("en-US", VolumeConcentrationUnit.CentiliterPerMilliliter, "cl/ml")] + [InlineData("en-US", VolumeConcentrationUnit.DeciliterPerLiter, "dl/l")] + [InlineData("en-US", VolumeConcentrationUnit.DeciliterPerMilliliter, "dl/ml")] + [InlineData("en-US", VolumeConcentrationUnit.DecimalFraction, "")] + [InlineData("en-US", VolumeConcentrationUnit.LiterPerLiter, "l/l")] + [InlineData("en-US", VolumeConcentrationUnit.LiterPerMilliliter, "l/ml")] + [InlineData("en-US", VolumeConcentrationUnit.MicroliterPerLiter, "µl/l")] + [InlineData("en-US", VolumeConcentrationUnit.MicroliterPerMilliliter, "µl/ml")] + [InlineData("en-US", VolumeConcentrationUnit.MilliliterPerLiter, "ml/l")] + [InlineData("en-US", VolumeConcentrationUnit.MilliliterPerMilliliter, "ml/ml")] + [InlineData("en-US", VolumeConcentrationUnit.NanoliterPerLiter, "nl/l")] + [InlineData("en-US", VolumeConcentrationUnit.NanoliterPerMilliliter, "nl/ml")] + [InlineData("en-US", VolumeConcentrationUnit.PartPerBillion, "ppb")] + [InlineData("en-US", VolumeConcentrationUnit.PartPerMillion, "ppm")] + [InlineData("en-US", VolumeConcentrationUnit.PartPerThousand, "‰")] + [InlineData("en-US", VolumeConcentrationUnit.PartPerTrillion, "ppt")] + [InlineData("en-US", VolumeConcentrationUnit.Percent, "%")] + [InlineData("en-US", VolumeConcentrationUnit.PicoliterPerLiter, "pl/l")] + [InlineData("en-US", VolumeConcentrationUnit.PicoliterPerMilliliter, "pl/ml")] + public void GetAbbreviationForCulture(string culture, VolumeConcentrationUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VolumeConcentration.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VolumeConcentration.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VolumeConcentration.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumeConcentrationUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index cb9093f478..92907c4ed9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -276,40 +276,26 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 4.2)] + public void Parse(string culture, string quantityString, VolumeFlowPerAreaUnit expectedUnit, double expectedValue) { - try - { - var parsed = VolumeFlowPerArea.Parse("1 CFM/ft²", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinutePerSquareFoot, CubicFeetPerMinutePerSquareFootTolerance); - Assert.Equal(VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlowPerArea.Parse("1 m³/(s·m²)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecondPerSquareMeter, CubicMetersPerSecondPerSquareMeterTolerance); - Assert.Equal(VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = VolumeFlowPerArea.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, 4.2)] + [InlineData("en-US", "4.2 m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 4.2)] + public void TryParse(string culture, string quantityString, VolumeFlowPerAreaUnit expectedUnit, double expectedValue) { - { - Assert.True(VolumeFlowPerArea.TryParse("1 CFM/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinutePerSquareFoot, CubicFeetPerMinutePerSquareFootTolerance); - Assert.Equal(VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, parsed.Unit); - } - - { - Assert.True(VolumeFlowPerArea.TryParse("1 m³/(s·m²)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecondPerSquareMeter, CubicMetersPerSecondPerSquareMeterTolerance); - Assert.Equal(VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(VolumeFlowPerArea.TryParse(quantityString, out VolumeFlowPerArea parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -394,6 +380,28 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Volume Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, "CFM/ft²")] + [InlineData("en-US", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, "m³/(s·m²)")] + public void GetAbbreviationForCulture(string culture, VolumeFlowPerAreaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VolumeFlowPerArea.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VolumeFlowPerArea.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VolumeFlowPerArea.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumeFlowPerAreaUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index c5608b6c01..bbb3e26cce 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -714,2080 +714,362 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() - { - try - { - var parsed = VolumeFlow.Parse("1 af/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerDay, AcreFeetPerDayTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 af/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerHour, AcreFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 af/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerMinute, AcreFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 af/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerSecond, AcreFeetPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 сл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 сл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 сл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cm³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicCentimetersPerMinute, CubicCentimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 см³/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicCentimetersPerMinute, CubicCentimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dm³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дм³/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ft³/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerHour, CubicFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cf/hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerHour, CubicFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ft³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 CFM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ft³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerSecond, CubicFeetPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 m³/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerDay, CubicMetersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 m³/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerHour, CubicMetersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 м³/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerHour, CubicMetersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 m³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 м³/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 m³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 м³/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 mm³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMillimetersPerSecond, CubicMillimetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мм³/с", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMillimetersPerSecond, CubicMillimetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 cy/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerDay, CubicYardsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 yd³/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerHour, CubicYardsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 yd³/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerMinute, CubicYardsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 yd³/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerSecond, CubicYardsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dal/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dal/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 daLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dal/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 daLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дал/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dal/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 daLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дал/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dal/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 daLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дал/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 dLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 дл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 гл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 гл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 hLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 гл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 кл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 кл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 кл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 kgal (U.S.)/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilousGallonsPerMinute, KilousGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 KGPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilousGallonsPerMinute, KilousGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 l/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 l/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 LPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 l/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 LPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 л/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 l/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 LPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 л/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 l/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 LPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 л/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Ml/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerDay, MegalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Ml/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerDay, MegalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 MLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerDay, MegalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Ml/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerHour, MegalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 MLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerHour, MegalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Мл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerHour, MegalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Ml/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerMinute, MegalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 MLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerMinute, MegalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Мл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerMinute, MegalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Ml/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerSecond, MegalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 MLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerSecond, MegalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Мл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegalitersPerSecond, MegalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Mgal (U. K.)/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaukGallonsPerDay, MegaukGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Mgal (imp.)/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaukGallonsPerSecond, MegaukGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Mgpd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegausGallonsPerDay, MegausGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 Mgal/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegausGallonsPerDay, MegausGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мкл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мкл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 µLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мкл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ml/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerDay, MillilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ml/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerDay, MillilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 mLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerDay, MillilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ml/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerHour, MillilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 mLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerHour, MillilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerHour, MillilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ml/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerMinute, MillilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 mLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerMinute, MillilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerMinute, MillilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 ml/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerSecond, MillilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 mLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerSecond, MillilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 мл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MillilitersPerSecond, MillilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 MGD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillionUsGallonsPerDay, MillionUsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MillionUsGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nl/day", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nLPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nl/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nLPH", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 нл/ч", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nLPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 нл/мин", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 nLPS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 нл/c", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bbl/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerDay, OilBarrelsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 BOPD", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerDay, OilBarrelsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bbl/hr", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerHour, OilBarrelsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bph", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerHour, OilBarrelsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bbl/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bpm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 bbl/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerSecond, OilBarrelsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (U. K.)/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerDay, UkGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (imp.)/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerHour, UkGallonsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (imp.)/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerMinute, UkGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (imp.)/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerSecond, UkGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gpd", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerDay, UsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal/d", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerDay, UsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (U.S.)/h", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerHour, UsGallonsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (U.S.)/min", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 GPM", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumeFlow.Parse("1 gal (U.S.)/s", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerSecond, UsGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(VolumeFlow.TryParse("1 af/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerDay, AcreFeetPerDayTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 af/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerHour, AcreFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 af/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerMinute, AcreFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 af/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeetPerSecond, AcreFeetPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.AcreFootPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerDay, CentilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 сл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerHour, CentilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 сл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerMinute, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 сл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentilitersPerSecond, CentilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicCentimetersPerMinute, CubicCentimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 см³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicCentimetersPerMinute, CubicCentimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дм³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 ft³/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerHour, CubicFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cf/hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerHour, CubicFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 ft³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 CFM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 ft³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeetPerSecond, CubicFeetPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 m³/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerDay, CubicMetersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 m³/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerHour, CubicMetersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 м³/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerHour, CubicMetersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 m³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 м³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 m³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 м³/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 mm³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMillimetersPerSecond, CubicMillimetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 мм³/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMillimetersPerSecond, CubicMillimetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 cy/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerDay, CubicYardsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 yd³/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerHour, CubicYardsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 yd³/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerMinute, CubicYardsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 yd³/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerSecond, CubicYardsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dal/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dal/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 daLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerDay, DecalitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dal/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 daLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дал/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerHour, DecalitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dal/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 daLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дал/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerMinute, DecalitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dal/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 daLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дал/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecalitersPerSecond, DecalitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerDay, DecilitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerHour, DecilitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerMinute, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 dLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 дл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecilitersPerSecond, DecilitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerDay, HectolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 гл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerHour, HectolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 гл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerMinute, HectolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 hLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 гл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectolitersPerSecond, HectolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerDay, KilolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 кл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerHour, KilolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 кл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerMinute, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 кл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilolitersPerSecond, KilolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 kgal (U.S.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilousGallonsPerMinute, KilousGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 KGPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilousGallonsPerMinute, KilousGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 l/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 l/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 LPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerDay, LitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 l/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 LPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 л/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerHour, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 l/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 LPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 л/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMinute, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 l/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 LPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 л/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerSecond, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 Mgal (U. K.)/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaukGallonsPerDay, MegaukGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 Mgal (imp.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaukGallonsPerSecond, MegaukGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 Mgpd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegausGallonsPerDay, MegausGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 Mgal/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegausGallonsPerDay, MegausGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerDay, MicrolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 мкл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerHour, MicrolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 мкл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 µLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 мкл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrolitersPerSecond, MicrolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 MGD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillionUsGallonsPerDay, MillionUsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MillionUsGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nl/day", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nLPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerDay, NanolitersPerDayTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nl/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nLPH", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 нл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerHour, NanolitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nLPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 нл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerMinute, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 nLPS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 нл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanolitersPerSecond, NanolitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bbl/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerDay, OilBarrelsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 BOPD", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerDay, OilBarrelsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bbl/hr", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerHour, OilBarrelsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bph", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerHour, OilBarrelsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bbl/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bpm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 bbl/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerSecond, OilBarrelsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (U. K.)/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerDay, UkGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (imp.)/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerHour, UkGallonsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (imp.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerMinute, UkGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (imp.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UkGallonsPerSecond, UkGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.UkGallonPerSecond, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gpd", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerDay, UsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal/d", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerDay, UsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (U.S.)/h", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerHour, UsGallonsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerHour, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (U.S.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 GPM", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsed.Unit); - } - - { - Assert.True(VolumeFlow.TryParse("1 gal (U.S.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerSecond, UsGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 af/d", VolumeFlowUnit.AcreFootPerDay, 4.2)] + [InlineData("en-US", "4.2 af/h", VolumeFlowUnit.AcreFootPerHour, 4.2)] + [InlineData("en-US", "4.2 af/m", VolumeFlowUnit.AcreFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 af/s", VolumeFlowUnit.AcreFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 cl/day", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cl/d", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cLPD", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cl/h", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("en-US", "4.2 cLPH", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("en-US", "4.2 cl/min", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cLPM", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cl/s", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cLPS", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft³/h", VolumeFlowUnit.CubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 cf/hr", VolumeFlowUnit.CubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 ft³/min", VolumeFlowUnit.CubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 CFM", VolumeFlowUnit.CubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft³/s", VolumeFlowUnit.CubicFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 m³/d", VolumeFlowUnit.CubicMeterPerDay, 4.2)] + [InlineData("en-US", "4.2 m³/h", VolumeFlowUnit.CubicMeterPerHour, 4.2)] + [InlineData("en-US", "4.2 m³/min", VolumeFlowUnit.CubicMeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 m³/s", VolumeFlowUnit.CubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cy/day", VolumeFlowUnit.CubicYardPerDay, 4.2)] + [InlineData("en-US", "4.2 yd³/h", VolumeFlowUnit.CubicYardPerHour, 4.2)] + [InlineData("en-US", "4.2 yd³/min", VolumeFlowUnit.CubicYardPerMinute, 4.2)] + [InlineData("en-US", "4.2 yd³/s", VolumeFlowUnit.CubicYardPerSecond, 4.2)] + [InlineData("en-US", "4.2 dal/day", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dal/d", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 daLPD", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dal/h", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 daLPH", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dal/min", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 daLPM", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dal/s", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 daLPS", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dl/day", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dl/d", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dLPD", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dl/h", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dLPH", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dl/min", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dLPM", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dl/s", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dLPS", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 hl/day", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hl/d", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hLPD", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hl/h", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 hLPH", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 hl/min", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 hLPM", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 hl/s", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 hLPS", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kl/day", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kl/d", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kLPD", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kl/h", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("en-US", "4.2 kLPH", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("en-US", "4.2 kl/min", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 kLPM", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 kl/s", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kLPS", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 KGPM", VolumeFlowUnit.KilousGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 l/day", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 l/d", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 LPD", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 l/h", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("en-US", "4.2 LPH", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("en-US", "4.2 l/min", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("en-US", "4.2 LPM", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("en-US", "4.2 l/s", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 LPS", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Ml/day", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 Ml/d", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 MLPD", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 Ml/h", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 MLPH", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 Ml/min", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 MLPM", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 Ml/s", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 MLPS", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mgpd", VolumeFlowUnit.MegausGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 Mgal/d", VolumeFlowUnit.MegausGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/day", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/d", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µLPD", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/h", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("en-US", "4.2 µLPH", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("en-US", "4.2 µl/min", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 µLPM", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 µl/s", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 µLPS", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 ml/day", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 ml/d", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 mLPD", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 ml/h", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("en-US", "4.2 mLPH", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("en-US", "4.2 ml/min", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 mLPM", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 ml/s", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mLPS", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 MGD", VolumeFlowUnit.MillionUsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/day", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/d", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nLPD", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/h", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 nLPH", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 nl/min", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 nLPM", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 nl/s", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 nLPS", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 bbl/d", VolumeFlowUnit.OilBarrelPerDay, 4.2)] + [InlineData("en-US", "4.2 BOPD", VolumeFlowUnit.OilBarrelPerDay, 4.2)] + [InlineData("en-US", "4.2 bbl/hr", VolumeFlowUnit.OilBarrelPerHour, 4.2)] + [InlineData("en-US", "4.2 bph", VolumeFlowUnit.OilBarrelPerHour, 4.2)] + [InlineData("en-US", "4.2 bbl/min", VolumeFlowUnit.OilBarrelPerMinute, 4.2)] + [InlineData("en-US", "4.2 bpm", VolumeFlowUnit.OilBarrelPerMinute, 4.2)] + [InlineData("en-US", "4.2 bbl/s", VolumeFlowUnit.OilBarrelPerSecond, 4.2)] + [InlineData("en-US", "4.2 gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond, 4.2)] + [InlineData("en-US", "4.2 gpd", VolumeFlowUnit.UsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal/d", VolumeFlowUnit.UsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 GPM", VolumeFlowUnit.UsGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 сл/ч", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 сл/мин", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 сл/c", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м³/ч", VolumeFlowUnit.CubicMeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 м³/мин", VolumeFlowUnit.CubicMeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м³/с", VolumeFlowUnit.CubicMeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дал/ч", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 дал/мин", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дал/c", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дл/ч", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 дл/мин", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дл/c", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 гл/ч", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 гл/мин", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 гл/c", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 кл/ч", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 кл/мин", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 кл/c", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 л/ч", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 л/мин", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 л/c", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мл/ч", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 Мл/мин", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мл/c", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкл/ч", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мкл/мин", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мкл/c", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мл/ч", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мл/мин", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мл/c", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нл/ч", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 нл/мин", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 нл/c", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + public void Parse(string culture, string quantityString, VolumeFlowUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + var parsed = VolumeFlow.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("en-US", "4.2 af/d", VolumeFlowUnit.AcreFootPerDay, 4.2)] + [InlineData("en-US", "4.2 af/h", VolumeFlowUnit.AcreFootPerHour, 4.2)] + [InlineData("en-US", "4.2 af/m", VolumeFlowUnit.AcreFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 af/s", VolumeFlowUnit.AcreFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 cl/day", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cl/d", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cLPD", VolumeFlowUnit.CentiliterPerDay, 4.2)] + [InlineData("en-US", "4.2 cl/h", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("en-US", "4.2 cLPH", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("en-US", "4.2 cl/min", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cLPM", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 cl/s", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cLPS", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft³/h", VolumeFlowUnit.CubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 cf/hr", VolumeFlowUnit.CubicFootPerHour, 4.2)] + [InlineData("en-US", "4.2 ft³/min", VolumeFlowUnit.CubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 CFM", VolumeFlowUnit.CubicFootPerMinute, 4.2)] + [InlineData("en-US", "4.2 ft³/s", VolumeFlowUnit.CubicFootPerSecond, 4.2)] + [InlineData("en-US", "4.2 m³/d", VolumeFlowUnit.CubicMeterPerDay, 4.2)] + [InlineData("en-US", "4.2 m³/h", VolumeFlowUnit.CubicMeterPerHour, 4.2)] + [InlineData("en-US", "4.2 m³/min", VolumeFlowUnit.CubicMeterPerMinute, 4.2)] + [InlineData("en-US", "4.2 m³/s", VolumeFlowUnit.CubicMeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond, 4.2)] + [InlineData("en-US", "4.2 cy/day", VolumeFlowUnit.CubicYardPerDay, 4.2)] + [InlineData("en-US", "4.2 yd³/h", VolumeFlowUnit.CubicYardPerHour, 4.2)] + [InlineData("en-US", "4.2 yd³/min", VolumeFlowUnit.CubicYardPerMinute, 4.2)] + [InlineData("en-US", "4.2 yd³/s", VolumeFlowUnit.CubicYardPerSecond, 4.2)] + [InlineData("en-US", "4.2 dal/day", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dal/d", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 daLPD", VolumeFlowUnit.DecaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dal/h", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 daLPH", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dal/min", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 daLPM", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dal/s", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 daLPS", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dl/day", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dl/d", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dLPD", VolumeFlowUnit.DeciliterPerDay, 4.2)] + [InlineData("en-US", "4.2 dl/h", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dLPH", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("en-US", "4.2 dl/min", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dLPM", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 dl/s", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 dLPS", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 hl/day", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hl/d", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hLPD", VolumeFlowUnit.HectoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 hl/h", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 hLPH", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 hl/min", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 hLPM", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 hl/s", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 hLPS", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kl/day", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kl/d", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kLPD", VolumeFlowUnit.KiloliterPerDay, 4.2)] + [InlineData("en-US", "4.2 kl/h", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("en-US", "4.2 kLPH", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("en-US", "4.2 kl/min", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 kLPM", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 kl/s", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kLPS", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 KGPM", VolumeFlowUnit.KilousGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 l/day", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 l/d", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 LPD", VolumeFlowUnit.LiterPerDay, 4.2)] + [InlineData("en-US", "4.2 l/h", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("en-US", "4.2 LPH", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("en-US", "4.2 l/min", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("en-US", "4.2 LPM", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("en-US", "4.2 l/s", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 LPS", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Ml/day", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 Ml/d", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 MLPD", VolumeFlowUnit.MegaliterPerDay, 4.2)] + [InlineData("en-US", "4.2 Ml/h", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 MLPH", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("en-US", "4.2 Ml/min", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 MLPM", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 Ml/s", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 MLPS", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond, 4.2)] + [InlineData("en-US", "4.2 Mgpd", VolumeFlowUnit.MegausGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 Mgal/d", VolumeFlowUnit.MegausGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/day", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/d", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µLPD", VolumeFlowUnit.MicroliterPerDay, 4.2)] + [InlineData("en-US", "4.2 µl/h", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("en-US", "4.2 µLPH", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("en-US", "4.2 µl/min", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 µLPM", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 µl/s", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 µLPS", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 ml/day", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 ml/d", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 mLPD", VolumeFlowUnit.MilliliterPerDay, 4.2)] + [InlineData("en-US", "4.2 ml/h", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("en-US", "4.2 mLPH", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("en-US", "4.2 ml/min", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 mLPM", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 ml/s", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 mLPS", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 MGD", VolumeFlowUnit.MillionUsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/day", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/d", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nLPD", VolumeFlowUnit.NanoliterPerDay, 4.2)] + [InlineData("en-US", "4.2 nl/h", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 nLPH", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("en-US", "4.2 nl/min", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 nLPM", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("en-US", "4.2 nl/s", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 nLPS", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + [InlineData("en-US", "4.2 bbl/d", VolumeFlowUnit.OilBarrelPerDay, 4.2)] + [InlineData("en-US", "4.2 BOPD", VolumeFlowUnit.OilBarrelPerDay, 4.2)] + [InlineData("en-US", "4.2 bbl/hr", VolumeFlowUnit.OilBarrelPerHour, 4.2)] + [InlineData("en-US", "4.2 bph", VolumeFlowUnit.OilBarrelPerHour, 4.2)] + [InlineData("en-US", "4.2 bbl/min", VolumeFlowUnit.OilBarrelPerMinute, 4.2)] + [InlineData("en-US", "4.2 bpm", VolumeFlowUnit.OilBarrelPerMinute, 4.2)] + [InlineData("en-US", "4.2 bbl/s", VolumeFlowUnit.OilBarrelPerSecond, 4.2)] + [InlineData("en-US", "4.2 gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond, 4.2)] + [InlineData("en-US", "4.2 gpd", VolumeFlowUnit.UsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal/d", VolumeFlowUnit.UsGallonPerDay, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 GPM", VolumeFlowUnit.UsGallonPerMinute, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 сл/ч", VolumeFlowUnit.CentiliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 сл/мин", VolumeFlowUnit.CentiliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 сл/c", VolumeFlowUnit.CentiliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м³/ч", VolumeFlowUnit.CubicMeterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 м³/мин", VolumeFlowUnit.CubicMeterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 м³/с", VolumeFlowUnit.CubicMeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дал/ч", VolumeFlowUnit.DecaliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 дал/мин", VolumeFlowUnit.DecaliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дал/c", VolumeFlowUnit.DecaliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 дл/ч", VolumeFlowUnit.DeciliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 дл/мин", VolumeFlowUnit.DeciliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 дл/c", VolumeFlowUnit.DeciliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 гл/ч", VolumeFlowUnit.HectoliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 гл/мин", VolumeFlowUnit.HectoliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 гл/c", VolumeFlowUnit.HectoliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 кл/ч", VolumeFlowUnit.KiloliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 кл/мин", VolumeFlowUnit.KiloliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 кл/c", VolumeFlowUnit.KiloliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 л/ч", VolumeFlowUnit.LiterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 л/мин", VolumeFlowUnit.LiterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 л/c", VolumeFlowUnit.LiterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 Мл/ч", VolumeFlowUnit.MegaliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 Мл/мин", VolumeFlowUnit.MegaliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 Мл/c", VolumeFlowUnit.MegaliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мкл/ч", VolumeFlowUnit.MicroliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мкл/мин", VolumeFlowUnit.MicroliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мкл/c", VolumeFlowUnit.MicroliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 мл/ч", VolumeFlowUnit.MilliliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 мл/мин", VolumeFlowUnit.MilliliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 мл/c", VolumeFlowUnit.MilliliterPerSecond, 4.2)] + [InlineData("ru-RU", "4,2 нл/ч", VolumeFlowUnit.NanoliterPerHour, 4.2)] + [InlineData("ru-RU", "4,2 нл/мин", VolumeFlowUnit.NanoliterPerMinute, 4.2)] + [InlineData("ru-RU", "4,2 нл/c", VolumeFlowUnit.NanoliterPerSecond, 4.2)] + public void TryParse(string culture, string quantityString, VolumeFlowUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(VolumeFlow.TryParse(quantityString, out VolumeFlow parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -4072,6 +2354,137 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Volume Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VolumeFlowUnit.AcreFootPerDay, "af/d")] + [InlineData("en-US", VolumeFlowUnit.AcreFootPerHour, "af/h")] + [InlineData("en-US", VolumeFlowUnit.AcreFootPerMinute, "af/m")] + [InlineData("en-US", VolumeFlowUnit.AcreFootPerSecond, "af/s")] + [InlineData("en-US", VolumeFlowUnit.CentiliterPerDay, "cl/day")] + [InlineData("en-US", VolumeFlowUnit.CentiliterPerHour, "cl/h")] + [InlineData("en-US", VolumeFlowUnit.CentiliterPerMinute, "cl/min")] + [InlineData("en-US", VolumeFlowUnit.CentiliterPerSecond, "cl/s")] + [InlineData("en-US", VolumeFlowUnit.CubicCentimeterPerMinute, "cm³/min")] + [InlineData("en-US", VolumeFlowUnit.CubicDecimeterPerMinute, "dm³/min")] + [InlineData("en-US", VolumeFlowUnit.CubicFootPerHour, "ft³/h")] + [InlineData("en-US", VolumeFlowUnit.CubicFootPerMinute, "ft³/min")] + [InlineData("en-US", VolumeFlowUnit.CubicFootPerSecond, "ft³/s")] + [InlineData("en-US", VolumeFlowUnit.CubicMeterPerDay, "m³/d")] + [InlineData("en-US", VolumeFlowUnit.CubicMeterPerHour, "m³/h")] + [InlineData("en-US", VolumeFlowUnit.CubicMeterPerMinute, "m³/min")] + [InlineData("en-US", VolumeFlowUnit.CubicMeterPerSecond, "m³/s")] + [InlineData("en-US", VolumeFlowUnit.CubicMillimeterPerSecond, "mm³/s")] + [InlineData("en-US", VolumeFlowUnit.CubicYardPerDay, "cy/day")] + [InlineData("en-US", VolumeFlowUnit.CubicYardPerHour, "yd³/h")] + [InlineData("en-US", VolumeFlowUnit.CubicYardPerMinute, "yd³/min")] + [InlineData("en-US", VolumeFlowUnit.CubicYardPerSecond, "yd³/s")] + [InlineData("en-US", VolumeFlowUnit.DecaliterPerDay, "dal/day")] + [InlineData("en-US", VolumeFlowUnit.DecaliterPerHour, "dal/h")] + [InlineData("en-US", VolumeFlowUnit.DecaliterPerMinute, "dal/min")] + [InlineData("en-US", VolumeFlowUnit.DecaliterPerSecond, "dal/s")] + [InlineData("en-US", VolumeFlowUnit.DeciliterPerDay, "dl/day")] + [InlineData("en-US", VolumeFlowUnit.DeciliterPerHour, "dl/h")] + [InlineData("en-US", VolumeFlowUnit.DeciliterPerMinute, "dl/min")] + [InlineData("en-US", VolumeFlowUnit.DeciliterPerSecond, "dl/s")] + [InlineData("en-US", VolumeFlowUnit.HectoliterPerDay, "hl/day")] + [InlineData("en-US", VolumeFlowUnit.HectoliterPerHour, "hl/h")] + [InlineData("en-US", VolumeFlowUnit.HectoliterPerMinute, "hl/min")] + [InlineData("en-US", VolumeFlowUnit.HectoliterPerSecond, "hl/s")] + [InlineData("en-US", VolumeFlowUnit.KiloliterPerDay, "kl/day")] + [InlineData("en-US", VolumeFlowUnit.KiloliterPerHour, "kl/h")] + [InlineData("en-US", VolumeFlowUnit.KiloliterPerMinute, "kl/min")] + [InlineData("en-US", VolumeFlowUnit.KiloliterPerSecond, "kl/s")] + [InlineData("en-US", VolumeFlowUnit.KilousGallonPerMinute, "kgal (U.S.)/min")] + [InlineData("en-US", VolumeFlowUnit.LiterPerDay, "l/day")] + [InlineData("en-US", VolumeFlowUnit.LiterPerHour, "l/h")] + [InlineData("en-US", VolumeFlowUnit.LiterPerMinute, "l/min")] + [InlineData("en-US", VolumeFlowUnit.LiterPerSecond, "l/s")] + [InlineData("en-US", VolumeFlowUnit.MegaliterPerDay, "Ml/day")] + [InlineData("en-US", VolumeFlowUnit.MegaliterPerHour, "Ml/h")] + [InlineData("en-US", VolumeFlowUnit.MegaliterPerMinute, "Ml/min")] + [InlineData("en-US", VolumeFlowUnit.MegaliterPerSecond, "Ml/s")] + [InlineData("en-US", VolumeFlowUnit.MegaukGallonPerDay, "Mgal (U. K.)/d")] + [InlineData("en-US", VolumeFlowUnit.MegaukGallonPerSecond, "Mgal (imp.)/s")] + [InlineData("en-US", VolumeFlowUnit.MegausGallonPerDay, "Mgpd")] + [InlineData("en-US", VolumeFlowUnit.MicroliterPerDay, "µl/day")] + [InlineData("en-US", VolumeFlowUnit.MicroliterPerHour, "µl/h")] + [InlineData("en-US", VolumeFlowUnit.MicroliterPerMinute, "µl/min")] + [InlineData("en-US", VolumeFlowUnit.MicroliterPerSecond, "µl/s")] + [InlineData("en-US", VolumeFlowUnit.MilliliterPerDay, "ml/day")] + [InlineData("en-US", VolumeFlowUnit.MilliliterPerHour, "ml/h")] + [InlineData("en-US", VolumeFlowUnit.MilliliterPerMinute, "ml/min")] + [InlineData("en-US", VolumeFlowUnit.MilliliterPerSecond, "ml/s")] + [InlineData("en-US", VolumeFlowUnit.MillionUsGallonPerDay, "MGD")] + [InlineData("en-US", VolumeFlowUnit.NanoliterPerDay, "nl/day")] + [InlineData("en-US", VolumeFlowUnit.NanoliterPerHour, "nl/h")] + [InlineData("en-US", VolumeFlowUnit.NanoliterPerMinute, "nl/min")] + [InlineData("en-US", VolumeFlowUnit.NanoliterPerSecond, "nl/s")] + [InlineData("en-US", VolumeFlowUnit.OilBarrelPerDay, "bbl/d")] + [InlineData("en-US", VolumeFlowUnit.OilBarrelPerHour, "bbl/hr")] + [InlineData("en-US", VolumeFlowUnit.OilBarrelPerMinute, "bbl/min")] + [InlineData("en-US", VolumeFlowUnit.OilBarrelPerSecond, "bbl/s")] + [InlineData("en-US", VolumeFlowUnit.UkGallonPerDay, "gal (U. K.)/d")] + [InlineData("en-US", VolumeFlowUnit.UkGallonPerHour, "gal (imp.)/h")] + [InlineData("en-US", VolumeFlowUnit.UkGallonPerMinute, "gal (imp.)/min")] + [InlineData("en-US", VolumeFlowUnit.UkGallonPerSecond, "gal (imp.)/s")] + [InlineData("en-US", VolumeFlowUnit.UsGallonPerDay, "gpd")] + [InlineData("en-US", VolumeFlowUnit.UsGallonPerHour, "gal (U.S.)/h")] + [InlineData("en-US", VolumeFlowUnit.UsGallonPerMinute, "gal (U.S.)/min")] + [InlineData("en-US", VolumeFlowUnit.UsGallonPerSecond, "gal (U.S.)/s")] + [InlineData("ru-RU", VolumeFlowUnit.CentiliterPerHour, "сл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.CentiliterPerMinute, "сл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.CentiliterPerSecond, "сл/c")] + [InlineData("ru-RU", VolumeFlowUnit.CubicCentimeterPerMinute, "см³/мин")] + [InlineData("ru-RU", VolumeFlowUnit.CubicDecimeterPerMinute, "дм³/мин")] + [InlineData("ru-RU", VolumeFlowUnit.CubicMeterPerHour, "м³/ч")] + [InlineData("ru-RU", VolumeFlowUnit.CubicMeterPerMinute, "м³/мин")] + [InlineData("ru-RU", VolumeFlowUnit.CubicMeterPerSecond, "м³/с")] + [InlineData("ru-RU", VolumeFlowUnit.CubicMillimeterPerSecond, "мм³/с")] + [InlineData("ru-RU", VolumeFlowUnit.DecaliterPerHour, "дал/ч")] + [InlineData("ru-RU", VolumeFlowUnit.DecaliterPerMinute, "дал/мин")] + [InlineData("ru-RU", VolumeFlowUnit.DecaliterPerSecond, "дал/c")] + [InlineData("ru-RU", VolumeFlowUnit.DeciliterPerHour, "дл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.DeciliterPerMinute, "дл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.DeciliterPerSecond, "дл/c")] + [InlineData("ru-RU", VolumeFlowUnit.HectoliterPerHour, "гл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.HectoliterPerMinute, "гл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.HectoliterPerSecond, "гл/c")] + [InlineData("ru-RU", VolumeFlowUnit.KiloliterPerHour, "кл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.KiloliterPerMinute, "кл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.KiloliterPerSecond, "кл/c")] + [InlineData("ru-RU", VolumeFlowUnit.LiterPerHour, "л/ч")] + [InlineData("ru-RU", VolumeFlowUnit.LiterPerMinute, "л/мин")] + [InlineData("ru-RU", VolumeFlowUnit.LiterPerSecond, "л/c")] + [InlineData("ru-RU", VolumeFlowUnit.MegaliterPerHour, "Мл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.MegaliterPerMinute, "Мл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.MegaliterPerSecond, "Мл/c")] + [InlineData("ru-RU", VolumeFlowUnit.MicroliterPerHour, "мкл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.MicroliterPerMinute, "мкл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.MicroliterPerSecond, "мкл/c")] + [InlineData("ru-RU", VolumeFlowUnit.MilliliterPerHour, "мл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.MilliliterPerMinute, "мл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.MilliliterPerSecond, "мл/c")] + [InlineData("ru-RU", VolumeFlowUnit.NanoliterPerHour, "нл/ч")] + [InlineData("ru-RU", VolumeFlowUnit.NanoliterPerMinute, "нл/мин")] + [InlineData("ru-RU", VolumeFlowUnit.NanoliterPerSecond, "нл/c")] + public void GetAbbreviationForCulture(string culture, VolumeFlowUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VolumeFlow.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VolumeFlow.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VolumeFlow.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumeFlowUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index de0e4c6336..f6f143c7a3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 m³/m", VolumePerLengthUnit.CubicMeterPerMeter, 4.2)] + [InlineData("en-US", "4.2 yd³/ft", VolumePerLengthUnit.CubicYardPerFoot, 4.2)] + [InlineData("en-US", "4.2 yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile, 4.2)] + [InlineData("en-US", "4.2 l/km", VolumePerLengthUnit.LiterPerKilometer, 4.2)] + [InlineData("en-US", "4.2 l/m", VolumePerLengthUnit.LiterPerMeter, 4.2)] + [InlineData("en-US", "4.2 l/mm", VolumePerLengthUnit.LiterPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile, 4.2)] + public void Parse(string culture, string quantityString, VolumePerLengthUnit expectedUnit, double expectedValue) { - try - { - var parsed = VolumePerLength.Parse("1 m³/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMeter, CubicMetersPerMeterTolerance); - Assert.Equal(VolumePerLengthUnit.CubicMeterPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 yd³/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerFoot, CubicYardsPerFootTolerance); - Assert.Equal(VolumePerLengthUnit.CubicYardPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 yd³/ftUS", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerUsSurveyFoot, CubicYardsPerUsSurveyFootTolerance); - Assert.Equal(VolumePerLengthUnit.CubicYardPerUsSurveyFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 gal (imp.)/mi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialGallonsPerMile, ImperialGallonsPerMileTolerance); - Assert.Equal(VolumePerLengthUnit.ImperialGallonPerMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 l/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerKilometer, LitersPerKilometerTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 l/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerMeter, LitersPerMeterTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 l/mm", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.LitersPerMillimeter, LitersPerMillimeterTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 bbl/ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerFoot, OilBarrelsPerFootTolerance); - Assert.Equal(VolumePerLengthUnit.OilBarrelPerFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumePerLength.Parse("1 gal (U.S.)/mi", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMile, UsGallonsPerMileTolerance); - Assert.Equal(VolumePerLengthUnit.UsGallonPerMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = VolumePerLength.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 m³/m", VolumePerLengthUnit.CubicMeterPerMeter, 4.2)] + [InlineData("en-US", "4.2 yd³/ft", VolumePerLengthUnit.CubicYardPerFoot, 4.2)] + [InlineData("en-US", "4.2 yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile, 4.2)] + [InlineData("en-US", "4.2 l/km", VolumePerLengthUnit.LiterPerKilometer, 4.2)] + [InlineData("en-US", "4.2 l/m", VolumePerLengthUnit.LiterPerMeter, 4.2)] + [InlineData("en-US", "4.2 l/mm", VolumePerLengthUnit.LiterPerMillimeter, 4.2)] + [InlineData("en-US", "4.2 bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile, 4.2)] + public void TryParse(string culture, string quantityString, VolumePerLengthUnit expectedUnit, double expectedValue) { - { - Assert.True(VolumePerLength.TryParse("1 m³/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMetersPerMeter, CubicMetersPerMeterTolerance); - Assert.Equal(VolumePerLengthUnit.CubicMeterPerMeter, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 yd³/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerFoot, CubicYardsPerFootTolerance); - Assert.Equal(VolumePerLengthUnit.CubicYardPerFoot, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 yd³/ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYardsPerUsSurveyFoot, CubicYardsPerUsSurveyFootTolerance); - Assert.Equal(VolumePerLengthUnit.CubicYardPerUsSurveyFoot, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 gal (imp.)/mi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialGallonsPerMile, ImperialGallonsPerMileTolerance); - Assert.Equal(VolumePerLengthUnit.ImperialGallonPerMile, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 l/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerKilometer, LitersPerKilometerTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerKilometer, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 l/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMeter, LitersPerMeterTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerMeter, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 l/mm", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.LitersPerMillimeter, LitersPerMillimeterTolerance); - Assert.Equal(VolumePerLengthUnit.LiterPerMillimeter, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 bbl/ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrelsPerFoot, OilBarrelsPerFootTolerance); - Assert.Equal(VolumePerLengthUnit.OilBarrelPerFoot, parsed.Unit); - } - - { - Assert.True(VolumePerLength.TryParse("1 gal (U.S.)/mi", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallonsPerMile, UsGallonsPerMileTolerance); - Assert.Equal(VolumePerLengthUnit.UsGallonPerMile, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(VolumePerLength.TryParse(quantityString, out VolumePerLength parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Volume Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VolumePerLengthUnit.CubicMeterPerMeter, "m³/m")] + [InlineData("en-US", VolumePerLengthUnit.CubicYardPerFoot, "yd³/ft")] + [InlineData("en-US", VolumePerLengthUnit.CubicYardPerUsSurveyFoot, "yd³/ftUS")] + [InlineData("en-US", VolumePerLengthUnit.ImperialGallonPerMile, "gal (imp.)/mi")] + [InlineData("en-US", VolumePerLengthUnit.LiterPerKilometer, "l/km")] + [InlineData("en-US", VolumePerLengthUnit.LiterPerMeter, "l/m")] + [InlineData("en-US", VolumePerLengthUnit.LiterPerMillimeter, "l/mm")] + [InlineData("en-US", VolumePerLengthUnit.OilBarrelPerFoot, "bbl/ft")] + [InlineData("en-US", VolumePerLengthUnit.UsGallonPerMile, "gal (U.S.)/mi")] + public void GetAbbreviationForCulture(string culture, VolumePerLengthUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VolumePerLength.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VolumePerLength.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VolumePerLength.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumePerLengthUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index 6f6446f3c9..40a0f36d8e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -588,1359 +588,244 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() - { - try - { - var parsed = Volume.Parse("1 ac-ft", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 acre-foot", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 acre-feet", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 tablespoon (A.U.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.AuTablespoons, AuTablespoonsTolerance); - Assert.Equal(VolumeUnit.AuTablespoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 bf", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 board foot", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 board feet", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pmp", CultureInfo.GetCultureInfo("fr-CA")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pied-planche", CultureInfo.GetCultureInfo("fr-CA")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pied de planche", CultureInfo.GetCultureInfo("fr-CA")); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 cl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Centiliters, CentilitersTolerance); - Assert.Equal(VolumeUnit.Centiliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 сл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Centiliters, CentilitersTolerance); - Assert.Equal(VolumeUnit.Centiliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 cm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicCentimeters, CubicCentimetersTolerance); - Assert.Equal(VolumeUnit.CubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 см³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicCentimeters, CubicCentimetersTolerance); - Assert.Equal(VolumeUnit.CubicCentimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 dm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicDecimeters, CubicDecimetersTolerance); - Assert.Equal(VolumeUnit.CubicDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 дм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicDecimeters, CubicDecimetersTolerance); - Assert.Equal(VolumeUnit.CubicDecimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 ft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicFeet, CubicFeetTolerance); - Assert.Equal(VolumeUnit.CubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 фут³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicFeet, CubicFeetTolerance); - Assert.Equal(VolumeUnit.CubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 hm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicHectometers, CubicHectometersTolerance); - Assert.Equal(VolumeUnit.CubicHectometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 гм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicHectometers, CubicHectometersTolerance); - Assert.Equal(VolumeUnit.CubicHectometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 in³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicInches, CubicInchesTolerance); - Assert.Equal(VolumeUnit.CubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 дюйм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicInches, CubicInchesTolerance); - Assert.Equal(VolumeUnit.CubicInch, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 km³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicKilometers, CubicKilometersTolerance); - Assert.Equal(VolumeUnit.CubicKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 км³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicKilometers, CubicKilometersTolerance); - Assert.Equal(VolumeUnit.CubicKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 m³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMeters, CubicMetersTolerance); - Assert.Equal(VolumeUnit.CubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 м³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMeters, CubicMetersTolerance); - Assert.Equal(VolumeUnit.CubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 µm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMicrometers, CubicMicrometersTolerance); - Assert.Equal(VolumeUnit.CubicMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 мкм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMicrometers, CubicMicrometersTolerance); - Assert.Equal(VolumeUnit.CubicMicrometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 mi³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMiles, CubicMilesTolerance); - Assert.Equal(VolumeUnit.CubicMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 миля³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMiles, CubicMilesTolerance); - Assert.Equal(VolumeUnit.CubicMile, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 mm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicMillimeters, CubicMillimetersTolerance); - Assert.Equal(VolumeUnit.CubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 мм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicMillimeters, CubicMillimetersTolerance); - Assert.Equal(VolumeUnit.CubicMillimeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 yd³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CubicYards, CubicYardsTolerance); - Assert.Equal(VolumeUnit.CubicYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 ярд³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.CubicYards, CubicYardsTolerance); - Assert.Equal(VolumeUnit.CubicYard, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 dal", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Decaliters, DecalitersTolerance); - Assert.Equal(VolumeUnit.Decaliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 дал", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Decaliters, DecalitersTolerance); - Assert.Equal(VolumeUnit.Decaliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 dagal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecausGallons, DecausGallonsTolerance); - Assert.Equal(VolumeUnit.DecausGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 даАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DecausGallons, DecausGallonsTolerance); - Assert.Equal(VolumeUnit.DecausGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 dl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Deciliters, DecilitersTolerance); - Assert.Equal(VolumeUnit.Deciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 дл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Deciliters, DecilitersTolerance); - Assert.Equal(VolumeUnit.Deciliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 dgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DeciusGallons, DeciusGallonsTolerance); - Assert.Equal(VolumeUnit.DeciusGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 дАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.DeciusGallons, DeciusGallonsTolerance); - Assert.Equal(VolumeUnit.DeciusGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 hft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectocubicFeet, HectocubicFeetTolerance); - Assert.Equal(VolumeUnit.HectocubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 гфут³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectocubicFeet, HectocubicFeetTolerance); - Assert.Equal(VolumeUnit.HectocubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 hm³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectocubicMeters, HectocubicMetersTolerance); - Assert.Equal(VolumeUnit.HectocubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 гм³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectocubicMeters, HectocubicMetersTolerance); - Assert.Equal(VolumeUnit.HectocubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 hl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Hectoliters, HectolitersTolerance); - Assert.Equal(VolumeUnit.Hectoliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 гл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Hectoliters, HectolitersTolerance); - Assert.Equal(VolumeUnit.Hectoliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 hgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.HectousGallons, HectousGallonsTolerance); - Assert.Equal(VolumeUnit.HectousGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 гАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.HectousGallons, HectousGallonsTolerance); - Assert.Equal(VolumeUnit.HectousGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 bl (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialBeerBarrels, ImperialBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.ImperialBeerBarrel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 gal (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialGallons, ImperialGallonsTolerance); - Assert.Equal(VolumeUnit.ImperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Английский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ImperialGallons, ImperialGallonsTolerance); - Assert.Equal(VolumeUnit.ImperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 oz (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialOunces, ImperialOuncesTolerance); - Assert.Equal(VolumeUnit.ImperialOunce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Английская унция", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.ImperialOunces, ImperialOuncesTolerance); - Assert.Equal(VolumeUnit.ImperialOunce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pt (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 UK pt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pt", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 p", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - 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")); - AssertEx.EqualTolerance(1, parsed.KilocubicFeet, KilocubicFeetTolerance); - Assert.Equal(VolumeUnit.KilocubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 кфут³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilocubicFeet, KilocubicFeetTolerance); - Assert.Equal(VolumeUnit.KilocubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 km³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocubicMeters, KilocubicMetersTolerance); - Assert.Equal(VolumeUnit.KilocubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 км³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilocubicMeters, KilocubicMetersTolerance); - Assert.Equal(VolumeUnit.KilocubicMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 kgal (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KiloimperialGallons, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 кАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KiloimperialGallons, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 kl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kiloliters, KilolitersTolerance); - Assert.Equal(VolumeUnit.Kiloliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 кл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Kiloliters, KilolitersTolerance); - Assert.Equal(VolumeUnit.Kiloliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 kgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilousGallons, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 кАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.KilousGallons, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 l", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Liters, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 л", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Liters, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Mft³", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegacubicFeet, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Мфут³", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegacubicFeet, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Mgal (imp.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegaimperialGallons, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 МАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegaimperialGallons, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megaliters, MegalitersTolerance); - Assert.Equal(VolumeUnit.Megaliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Megaliters, MegalitersTolerance); - Assert.Equal(VolumeUnit.Megaliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Mgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegausGallons, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 МАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.MegausGallons, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 metric cup", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricCups, MetricCupsTolerance); - Assert.Equal(VolumeUnit.MetricCup, 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.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, 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.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 ts", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 tspn", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, 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.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 ts.", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, 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.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 tspn.", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 teaspoon", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 µl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 мкл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 ml", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Milliliters, MillilitersTolerance); - Assert.Equal(VolumeUnit.Milliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 мл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Milliliters, MillilitersTolerance); - Assert.Equal(VolumeUnit.Milliliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 nl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 нл", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 bbl", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.OilBarrels, OilBarrelsTolerance); - Assert.Equal(VolumeUnit.OilBarrel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 tablespoon (U.K.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UkTablespoons, UkTablespoonsTolerance); - Assert.Equal(VolumeUnit.UkTablespoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 bl (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsBeerBarrels, UsBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.UsBeerBarrel, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 cup (U.S. customary)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsCustomaryCups, UsCustomaryCupsTolerance); - Assert.Equal(VolumeUnit.UsCustomaryCup, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 gal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Американский галлон", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 cup (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsLegalCups, UsLegalCupsTolerance); - Assert.Equal(VolumeUnit.UsLegalCup, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 oz (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 Американская унция", CultureInfo.GetCultureInfo("ru-RU")); - AssertEx.EqualTolerance(1, parsed.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 pt (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsPints, UsPintsTolerance); - Assert.Equal(VolumeUnit.UsPint, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 qt (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsQuarts, UsQuartsTolerance); - Assert.Equal(VolumeUnit.UsQuart, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 tablespoon (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsTablespoons, UsTablespoonsTolerance); - Assert.Equal(VolumeUnit.UsTablespoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Volume.Parse("1 teaspoon (U.S.)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.UsTeaspoons, UsTeaspoonsTolerance); - Assert.Equal(VolumeUnit.UsTeaspoon, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(Volume.TryParse("1 ac-ft", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 acre-foot", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 acre-feet", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AcreFeet, AcreFeetTolerance); - Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 tablespoon (A.U.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.AuTablespoons, AuTablespoonsTolerance); - Assert.Equal(VolumeUnit.AuTablespoon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 bf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 board foot", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 board feet", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pmp", CultureInfo.GetCultureInfo("fr-CA"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pied-planche", CultureInfo.GetCultureInfo("fr-CA"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pied de planche", CultureInfo.GetCultureInfo("fr-CA"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); - Assert.Equal(VolumeUnit.BoardFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 cl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centiliters, CentilitersTolerance); - Assert.Equal(VolumeUnit.Centiliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 сл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Centiliters, CentilitersTolerance); - Assert.Equal(VolumeUnit.Centiliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 cm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicCentimeters, CubicCentimetersTolerance); - Assert.Equal(VolumeUnit.CubicCentimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicCentimeters, CubicCentimetersTolerance); - Assert.Equal(VolumeUnit.CubicCentimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 dm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicDecimeters, CubicDecimetersTolerance); - Assert.Equal(VolumeUnit.CubicDecimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 дм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicDecimeters, CubicDecimetersTolerance); - Assert.Equal(VolumeUnit.CubicDecimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 ft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeet, CubicFeetTolerance); - Assert.Equal(VolumeUnit.CubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 фут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicFeet, CubicFeetTolerance); - Assert.Equal(VolumeUnit.CubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 in³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicInches, CubicInchesTolerance); - Assert.Equal(VolumeUnit.CubicInch, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 дюйм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicInches, CubicInchesTolerance); - Assert.Equal(VolumeUnit.CubicInch, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 m³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMeters, CubicMetersTolerance); - Assert.Equal(VolumeUnit.CubicMeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMeters, CubicMetersTolerance); - Assert.Equal(VolumeUnit.CubicMeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 µm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMicrometers, CubicMicrometersTolerance); - Assert.Equal(VolumeUnit.CubicMicrometer, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 мкм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMicrometers, CubicMicrometersTolerance); - Assert.Equal(VolumeUnit.CubicMicrometer, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 mi³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMiles, CubicMilesTolerance); - Assert.Equal(VolumeUnit.CubicMile, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 миля³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMiles, CubicMilesTolerance); - Assert.Equal(VolumeUnit.CubicMile, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 mm³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMillimeters, CubicMillimetersTolerance); - Assert.Equal(VolumeUnit.CubicMillimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 мм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicMillimeters, CubicMillimetersTolerance); - Assert.Equal(VolumeUnit.CubicMillimeter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 yd³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYards, CubicYardsTolerance); - Assert.Equal(VolumeUnit.CubicYard, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 ярд³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CubicYards, CubicYardsTolerance); - Assert.Equal(VolumeUnit.CubicYard, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 dal", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decaliters, DecalitersTolerance); - Assert.Equal(VolumeUnit.Decaliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 дал", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Decaliters, DecalitersTolerance); - Assert.Equal(VolumeUnit.Decaliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 dagal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecausGallons, DecausGallonsTolerance); - Assert.Equal(VolumeUnit.DecausGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 даАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecausGallons, DecausGallonsTolerance); - Assert.Equal(VolumeUnit.DecausGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 dl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciliters, DecilitersTolerance); - Assert.Equal(VolumeUnit.Deciliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 дл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Deciliters, DecilitersTolerance); - Assert.Equal(VolumeUnit.Deciliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 dgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciusGallons, DeciusGallonsTolerance); - Assert.Equal(VolumeUnit.DeciusGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 дАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DeciusGallons, DeciusGallonsTolerance); - Assert.Equal(VolumeUnit.DeciusGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 hft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectocubicFeet, HectocubicFeetTolerance); - Assert.Equal(VolumeUnit.HectocubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 гфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectocubicFeet, HectocubicFeetTolerance); - Assert.Equal(VolumeUnit.HectocubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 hl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectoliters, HectolitersTolerance); - Assert.Equal(VolumeUnit.Hectoliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 гл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Hectoliters, HectolitersTolerance); - Assert.Equal(VolumeUnit.Hectoliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 hgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectousGallons, HectousGallonsTolerance); - Assert.Equal(VolumeUnit.HectousGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 гАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.HectousGallons, HectousGallonsTolerance); - Assert.Equal(VolumeUnit.HectousGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 bl (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialBeerBarrels, ImperialBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.ImperialBeerBarrel, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 gal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialGallons, ImperialGallonsTolerance); - Assert.Equal(VolumeUnit.ImperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Английский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialGallons, ImperialGallonsTolerance); - Assert.Equal(VolumeUnit.ImperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 oz (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialOunces, ImperialOuncesTolerance); - Assert.Equal(VolumeUnit.ImperialOunce, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Английская унция", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialOunces, ImperialOuncesTolerance); - Assert.Equal(VolumeUnit.ImperialOunce, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pt (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 UK pt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pt", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - Assert.Equal(VolumeUnit.ImperialPint, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 p", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.ImperialPints, ImperialPintsTolerance); - 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); - Assert.Equal(VolumeUnit.KilocubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 кфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocubicFeet, KilocubicFeetTolerance); - Assert.Equal(VolumeUnit.KilocubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 kgal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloimperialGallons, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 кАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KiloimperialGallons, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 kl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloliters, KilolitersTolerance); - Assert.Equal(VolumeUnit.Kiloliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 кл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kiloliters, KilolitersTolerance); - Assert.Equal(VolumeUnit.Kiloliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 kgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilousGallons, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 кАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilousGallons, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 l", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Liters, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 л", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Liters, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Mft³", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegacubicFeet, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Мфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegacubicFeet, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Mgal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaimperialGallons, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 МАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegaimperialGallons, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Mgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegausGallons, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 МАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegausGallons, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 metric cup", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricCups, MetricCupsTolerance); - Assert.Equal(VolumeUnit.MetricCup, 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); - 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); - 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); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 teaspoon", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 µl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 мкл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microliters, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 nl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 нл", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanoliters, NanolitersTolerance); - Assert.Equal(VolumeUnit.Nanoliter, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 bbl", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.OilBarrels, OilBarrelsTolerance); - Assert.Equal(VolumeUnit.OilBarrel, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 tablespoon (U.K.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UkTablespoons, UkTablespoonsTolerance); - Assert.Equal(VolumeUnit.UkTablespoon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 bl (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsBeerBarrels, UsBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.UsBeerBarrel, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 cup (U.S. customary)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsCustomaryCups, UsCustomaryCupsTolerance); - Assert.Equal(VolumeUnit.UsCustomaryCup, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 gal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Американский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsGallons, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 cup (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsLegalCups, UsLegalCupsTolerance); - Assert.Equal(VolumeUnit.UsLegalCup, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 oz (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 Американская унция", CultureInfo.GetCultureInfo("ru-RU"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsOunces, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 pt (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsPints, UsPintsTolerance); - Assert.Equal(VolumeUnit.UsPint, parsed.Unit); - } - - { - Assert.True(Volume.TryParse("1 qt (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsQuarts, UsQuartsTolerance); - Assert.Equal(VolumeUnit.UsQuart, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 ac-ft", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 acre-foot", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 acre-feet", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 tablespoon (A.U.)", VolumeUnit.AuTablespoon, 4.2)] + [InlineData("en-US", "4.2 bf", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 board foot", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 board feet", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 cl", VolumeUnit.Centiliter, 4.2)] + [InlineData("en-US", "4.2 cm³", VolumeUnit.CubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm³", VolumeUnit.CubicDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft³", VolumeUnit.CubicFoot, 4.2)] + [InlineData("en-US", "4.2 in³", VolumeUnit.CubicInch, 4.2)] + [InlineData("en-US", "4.2 m³", VolumeUnit.CubicMeter, 4.2)] + [InlineData("en-US", "4.2 µm³", VolumeUnit.CubicMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi³", VolumeUnit.CubicMile, 4.2)] + [InlineData("en-US", "4.2 mm³", VolumeUnit.CubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 yd³", VolumeUnit.CubicYard, 4.2)] + [InlineData("en-US", "4.2 dal", VolumeUnit.Decaliter, 4.2)] + [InlineData("en-US", "4.2 dagal (U.S.)", VolumeUnit.DecausGallon, 4.2)] + [InlineData("en-US", "4.2 dl", VolumeUnit.Deciliter, 4.2)] + [InlineData("en-US", "4.2 dgal (U.S.)", VolumeUnit.DeciusGallon, 4.2)] + [InlineData("en-US", "4.2 hft³", VolumeUnit.HectocubicFoot, 4.2)] + [InlineData("en-US", "4.2 hl", VolumeUnit.Hectoliter, 4.2)] + [InlineData("en-US", "4.2 hgal (U.S.)", VolumeUnit.HectousGallon, 4.2)] + [InlineData("en-US", "4.2 bl (imp.)", VolumeUnit.ImperialBeerBarrel, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)", VolumeUnit.ImperialGallon, 4.2)] + [InlineData("en-US", "4.2 oz (imp.)", VolumeUnit.ImperialOunce, 4.2)] + [InlineData("en-US", "4.2 pt (imp.)", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 UK pt", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 pt", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 p", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 qt (imp.)", VolumeUnit.ImperialQuart, 4.2)] + [InlineData("en-US", "4.2 kft³", VolumeUnit.KilocubicFoot, 4.2)] + [InlineData("en-US", "4.2 kgal (imp.)", VolumeUnit.KiloimperialGallon, 4.2)] + [InlineData("en-US", "4.2 kl", VolumeUnit.Kiloliter, 4.2)] + [InlineData("en-US", "4.2 kgal (U.S.)", VolumeUnit.KilousGallon, 4.2)] + [InlineData("en-US", "4.2 l", VolumeUnit.Liter, 4.2)] + [InlineData("en-US", "4.2 Mft³", VolumeUnit.MegacubicFoot, 4.2)] + [InlineData("en-US", "4.2 Mgal (imp.)", VolumeUnit.MegaimperialGallon, 4.2)] + [InlineData("en-US", "4.2 Ml", VolumeUnit.Megaliter, 4.2)] + [InlineData("en-US", "4.2 Mgal (U.S.)", VolumeUnit.MegausGallon, 4.2)] + [InlineData("en-US", "4.2 metric cup", VolumeUnit.MetricCup, 4.2)] + [InlineData("en-US", "4.2 tsp", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 t", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 ts", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tspn", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 t.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 ts.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tsp.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tspn.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 teaspoon", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 µl", VolumeUnit.Microliter, 4.2)] + [InlineData("en-US", "4.2 ml", VolumeUnit.Milliliter, 4.2)] + [InlineData("en-US", "4.2 nl", VolumeUnit.Nanoliter, 4.2)] + [InlineData("en-US", "4.2 bbl", VolumeUnit.OilBarrel, 4.2)] + [InlineData("en-US", "4.2 tablespoon (U.K.)", VolumeUnit.UkTablespoon, 4.2)] + [InlineData("en-US", "4.2 bl (U.S.)", VolumeUnit.UsBeerBarrel, 4.2)] + [InlineData("en-US", "4.2 cup (U.S. customary)", VolumeUnit.UsCustomaryCup, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)", VolumeUnit.UsGallon, 4.2)] + [InlineData("en-US", "4.2 cup (U.S.)", VolumeUnit.UsLegalCup, 4.2)] + [InlineData("en-US", "4.2 oz (U.S.)", VolumeUnit.UsOunce, 4.2)] + [InlineData("en-US", "4.2 pt (U.S.)", VolumeUnit.UsPint, 4.2)] + [InlineData("en-US", "4.2 qt (U.S.)", VolumeUnit.UsQuart, 4.2)] + [InlineData("en-US", "4.2 tablespoon (U.S.)", VolumeUnit.UsTablespoon, 4.2)] + [InlineData("en-US", "4.2 teaspoon (U.S.)", VolumeUnit.UsTeaspoon, 4.2)] + [InlineData("fr-CA", "4,2 pmp", VolumeUnit.BoardFoot, 4.2)] + [InlineData("fr-CA", "4,2 pied-planche", VolumeUnit.BoardFoot, 4.2)] + [InlineData("fr-CA", "4,2 pied de planche", VolumeUnit.BoardFoot, 4.2)] + [InlineData("ru-RU", "4,2 сл", VolumeUnit.Centiliter, 4.2)] + [InlineData("ru-RU", "4,2 см³", VolumeUnit.CubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дм³", VolumeUnit.CubicDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 фут³", VolumeUnit.CubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 дюйм³", VolumeUnit.CubicInch, 4.2)] + [InlineData("ru-RU", "4,2 м³", VolumeUnit.CubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкм³", VolumeUnit.CubicMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля³", VolumeUnit.CubicMile, 4.2)] + [InlineData("ru-RU", "4,2 мм³", VolumeUnit.CubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 ярд³", VolumeUnit.CubicYard, 4.2)] + [InlineData("ru-RU", "4,2 дал", VolumeUnit.Decaliter, 4.2)] + [InlineData("ru-RU", "4,2 даАмериканский галлон", VolumeUnit.DecausGallon, 4.2)] + [InlineData("ru-RU", "4,2 дл", VolumeUnit.Deciliter, 4.2)] + [InlineData("ru-RU", "4,2 дАмериканский галлон", VolumeUnit.DeciusGallon, 4.2)] + [InlineData("ru-RU", "4,2 гфут³", VolumeUnit.HectocubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 гл", VolumeUnit.Hectoliter, 4.2)] + [InlineData("ru-RU", "4,2 гАмериканский галлон", VolumeUnit.HectousGallon, 4.2)] + [InlineData("ru-RU", "4,2 Английский галлон", VolumeUnit.ImperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 Английская унция", VolumeUnit.ImperialOunce, 4.2)] + [InlineData("ru-RU", "4,2 кфут³", VolumeUnit.KilocubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 кАнглийский галлон", VolumeUnit.KiloimperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 кл", VolumeUnit.Kiloliter, 4.2)] + [InlineData("ru-RU", "4,2 кАмериканский галлон", VolumeUnit.KilousGallon, 4.2)] + [InlineData("ru-RU", "4,2 л", VolumeUnit.Liter, 4.2)] + [InlineData("ru-RU", "4,2 Мфут³", VolumeUnit.MegacubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 МАнглийский галлон", VolumeUnit.MegaimperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 Мл", VolumeUnit.Megaliter, 4.2)] + [InlineData("ru-RU", "4,2 МАмериканский галлон", VolumeUnit.MegausGallon, 4.2)] + [InlineData("ru-RU", "4,2 мкл", VolumeUnit.Microliter, 4.2)] + [InlineData("ru-RU", "4,2 мл", VolumeUnit.Milliliter, 4.2)] + [InlineData("ru-RU", "4,2 нл", VolumeUnit.Nanoliter, 4.2)] + [InlineData("ru-RU", "4,2 Американский галлон", VolumeUnit.UsGallon, 4.2)] + [InlineData("ru-RU", "4,2 Американская унция", VolumeUnit.UsOunce, 4.2)] + public void Parse(string culture, string quantityString, VolumeUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + var parsed = Volume.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } - { - Assert.True(Volume.TryParse("1 tablespoon (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsTablespoons, UsTablespoonsTolerance); - Assert.Equal(VolumeUnit.UsTablespoon, parsed.Unit); - } + [Theory] + [InlineData("en-US", "1 hm³")] // [CubicHectometer, HectocubicMeter] + [InlineData("en-US", "1 km³")] // [CubicKilometer, KilocubicMeter] + [InlineData("ru-RU", "1 гм³")] // [CubicHectometer, HectocubicMeter] + [InlineData("ru-RU", "1 км³")] // [CubicKilometer, KilocubicMeter] + public void ParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.Throws(() => Volume.Parse(quantityString, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Volume.TryParse("1 teaspoon (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.UsTeaspoons, UsTeaspoonsTolerance); - Assert.Equal(VolumeUnit.UsTeaspoon, parsed.Unit); - } + [Theory] + [InlineData("en-US", "4.2 ac-ft", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 acre-foot", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 acre-feet", VolumeUnit.AcreFoot, 4.2)] + [InlineData("en-US", "4.2 tablespoon (A.U.)", VolumeUnit.AuTablespoon, 4.2)] + [InlineData("en-US", "4.2 bf", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 board foot", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 board feet", VolumeUnit.BoardFoot, 4.2)] + [InlineData("en-US", "4.2 cl", VolumeUnit.Centiliter, 4.2)] + [InlineData("en-US", "4.2 cm³", VolumeUnit.CubicCentimeter, 4.2)] + [InlineData("en-US", "4.2 dm³", VolumeUnit.CubicDecimeter, 4.2)] + [InlineData("en-US", "4.2 ft³", VolumeUnit.CubicFoot, 4.2)] + [InlineData("en-US", "4.2 in³", VolumeUnit.CubicInch, 4.2)] + [InlineData("en-US", "4.2 m³", VolumeUnit.CubicMeter, 4.2)] + [InlineData("en-US", "4.2 µm³", VolumeUnit.CubicMicrometer, 4.2)] + [InlineData("en-US", "4.2 mi³", VolumeUnit.CubicMile, 4.2)] + [InlineData("en-US", "4.2 mm³", VolumeUnit.CubicMillimeter, 4.2)] + [InlineData("en-US", "4.2 yd³", VolumeUnit.CubicYard, 4.2)] + [InlineData("en-US", "4.2 dal", VolumeUnit.Decaliter, 4.2)] + [InlineData("en-US", "4.2 dagal (U.S.)", VolumeUnit.DecausGallon, 4.2)] + [InlineData("en-US", "4.2 dl", VolumeUnit.Deciliter, 4.2)] + [InlineData("en-US", "4.2 dgal (U.S.)", VolumeUnit.DeciusGallon, 4.2)] + [InlineData("en-US", "4.2 hft³", VolumeUnit.HectocubicFoot, 4.2)] + [InlineData("en-US", "4.2 hl", VolumeUnit.Hectoliter, 4.2)] + [InlineData("en-US", "4.2 hgal (U.S.)", VolumeUnit.HectousGallon, 4.2)] + [InlineData("en-US", "4.2 bl (imp.)", VolumeUnit.ImperialBeerBarrel, 4.2)] + [InlineData("en-US", "4.2 gal (imp.)", VolumeUnit.ImperialGallon, 4.2)] + [InlineData("en-US", "4.2 oz (imp.)", VolumeUnit.ImperialOunce, 4.2)] + [InlineData("en-US", "4.2 pt (imp.)", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 UK pt", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 pt", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 p", VolumeUnit.ImperialPint, 4.2)] + [InlineData("en-US", "4.2 qt (imp.)", VolumeUnit.ImperialQuart, 4.2)] + [InlineData("en-US", "4.2 kft³", VolumeUnit.KilocubicFoot, 4.2)] + [InlineData("en-US", "4.2 kgal (imp.)", VolumeUnit.KiloimperialGallon, 4.2)] + [InlineData("en-US", "4.2 kl", VolumeUnit.Kiloliter, 4.2)] + [InlineData("en-US", "4.2 kgal (U.S.)", VolumeUnit.KilousGallon, 4.2)] + [InlineData("en-US", "4.2 l", VolumeUnit.Liter, 4.2)] + [InlineData("en-US", "4.2 Mft³", VolumeUnit.MegacubicFoot, 4.2)] + [InlineData("en-US", "4.2 Mgal (imp.)", VolumeUnit.MegaimperialGallon, 4.2)] + [InlineData("en-US", "4.2 Ml", VolumeUnit.Megaliter, 4.2)] + [InlineData("en-US", "4.2 Mgal (U.S.)", VolumeUnit.MegausGallon, 4.2)] + [InlineData("en-US", "4.2 metric cup", VolumeUnit.MetricCup, 4.2)] + [InlineData("en-US", "4.2 tsp", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 t", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 ts", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tspn", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 t.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 ts.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tsp.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 tspn.", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 teaspoon", VolumeUnit.MetricTeaspoon, 4.2)] + [InlineData("en-US", "4.2 µl", VolumeUnit.Microliter, 4.2)] + [InlineData("en-US", "4.2 ml", VolumeUnit.Milliliter, 4.2)] + [InlineData("en-US", "4.2 nl", VolumeUnit.Nanoliter, 4.2)] + [InlineData("en-US", "4.2 bbl", VolumeUnit.OilBarrel, 4.2)] + [InlineData("en-US", "4.2 tablespoon (U.K.)", VolumeUnit.UkTablespoon, 4.2)] + [InlineData("en-US", "4.2 bl (U.S.)", VolumeUnit.UsBeerBarrel, 4.2)] + [InlineData("en-US", "4.2 cup (U.S. customary)", VolumeUnit.UsCustomaryCup, 4.2)] + [InlineData("en-US", "4.2 gal (U.S.)", VolumeUnit.UsGallon, 4.2)] + [InlineData("en-US", "4.2 cup (U.S.)", VolumeUnit.UsLegalCup, 4.2)] + [InlineData("en-US", "4.2 oz (U.S.)", VolumeUnit.UsOunce, 4.2)] + [InlineData("en-US", "4.2 pt (U.S.)", VolumeUnit.UsPint, 4.2)] + [InlineData("en-US", "4.2 qt (U.S.)", VolumeUnit.UsQuart, 4.2)] + [InlineData("en-US", "4.2 tablespoon (U.S.)", VolumeUnit.UsTablespoon, 4.2)] + [InlineData("en-US", "4.2 teaspoon (U.S.)", VolumeUnit.UsTeaspoon, 4.2)] + [InlineData("fr-CA", "4,2 pmp", VolumeUnit.BoardFoot, 4.2)] + [InlineData("fr-CA", "4,2 pied-planche", VolumeUnit.BoardFoot, 4.2)] + [InlineData("fr-CA", "4,2 pied de planche", VolumeUnit.BoardFoot, 4.2)] + [InlineData("ru-RU", "4,2 сл", VolumeUnit.Centiliter, 4.2)] + [InlineData("ru-RU", "4,2 см³", VolumeUnit.CubicCentimeter, 4.2)] + [InlineData("ru-RU", "4,2 дм³", VolumeUnit.CubicDecimeter, 4.2)] + [InlineData("ru-RU", "4,2 фут³", VolumeUnit.CubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 дюйм³", VolumeUnit.CubicInch, 4.2)] + [InlineData("ru-RU", "4,2 м³", VolumeUnit.CubicMeter, 4.2)] + [InlineData("ru-RU", "4,2 мкм³", VolumeUnit.CubicMicrometer, 4.2)] + [InlineData("ru-RU", "4,2 миля³", VolumeUnit.CubicMile, 4.2)] + [InlineData("ru-RU", "4,2 мм³", VolumeUnit.CubicMillimeter, 4.2)] + [InlineData("ru-RU", "4,2 ярд³", VolumeUnit.CubicYard, 4.2)] + [InlineData("ru-RU", "4,2 дал", VolumeUnit.Decaliter, 4.2)] + [InlineData("ru-RU", "4,2 даАмериканский галлон", VolumeUnit.DecausGallon, 4.2)] + [InlineData("ru-RU", "4,2 дл", VolumeUnit.Deciliter, 4.2)] + [InlineData("ru-RU", "4,2 дАмериканский галлон", VolumeUnit.DeciusGallon, 4.2)] + [InlineData("ru-RU", "4,2 гфут³", VolumeUnit.HectocubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 гл", VolumeUnit.Hectoliter, 4.2)] + [InlineData("ru-RU", "4,2 гАмериканский галлон", VolumeUnit.HectousGallon, 4.2)] + [InlineData("ru-RU", "4,2 Английский галлон", VolumeUnit.ImperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 Английская унция", VolumeUnit.ImperialOunce, 4.2)] + [InlineData("ru-RU", "4,2 кфут³", VolumeUnit.KilocubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 кАнглийский галлон", VolumeUnit.KiloimperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 кл", VolumeUnit.Kiloliter, 4.2)] + [InlineData("ru-RU", "4,2 кАмериканский галлон", VolumeUnit.KilousGallon, 4.2)] + [InlineData("ru-RU", "4,2 л", VolumeUnit.Liter, 4.2)] + [InlineData("ru-RU", "4,2 Мфут³", VolumeUnit.MegacubicFoot, 4.2)] + [InlineData("ru-RU", "4,2 МАнглийский галлон", VolumeUnit.MegaimperialGallon, 4.2)] + [InlineData("ru-RU", "4,2 Мл", VolumeUnit.Megaliter, 4.2)] + [InlineData("ru-RU", "4,2 МАмериканский галлон", VolumeUnit.MegausGallon, 4.2)] + [InlineData("ru-RU", "4,2 мкл", VolumeUnit.Microliter, 4.2)] + [InlineData("ru-RU", "4,2 мл", VolumeUnit.Milliliter, 4.2)] + [InlineData("ru-RU", "4,2 нл", VolumeUnit.Nanoliter, 4.2)] + [InlineData("ru-RU", "4,2 Американский галлон", VolumeUnit.UsGallon, 4.2)] + [InlineData("ru-RU", "4,2 Американская унция", VolumeUnit.UsOunce, 4.2)] + public void TryParse(string culture, string quantityString, VolumeUnit expectedUnit, double expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(Volume.TryParse(quantityString, out Volume parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + [Theory] + [InlineData("en-US", "1 hm³")] // [CubicHectometer, HectocubicMeter] + [InlineData("en-US", "1 km³")] // [CubicKilometer, KilocubicMeter] + [InlineData("ru-RU", "1 гм³")] // [CubicHectometer, HectocubicMeter] + [InlineData("ru-RU", "1 км³")] // [CubicKilometer, KilocubicMeter] + public void TryParseWithAmbiguousAbbreviation(string culture, string quantityString) + { + Assert.False(Volume.TryParse(quantityString, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] @@ -2693,6 +1578,118 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi Assert.False(Volume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } + [Theory] + [InlineData("en-US", VolumeUnit.AcreFoot, "ac-ft")] + [InlineData("en-US", VolumeUnit.AuTablespoon, "tablespoon (A.U.)")] + [InlineData("en-US", VolumeUnit.BoardFoot, "bf")] + [InlineData("en-US", VolumeUnit.Centiliter, "cl")] + [InlineData("en-US", VolumeUnit.CubicCentimeter, "cm³")] + [InlineData("en-US", VolumeUnit.CubicDecimeter, "dm³")] + [InlineData("en-US", VolumeUnit.CubicFoot, "ft³")] + [InlineData("en-US", VolumeUnit.CubicHectometer, "hm³")] + [InlineData("en-US", VolumeUnit.CubicInch, "in³")] + [InlineData("en-US", VolumeUnit.CubicKilometer, "km³")] + [InlineData("en-US", VolumeUnit.CubicMeter, "m³")] + [InlineData("en-US", VolumeUnit.CubicMicrometer, "µm³")] + [InlineData("en-US", VolumeUnit.CubicMile, "mi³")] + [InlineData("en-US", VolumeUnit.CubicMillimeter, "mm³")] + [InlineData("en-US", VolumeUnit.CubicYard, "yd³")] + [InlineData("en-US", VolumeUnit.Decaliter, "dal")] + [InlineData("en-US", VolumeUnit.DecausGallon, "dagal (U.S.)")] + [InlineData("en-US", VolumeUnit.Deciliter, "dl")] + [InlineData("en-US", VolumeUnit.DeciusGallon, "dgal (U.S.)")] + [InlineData("en-US", VolumeUnit.HectocubicFoot, "hft³")] + [InlineData("en-US", VolumeUnit.HectocubicMeter, "hm³")] + [InlineData("en-US", VolumeUnit.Hectoliter, "hl")] + [InlineData("en-US", VolumeUnit.HectousGallon, "hgal (U.S.)")] + [InlineData("en-US", VolumeUnit.ImperialBeerBarrel, "bl (imp.)")] + [InlineData("en-US", VolumeUnit.ImperialGallon, "gal (imp.)")] + [InlineData("en-US", VolumeUnit.ImperialOunce, "oz (imp.)")] + [InlineData("en-US", VolumeUnit.ImperialPint, "pt (imp.)")] + [InlineData("en-US", VolumeUnit.ImperialQuart, "qt (imp.)")] + [InlineData("en-US", VolumeUnit.KilocubicFoot, "kft³")] + [InlineData("en-US", VolumeUnit.KilocubicMeter, "km³")] + [InlineData("en-US", VolumeUnit.KiloimperialGallon, "kgal (imp.)")] + [InlineData("en-US", VolumeUnit.Kiloliter, "kl")] + [InlineData("en-US", VolumeUnit.KilousGallon, "kgal (U.S.)")] + [InlineData("en-US", VolumeUnit.Liter, "l")] + [InlineData("en-US", VolumeUnit.MegacubicFoot, "Mft³")] + [InlineData("en-US", VolumeUnit.MegaimperialGallon, "Mgal (imp.)")] + [InlineData("en-US", VolumeUnit.Megaliter, "Ml")] + [InlineData("en-US", VolumeUnit.MegausGallon, "Mgal (U.S.)")] + [InlineData("en-US", VolumeUnit.MetricCup, "metric cup")] + [InlineData("en-US", VolumeUnit.MetricTeaspoon, "tsp")] + [InlineData("en-US", VolumeUnit.Microliter, "µl")] + [InlineData("en-US", VolumeUnit.Milliliter, "ml")] + [InlineData("en-US", VolumeUnit.Nanoliter, "nl")] + [InlineData("en-US", VolumeUnit.OilBarrel, "bbl")] + [InlineData("en-US", VolumeUnit.UkTablespoon, "tablespoon (U.K.)")] + [InlineData("en-US", VolumeUnit.UsBeerBarrel, "bl (U.S.)")] + [InlineData("en-US", VolumeUnit.UsCustomaryCup, "cup (U.S. customary)")] + [InlineData("en-US", VolumeUnit.UsGallon, "gal (U.S.)")] + [InlineData("en-US", VolumeUnit.UsLegalCup, "cup (U.S.)")] + [InlineData("en-US", VolumeUnit.UsOunce, "oz (U.S.)")] + [InlineData("en-US", VolumeUnit.UsPint, "pt (U.S.)")] + [InlineData("en-US", VolumeUnit.UsQuart, "qt (U.S.)")] + [InlineData("en-US", VolumeUnit.UsTablespoon, "tablespoon (U.S.)")] + [InlineData("en-US", VolumeUnit.UsTeaspoon, "teaspoon (U.S.)")] + [InlineData("fr-CA", VolumeUnit.BoardFoot, "pmp")] + [InlineData("ru-RU", VolumeUnit.Centiliter, "сл")] + [InlineData("ru-RU", VolumeUnit.CubicCentimeter, "см³")] + [InlineData("ru-RU", VolumeUnit.CubicDecimeter, "дм³")] + [InlineData("ru-RU", VolumeUnit.CubicFoot, "фут³")] + [InlineData("ru-RU", VolumeUnit.CubicHectometer, "гм³")] + [InlineData("ru-RU", VolumeUnit.CubicInch, "дюйм³")] + [InlineData("ru-RU", VolumeUnit.CubicKilometer, "км³")] + [InlineData("ru-RU", VolumeUnit.CubicMeter, "м³")] + [InlineData("ru-RU", VolumeUnit.CubicMicrometer, "мкм³")] + [InlineData("ru-RU", VolumeUnit.CubicMile, "миля³")] + [InlineData("ru-RU", VolumeUnit.CubicMillimeter, "мм³")] + [InlineData("ru-RU", VolumeUnit.CubicYard, "ярд³")] + [InlineData("ru-RU", VolumeUnit.Decaliter, "дал")] + [InlineData("ru-RU", VolumeUnit.DecausGallon, "даАмериканский галлон")] + [InlineData("ru-RU", VolumeUnit.Deciliter, "дл")] + [InlineData("ru-RU", VolumeUnit.DeciusGallon, "дАмериканский галлон")] + [InlineData("ru-RU", VolumeUnit.HectocubicFoot, "гфут³")] + [InlineData("ru-RU", VolumeUnit.HectocubicMeter, "гм³")] + [InlineData("ru-RU", VolumeUnit.Hectoliter, "гл")] + [InlineData("ru-RU", VolumeUnit.HectousGallon, "гАмериканский галлон")] + [InlineData("ru-RU", VolumeUnit.ImperialGallon, "Английский галлон")] + [InlineData("ru-RU", VolumeUnit.ImperialOunce, "Английская унция")] + [InlineData("ru-RU", VolumeUnit.KilocubicFoot, "кфут³")] + [InlineData("ru-RU", VolumeUnit.KilocubicMeter, "км³")] + [InlineData("ru-RU", VolumeUnit.KiloimperialGallon, "кАнглийский галлон")] + [InlineData("ru-RU", VolumeUnit.Kiloliter, "кл")] + [InlineData("ru-RU", VolumeUnit.KilousGallon, "кАмериканский галлон")] + [InlineData("ru-RU", VolumeUnit.Liter, "л")] + [InlineData("ru-RU", VolumeUnit.MegacubicFoot, "Мфут³")] + [InlineData("ru-RU", VolumeUnit.MegaimperialGallon, "МАнглийский галлон")] + [InlineData("ru-RU", VolumeUnit.Megaliter, "Мл")] + [InlineData("ru-RU", VolumeUnit.MegausGallon, "МАмериканский галлон")] + [InlineData("ru-RU", VolumeUnit.Microliter, "мкл")] + [InlineData("ru-RU", VolumeUnit.Milliliter, "мл")] + [InlineData("ru-RU", VolumeUnit.Nanoliter, "нл")] + [InlineData("ru-RU", VolumeUnit.UsGallon, "Американский галлон")] + [InlineData("ru-RU", VolumeUnit.UsOunce, "Американская унция")] + public void GetAbbreviationForCulture(string culture, VolumeUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = Volume.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(Volume.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = Volume.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumeUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index 0ed711b2aa..51b39e1cac 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -318,131 +318,40 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, 4.2)] + public void Parse(string culture, string quantityString, VolumetricHeatCapacityUnit expectedUnit, double expectedValue) { - try - { - var parsed = VolumetricHeatCapacity.Parse("1 BTU/(ft³·°F)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.BtusPerCubicFootDegreeFahrenheit, BtusPerCubicFootDegreeFahrenheitTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 cal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CaloriesPerCubicCentimeterDegreeCelsius, CaloriesPerCubicCentimeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 J/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeterDegreeCelsius, JoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 J/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeterKelvin, JoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 kcal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerCubicCentimeterDegreeCelsius, KilocaloriesPerCubicCentimeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 kJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeterDegreeCelsius, KilojoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 kJ/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeterKelvin, KilojoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 MJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeterDegreeCelsius, MegajoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = VolumetricHeatCapacity.Parse("1 MJ/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeterKelvin, MegajoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = VolumetricHeatCapacity.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, 4.2)] + [InlineData("en-US", "4.2 cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 4.2)] + [InlineData("en-US", "4.2 kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, 4.2)] + [InlineData("en-US", "4.2 MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, 4.2)] + [InlineData("en-US", "4.2 MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, 4.2)] + public void TryParse(string culture, string quantityString, VolumetricHeatCapacityUnit expectedUnit, double expectedValue) { - { - Assert.True(VolumetricHeatCapacity.TryParse("1 BTU/(ft³·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.BtusPerCubicFootDegreeFahrenheit, BtusPerCubicFootDegreeFahrenheitTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 cal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CaloriesPerCubicCentimeterDegreeCelsius, CaloriesPerCubicCentimeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 J/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeterDegreeCelsius, JoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 J/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.JoulesPerCubicMeterKelvin, JoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 kcal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilocaloriesPerCubicCentimeterDegreeCelsius, KilocaloriesPerCubicCentimeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 kJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeterDegreeCelsius, KilojoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 kJ/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilojoulesPerCubicMeterKelvin, KilojoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 MJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeterDegreeCelsius, MegajoulesPerCubicMeterDegreeCelsiusTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, parsed.Unit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParse("1 MJ/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegajoulesPerCubicMeterKelvin, MegajoulesPerCubicMeterKelvinTolerance); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(VolumetricHeatCapacity.TryParse(quantityString, out VolumetricHeatCapacity parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -583,6 +492,35 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Volume Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, "BTU/(ft³·°F)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, "cal/(cm³·°C)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, "J/(m³·°C)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, "J/(m³·K)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, "kcal/(cm³·°C)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, "kJ/(m³·°C)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, "kJ/(m³·K)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, "MJ/(m³·°C)")] + [InlineData("en-US", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, "MJ/(m³·K)")] + public void GetAbbreviationForCulture(string culture, VolumetricHeatCapacityUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = VolumetricHeatCapacity.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(VolumetricHeatCapacity.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = VolumetricHeatCapacity.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(VolumetricHeatCapacityUnit unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index a79027c1a3..cfa00d5035 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -300,92 +300,34 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() }); } - [Fact] - public void Parse() + [Theory] + [InlineData("en-US", "4.2 cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth, 4.2)] + [InlineData("en-US", "4.2 in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth, 4.2)] + [InlineData("en-US", "4.2 m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth, 4.2)] + public void Parse(string culture, string quantityString, WarpingMomentOfInertiaUnit expectedUnit, double expectedValue) { - try - { - var parsed = WarpingMomentOfInertia.Parse("1 cm⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.CentimetersToTheSixth, CentimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = WarpingMomentOfInertia.Parse("1 dm⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.DecimetersToTheSixth, DecimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = WarpingMomentOfInertia.Parse("1 ft⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FeetToTheSixth, FeetToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = WarpingMomentOfInertia.Parse("1 in⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.InchesToTheSixth, InchesToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = WarpingMomentOfInertia.Parse("1 m⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MetersToTheSixth, MetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = WarpingMomentOfInertia.Parse("1 mm⁶", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillimetersToTheSixth, MillimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + using var _ = new CultureScope(culture); + var parsed = WarpingMomentOfInertia.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } - [Fact] - public void TryParse() + [Theory] + [InlineData("en-US", "4.2 cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth, 4.2)] + [InlineData("en-US", "4.2 in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth, 4.2)] + [InlineData("en-US", "4.2 m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth, 4.2)] + [InlineData("en-US", "4.2 mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth, 4.2)] + public void TryParse(string culture, string quantityString, WarpingMomentOfInertiaUnit expectedUnit, double expectedValue) { - { - Assert.True(WarpingMomentOfInertia.TryParse("1 cm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.CentimetersToTheSixth, CentimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsed.Unit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParse("1 dm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.DecimetersToTheSixth, DecimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsed.Unit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParse("1 ft⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FeetToTheSixth, FeetToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsed.Unit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParse("1 in⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.InchesToTheSixth, InchesToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsed.Unit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParse("1 m⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MetersToTheSixth, MetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsed.Unit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParse("1 mm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MillimetersToTheSixth, MillimetersToTheSixthTolerance); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsed.Unit); - } - + using var _ = new CultureScope(culture); + Assert.True(WarpingMomentOfInertia.TryParse(quantityString, out WarpingMomentOfInertia parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); } [Theory] @@ -502,6 +444,32 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, Warpin Assert.Equal(expectedUnit, parsedUnit); } + [Theory] + [InlineData("en-US", WarpingMomentOfInertiaUnit.CentimeterToTheSixth, "cm⁶")] + [InlineData("en-US", WarpingMomentOfInertiaUnit.DecimeterToTheSixth, "dm⁶")] + [InlineData("en-US", WarpingMomentOfInertiaUnit.FootToTheSixth, "ft⁶")] + [InlineData("en-US", WarpingMomentOfInertiaUnit.InchToTheSixth, "in⁶")] + [InlineData("en-US", WarpingMomentOfInertiaUnit.MeterToTheSixth, "m⁶")] + [InlineData("en-US", WarpingMomentOfInertiaUnit.MillimeterToTheSixth, "mm⁶")] + public void GetAbbreviationForCulture(string culture, WarpingMomentOfInertiaUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = WarpingMomentOfInertia.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(WarpingMomentOfInertia.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = WarpingMomentOfInertia.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit(WarpingMomentOfInertiaUnit unit)