diff --git a/Common/UnitDefinitions/JapaneseHydrometerScale.json b/Common/UnitDefinitions/JapaneseHydrometerScale.json new file mode 100644 index 0000000000..8799dfaa43 --- /dev/null +++ b/Common/UnitDefinitions/JapaneseHydrometerScale.json @@ -0,0 +1,67 @@ +{ + "Name": "JapaneseHydrometerScale", + "BaseUnit": "ReciprocalSpecificGravity", + "XmlDocSummary": "A dimensionless quantity representing hydrometer scale readings derived from reciprocal specific gravity, including degrees Baumé and Sake Meter Value.", + "Units": [ + { + "SingularName": "ReciprocalSpecificGravity", + "PluralName": "ReciprocalSpecificGravities", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "1/SG" ] + } + ] + }, + { + "SingularName": "DegreeBaumeHeavy", + "PluralName": "DegreesBaumeHeavy", + "FromUnitToBaseFunc": "1 - {x} / 144.3", + "FromBaseToUnitFunc": "144.3 * (1 - {x})", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "°Bé heavy" ] + }, + { + "Culture": "ja-JP", + "Abbreviations": [ "°Bh" ] + } + ] + }, + { + "SingularName": "DegreeBaumeLight", + "PluralName": "DegreesBaumeLight", + "FromUnitToBaseFunc": "({x} + 134.3) / 144.3", + "FromBaseToUnitFunc": "144.3 * {x} - 134.3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "°Bé light" ] + }, + { + "Culture": "ja-JP", + "Abbreviations": [ "°Bl" ] + } + ] + }, + { + "SingularName": "SakeMeterValue", + "PluralName": "SakeMeterValues", + "FromUnitToBaseFunc": "1 + {x} / 1443", + "FromBaseToUnitFunc": "1443 * ({x} - 1)", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "SMV" ] + }, + { + "Culture": "ja-JP", + "Abbreviations": [ "日本酒度" ] + } + ] + } + ] +} diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index a3ddd96516..f8c654f4dc 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -2047,5 +2047,11 @@ "SquareInchPerInch": 7, "SquareMeterPerMeter": 1, "SquareMillimeterPerMeter": 5 + }, + "JapaneseHydrometerScale": { + "DegreeBaumeHeavy": 6, + "DegreeBaumeLight": 9, + "ReciprocalSpecificGravity": 5, + "SakeMeterValue": 7 } } diff --git a/UnitsNet.NumberExtensions.CS14.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs b/UnitsNet.NumberExtensions.CS14.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs new file mode 100644 index 0000000000..1e7da344a8 --- /dev/null +++ b/UnitsNet.NumberExtensions.CS14.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.NumberExtensions.NumberToJapaneseHydrometerScale; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToJapaneseHydrometerScaleExtensionsTests + { + [Fact] + public void NumberToDegreesBaumeHeavyTest() => + Assert.Equal(JapaneseHydrometerScale.FromDegreesBaumeHeavy(2), 2.DegreesBaumeHeavy); + + [Fact] + public void NumberToDegreesBaumeLightTest() => + Assert.Equal(JapaneseHydrometerScale.FromDegreesBaumeLight(2), 2.DegreesBaumeLight); + + [Fact] + public void NumberToReciprocalSpecificGravitiesTest() => + Assert.Equal(JapaneseHydrometerScale.FromReciprocalSpecificGravities(2), 2.ReciprocalSpecificGravities); + + [Fact] + public void NumberToSakeMeterValuesTest() => + Assert.Equal(JapaneseHydrometerScale.FromSakeMeterValues(2), 2.SakeMeterValues); + + } +} diff --git a/UnitsNet.NumberExtensions.CS14/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs b/UnitsNet.NumberExtensions.CS14/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs new file mode 100644 index 0000000000..7dd132c622 --- /dev/null +++ b/UnitsNet.NumberExtensions.CS14/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +#if NET7_0_OR_GREATER +using System.Numerics; +#endif + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToJapaneseHydrometerScale +{ + /// + /// A number to JapaneseHydrometerScale Extensions + /// + public static class NumberToJapaneseHydrometerScaleExtensions + { +#pragma warning disable CS1591 + extension(T value) +#pragma warning restore CS1591 + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#else + , IConvertible +#endif + { + /// + public JapaneseHydrometerScale DegreesBaumeHeavy +#if NET7_0_OR_GREATER + => JapaneseHydrometerScale.FromDegreesBaumeHeavy(QuantityValue.CreateChecked(value)); +#else + => JapaneseHydrometerScale.FromDegreesBaumeHeavy(value.ToQuantityValue()); +#endif + + /// + public JapaneseHydrometerScale DegreesBaumeLight +#if NET7_0_OR_GREATER + => JapaneseHydrometerScale.FromDegreesBaumeLight(QuantityValue.CreateChecked(value)); +#else + => JapaneseHydrometerScale.FromDegreesBaumeLight(value.ToQuantityValue()); +#endif + + /// + public JapaneseHydrometerScale ReciprocalSpecificGravities +#if NET7_0_OR_GREATER + => JapaneseHydrometerScale.FromReciprocalSpecificGravities(QuantityValue.CreateChecked(value)); +#else + => JapaneseHydrometerScale.FromReciprocalSpecificGravities(value.ToQuantityValue()); +#endif + + /// + public JapaneseHydrometerScale SakeMeterValues +#if NET7_0_OR_GREATER + => JapaneseHydrometerScale.FromSakeMeterValues(QuantityValue.CreateChecked(value)); +#else + => JapaneseHydrometerScale.FromSakeMeterValues(value.ToQuantityValue()); +#endif + + } + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs new file mode 100644 index 0000000000..75b290f0bd --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToJapaneseHydrometerScaleExtensionsTest.g.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.NumberExtensions.NumberToJapaneseHydrometerScale; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToJapaneseHydrometerScaleExtensionsTests + { + [Fact] + public void NumberToDegreesBaumeHeavyTest() => + Assert.Equal(JapaneseHydrometerScale.FromDegreesBaumeHeavy(2), 2.DegreesBaumeHeavy()); + + [Fact] + public void NumberToDegreesBaumeLightTest() => + Assert.Equal(JapaneseHydrometerScale.FromDegreesBaumeLight(2), 2.DegreesBaumeLight()); + + [Fact] + public void NumberToReciprocalSpecificGravitiesTest() => + Assert.Equal(JapaneseHydrometerScale.FromReciprocalSpecificGravities(2), 2.ReciprocalSpecificGravities()); + + [Fact] + public void NumberToSakeMeterValuesTest() => + Assert.Equal(JapaneseHydrometerScale.FromSakeMeterValues(2), 2.SakeMeterValues()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs new file mode 100644 index 0000000000..31f0e319c8 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToJapaneseHydrometerScaleExtensions.g.cs @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +#if NET7_0_OR_GREATER +using System.Numerics; +#endif + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToJapaneseHydrometerScale +{ + /// + /// A number to JapaneseHydrometerScale Extensions + /// + public static class NumberToJapaneseHydrometerScaleExtensions + { + /// + public static JapaneseHydrometerScale DegreesBaumeHeavy(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber + => JapaneseHydrometerScale.FromDegreesBaumeHeavy(QuantityValue.CreateChecked(value)); +#else + , IConvertible + => JapaneseHydrometerScale.FromDegreesBaumeHeavy(value.ToQuantityValue()); +#endif + + /// + public static JapaneseHydrometerScale DegreesBaumeLight(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber + => JapaneseHydrometerScale.FromDegreesBaumeLight(QuantityValue.CreateChecked(value)); +#else + , IConvertible + => JapaneseHydrometerScale.FromDegreesBaumeLight(value.ToQuantityValue()); +#endif + + /// + public static JapaneseHydrometerScale ReciprocalSpecificGravities(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber + => JapaneseHydrometerScale.FromReciprocalSpecificGravities(QuantityValue.CreateChecked(value)); +#else + , IConvertible + => JapaneseHydrometerScale.FromReciprocalSpecificGravities(value.ToQuantityValue()); +#endif + + /// + public static JapaneseHydrometerScale SakeMeterValues(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber + => JapaneseHydrometerScale.FromSakeMeterValues(QuantityValue.CreateChecked(value)); +#else + , IConvertible + => JapaneseHydrometerScale.FromSakeMeterValues(value.ToQuantityValue()); +#endif + + } +} diff --git a/UnitsNet.Tests/CustomCode/JapaneseHydrometerScaleTests.cs b/UnitsNet.Tests/CustomCode/JapaneseHydrometerScaleTests.cs new file mode 100644 index 0000000000..6b297102a1 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/JapaneseHydrometerScaleTests.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +namespace UnitsNet.Tests.CustomCode +{ + public class JapaneseHydrometerScaleTests : JapaneseHydrometerScaleTestsBase + { + protected override double DegreesBaumeHeavyInOneReciprocalSpecificGravity => 0; + + protected override double DegreesBaumeLightInOneReciprocalSpecificGravity => 10; + + protected override double ReciprocalSpecificGravitiesInOneReciprocalSpecificGravity => 1; + + protected override double SakeMeterValuesInOneReciprocalSpecificGravity => 0; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index cdb328511b..a8e285ad12 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -90,6 +90,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, InformationUnit.Teraoctet, Quantity.From(3, InformationUnit.Teraoctet)); Assertion(3, IrradianceUnit.WattPerSquareMeter, Quantity.From(3, IrradianceUnit.WattPerSquareMeter)); Assertion(3, IrradiationUnit.WattHourPerSquareMeter, Quantity.From(3, IrradiationUnit.WattHourPerSquareMeter)); + Assertion(3, JapaneseHydrometerScaleUnit.SakeMeterValue, Quantity.From(3, JapaneseHydrometerScaleUnit.SakeMeterValue)); Assertion(3, JerkUnit.StandardGravitiesPerSecond, Quantity.From(3, JerkUnit.StandardGravitiesPerSecond)); Assertion(3, KinematicViscosityUnit.Stokes, Quantity.From(3, KinematicViscosityUnit.Stokes)); Assertion(3, LeakRateUnit.TorrLiterPerSecond, Quantity.From(3, LeakRateUnit.TorrLiterPerSecond)); @@ -226,6 +227,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(Information.Info, Information.Zero); Assertion(Irradiance.Info, Irradiance.Zero); Assertion(Irradiation.Info, Irradiation.Zero); + Assertion(JapaneseHydrometerScale.Info, JapaneseHydrometerScale.Zero); Assertion(Jerk.Info, Jerk.Zero); Assertion(KinematicViscosity.Info, KinematicViscosity.Zero); Assertion(LeakRate.Info, LeakRate.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JapaneseHydrometerScaleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JapaneseHydrometerScaleTestsBase.g.cs new file mode 100644 index 0000000000..261f6ef6ec --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JapaneseHydrometerScaleTestsBase.g.cs @@ -0,0 +1,713 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.InternalHelpers; +using UnitsNet.Tests.Helpers; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of JapaneseHydrometerScale. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class JapaneseHydrometerScaleTestsBase : QuantityTestsBase + { + protected abstract double DegreesBaumeHeavyInOneReciprocalSpecificGravity { get; } + protected abstract double DegreesBaumeLightInOneReciprocalSpecificGravity { get; } + protected abstract double ReciprocalSpecificGravitiesInOneReciprocalSpecificGravity { get; } + protected abstract double SakeMeterValuesInOneReciprocalSpecificGravity { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double DegreesBaumeHeavyTolerance { get { return 1e-5; } } + protected virtual double DegreesBaumeLightTolerance { get { return 1e-5; } } + protected virtual double ReciprocalSpecificGravitiesTolerance { get { return 1e-5; } } + protected virtual double SakeMeterValuesTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(JapaneseHydrometerScaleUnit unit) + { + return unit switch + { + JapaneseHydrometerScaleUnit.DegreeBaumeHeavy => (DegreesBaumeHeavyInOneReciprocalSpecificGravity, DegreesBaumeHeavyTolerance), + JapaneseHydrometerScaleUnit.DegreeBaumeLight => (DegreesBaumeLightInOneReciprocalSpecificGravity, DegreesBaumeLightTolerance), + JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity => (ReciprocalSpecificGravitiesInOneReciprocalSpecificGravity, ReciprocalSpecificGravitiesTolerance), + JapaneseHydrometerScaleUnit.SakeMeterValue => (SakeMeterValuesInOneReciprocalSpecificGravity, SakeMeterValuesTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { JapaneseHydrometerScaleUnit.DegreeBaumeHeavy }, + new object[] { JapaneseHydrometerScaleUnit.DegreeBaumeLight }, + new object[] { JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity }, + new object[] { JapaneseHydrometerScaleUnit.SakeMeterValue }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new JapaneseHydrometerScale(); + Assert.Equal(0, quantity.Value); + Assert.Equal(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new JapaneseHydrometerScale(double.PositiveInfinity, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)); + var exception2 = Record.Exception(() => new JapaneseHydrometerScale(double.NegativeInfinity, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new JapaneseHydrometerScale(double.NaN, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)); + + Assert.Null(exception); + } + + [Fact] + public void JapaneseHydrometerScale_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + JapaneseHydrometerScaleUnit[] unitsOrderedByName = EnumHelper.GetValues().OrderBy(x => x.ToString(), StringComparer.OrdinalIgnoreCase).ToArray(); + var quantity = new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal("JapaneseHydrometerScale", quantityInfo.Name); + Assert.Equal(JapaneseHydrometerScale.Zero, quantityInfo.Zero); + Assert.Equal(JapaneseHydrometerScale.BaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Equal(unitsOrderedByName, quantityInfo.Units); + Assert.Equal(unitsOrderedByName, quantityInfo.UnitInfos.Select(x => x.Value)); + Assert.Equal(JapaneseHydrometerScale.Info, quantityInfo); + Assert.Equal(quantityInfo, ((IQuantity)quantity).QuantityInfo); + Assert.Equal(quantityInfo, ((IQuantity)quantity).QuantityInfo); + } + + [Fact] + public void JapaneseHydrometerScaleInfo_CreateWithCustomUnitInfos() + { + JapaneseHydrometerScaleUnit[] expectedUnits = [JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity]; + + JapaneseHydrometerScale.JapaneseHydrometerScaleInfo quantityInfo = JapaneseHydrometerScale.JapaneseHydrometerScaleInfo.CreateDefault(mappings => mappings.SelectUnits(expectedUnits)); + + Assert.Equal("JapaneseHydrometerScale", quantityInfo.Name); + Assert.Equal(JapaneseHydrometerScale.Zero, quantityInfo.Zero); + Assert.Equal(JapaneseHydrometerScale.BaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Equal(expectedUnits, quantityInfo.Units); + Assert.Equal(expectedUnits, quantityInfo.UnitInfos.Select(x => x.Value)); + } + + [Fact] + public void ReciprocalSpecificGravityToJapaneseHydrometerScaleUnits() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + AssertEx.EqualTolerance(DegreesBaumeHeavyInOneReciprocalSpecificGravity, reciprocalspecificgravity.DegreesBaumeHeavy, DegreesBaumeHeavyTolerance); + AssertEx.EqualTolerance(DegreesBaumeLightInOneReciprocalSpecificGravity, reciprocalspecificgravity.DegreesBaumeLight, DegreesBaumeLightTolerance); + AssertEx.EqualTolerance(ReciprocalSpecificGravitiesInOneReciprocalSpecificGravity, reciprocalspecificgravity.ReciprocalSpecificGravities, ReciprocalSpecificGravitiesTolerance); + AssertEx.EqualTolerance(SakeMeterValuesInOneReciprocalSpecificGravity, reciprocalspecificgravity.SakeMeterValues, SakeMeterValuesTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + Assert.All(EnumHelper.GetValues(), unit => + { + var quantity = JapaneseHydrometerScale.From(1, unit); + Assert.Equal(1, quantity.Value); + Assert.Equal(unit, quantity.Unit); + }); + } + + [Fact] + public void FromReciprocalSpecificGravities_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => JapaneseHydrometerScale.FromReciprocalSpecificGravities(double.PositiveInfinity)); + var exception2 = Record.Exception(() => JapaneseHydrometerScale.FromReciprocalSpecificGravities(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromReciprocalSpecificGravities_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => JapaneseHydrometerScale.FromReciprocalSpecificGravities(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + AssertEx.EqualTolerance(DegreesBaumeHeavyInOneReciprocalSpecificGravity, reciprocalspecificgravity.As(JapaneseHydrometerScaleUnit.DegreeBaumeHeavy), DegreesBaumeHeavyTolerance); + AssertEx.EqualTolerance(DegreesBaumeLightInOneReciprocalSpecificGravity, reciprocalspecificgravity.As(JapaneseHydrometerScaleUnit.DegreeBaumeLight), DegreesBaumeLightTolerance); + AssertEx.EqualTolerance(ReciprocalSpecificGravitiesInOneReciprocalSpecificGravity, reciprocalspecificgravity.As(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity), ReciprocalSpecificGravitiesTolerance); + AssertEx.EqualTolerance(SakeMeterValuesInOneReciprocalSpecificGravity, reciprocalspecificgravity.As(JapaneseHydrometerScaleUnit.SakeMeterValue), SakeMeterValuesTolerance); + } + + [Fact] + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScale.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void ToUnit_UnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => + { + var quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + JapaneseHydrometerScale convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScale.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScale.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new JapaneseHydrometerScale(value: 1, unit: JapaneseHydrometerScale.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Theory] + [InlineData("en-US", "4.2 °Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, 4.2)] + [InlineData("en-US", "4.2 °Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight, 4.2)] + [InlineData("en-US", "4.2 1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, 4.2)] + [InlineData("en-US", "4.2 SMV", JapaneseHydrometerScaleUnit.SakeMeterValue, 4.2)] + [InlineData("ja-JP", "4.2 °Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, 4.2)] + [InlineData("ja-JP", "4.2 °Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight, 4.2)] + [InlineData("ja-JP", "4.2 日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue, 4.2)] + public void Parse(string culture, string quantityString, JapaneseHydrometerScaleUnit expectedUnit, decimal expectedValue) + { + using var _ = new CultureScope(culture); + var parsed = JapaneseHydrometerScale.Parse(quantityString); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + + [Theory] + [InlineData("en-US", "4.2 °Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, 4.2)] + [InlineData("en-US", "4.2 °Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight, 4.2)] + [InlineData("en-US", "4.2 1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, 4.2)] + [InlineData("en-US", "4.2 SMV", JapaneseHydrometerScaleUnit.SakeMeterValue, 4.2)] + [InlineData("ja-JP", "4.2 °Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, 4.2)] + [InlineData("ja-JP", "4.2 °Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight, 4.2)] + [InlineData("ja-JP", "4.2 日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue, 4.2)] + public void TryParse(string culture, string quantityString, JapaneseHydrometerScaleUnit expectedUnit, decimal expectedValue) + { + using var _ = new CultureScope(culture); + Assert.True(JapaneseHydrometerScale.TryParse(quantityString, out JapaneseHydrometerScale parsed)); + Assert.Equal(expectedUnit, parsed.Unit); + Assert.Equal(expectedValue, parsed.Value); + } + + [Theory] + [InlineData("°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + JapaneseHydrometerScaleUnit parsedUnit = JapaneseHydrometerScale.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + JapaneseHydrometerScaleUnit parsedUnit = JapaneseHydrometerScale.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("en-US", "°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("en-US", "1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("en-US", "SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + [InlineData("ja-JP", "°Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("ja-JP", "°Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("ja-JP", "日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + using var _ = new CultureScope(culture); + JapaneseHydrometerScaleUnit parsedUnit = JapaneseHydrometerScale.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("en-US", "°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("en-US", "1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("en-US", "SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + [InlineData("ja-JP", "°Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("ja-JP", "°Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("ja-JP", "日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void ParseUnit_WithCulture(string culture, string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + JapaneseHydrometerScaleUnit parsedUnit = JapaneseHydrometerScale.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(JapaneseHydrometerScale.TryParseUnit(abbreviation, out JapaneseHydrometerScaleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(JapaneseHydrometerScale.TryParseUnit(abbreviation, out JapaneseHydrometerScaleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("en-US", "°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("en-US", "1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("en-US", "SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + [InlineData("ja-JP", "°Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("ja-JP", "°Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("ja-JP", "日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + using var _ = new CultureScope(culture); + Assert.True(JapaneseHydrometerScale.TryParseUnit(abbreviation, out JapaneseHydrometerScaleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°Bé heavy", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("en-US", "°Bé light", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("en-US", "1/SG", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity)] + [InlineData("en-US", "SMV", JapaneseHydrometerScaleUnit.SakeMeterValue)] + [InlineData("ja-JP", "°Bh", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy)] + [InlineData("ja-JP", "°Bl", JapaneseHydrometerScaleUnit.DegreeBaumeLight)] + [InlineData("ja-JP", "日本酒度", JapaneseHydrometerScaleUnit.SakeMeterValue)] + public void TryParseUnit_WithCulture(string culture, string abbreviation, JapaneseHydrometerScaleUnit expectedUnit) + { + Assert.True(JapaneseHydrometerScale.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out JapaneseHydrometerScaleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, "°Bé heavy")] + [InlineData("en-US", JapaneseHydrometerScaleUnit.DegreeBaumeLight, "°Bé light")] + [InlineData("en-US", JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, "1/SG")] + [InlineData("en-US", JapaneseHydrometerScaleUnit.SakeMeterValue, "SMV")] + [InlineData("ja-JP", JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, "°Bh")] + [InlineData("ja-JP", JapaneseHydrometerScaleUnit.DegreeBaumeLight, "°Bl")] + [InlineData("ja-JP", JapaneseHydrometerScaleUnit.SakeMeterValue, "日本酒度")] + public void GetAbbreviationForCulture(string culture, JapaneseHydrometerScaleUnit unit, string expectedAbbreviation) + { + var defaultAbbreviation = JapaneseHydrometerScale.GetAbbreviation(unit, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + } + + [Fact] + public void GetAbbreviationWithDefaultCulture() + { + Assert.All(JapaneseHydrometerScale.Units, unit => + { + var expectedAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + + var defaultAbbreviation = JapaneseHydrometerScale.GetAbbreviation(unit); + + Assert.Equal(expectedAbbreviation, defaultAbbreviation); + }); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(JapaneseHydrometerScaleUnit unit) + { + var inBaseUnits = JapaneseHydrometerScale.From(1.0, JapaneseHydrometerScale.BaseUnit); + var converted = inBaseUnits.ToUnit(unit); + + var conversionFactor = GetConversionFactor(unit); + AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); + Assert.Equal(unit, converted.Unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_WithSameUnits_AreEqual(JapaneseHydrometerScaleUnit unit) + { + var quantity = JapaneseHydrometerScale.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(JapaneseHydrometerScaleUnit unit) + { + Assert.All(JapaneseHydrometerScale.Units.Where(u => u != JapaneseHydrometerScale.BaseUnit), fromUnit => + { + var quantity = JapaneseHydrometerScale.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + Assert.Equal(quantity, converted); + }); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(JapaneseHydrometerScaleUnit unit) + { + var quantity = default(JapaneseHydrometerScale); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(JapaneseHydrometerScaleUnit unit) + { + var quantity = JapaneseHydrometerScale.From(3, JapaneseHydrometerScale.BaseUnit); + JapaneseHydrometerScale expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + Assert.Equal(expectedQuantity, convertedQuantity); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + Assert.Equal(expectedQuantity, convertedQuantity); + }); + } + + [Fact] + public void ConversionRoundTrip() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(3); + Assert.Equal(3, JapaneseHydrometerScale.FromDegreesBaumeHeavy(reciprocalspecificgravity.DegreesBaumeHeavy).ReciprocalSpecificGravities); + Assert.Equal(3, JapaneseHydrometerScale.FromDegreesBaumeLight(reciprocalspecificgravity.DegreesBaumeLight).ReciprocalSpecificGravities); + Assert.Equal(3, JapaneseHydrometerScale.FromReciprocalSpecificGravities(reciprocalspecificgravity.ReciprocalSpecificGravities).ReciprocalSpecificGravities); + Assert.Equal(3, JapaneseHydrometerScale.FromSakeMeterValues(reciprocalspecificgravity.SakeMeterValues).ReciprocalSpecificGravities); + } + + [Fact] + public void ArithmeticOperators() + { + JapaneseHydrometerScale v = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.Equal(-1, -v.ReciprocalSpecificGravities); + Assert.Equal(2, (JapaneseHydrometerScale.FromReciprocalSpecificGravities(3) - v).ReciprocalSpecificGravities); + Assert.Equal(2, (v + v).ReciprocalSpecificGravities); + Assert.Equal(10, (v * 10).ReciprocalSpecificGravities); + Assert.Equal(10, (10 * v).ReciprocalSpecificGravities); + Assert.Equal(2, (JapaneseHydrometerScale.FromReciprocalSpecificGravities(10) / 5).ReciprocalSpecificGravities); + Assert.Equal(2, JapaneseHydrometerScale.FromReciprocalSpecificGravities(10) / JapaneseHydrometerScale.FromReciprocalSpecificGravities(5)); + } + + [Fact] + public void ComparisonOperators() + { + JapaneseHydrometerScale oneReciprocalSpecificGravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + JapaneseHydrometerScale twoReciprocalSpecificGravities = JapaneseHydrometerScale.FromReciprocalSpecificGravities(2); + + Assert.True(oneReciprocalSpecificGravity < twoReciprocalSpecificGravities); + Assert.True(oneReciprocalSpecificGravity <= twoReciprocalSpecificGravities); + Assert.True(twoReciprocalSpecificGravities > oneReciprocalSpecificGravity); + Assert.True(twoReciprocalSpecificGravities >= oneReciprocalSpecificGravity); + + Assert.False(oneReciprocalSpecificGravity > twoReciprocalSpecificGravities); + Assert.False(oneReciprocalSpecificGravity >= twoReciprocalSpecificGravities); + Assert.False(twoReciprocalSpecificGravities < oneReciprocalSpecificGravity); + Assert.False(twoReciprocalSpecificGravities <= oneReciprocalSpecificGravity); + } + + [Fact] + public void CompareToIsImplemented() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.Equal(0, reciprocalspecificgravity.CompareTo(reciprocalspecificgravity)); + Assert.True(reciprocalspecificgravity.CompareTo(JapaneseHydrometerScale.Zero) > 0); + Assert.True(JapaneseHydrometerScale.Zero.CompareTo(reciprocalspecificgravity) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.Throws(() => reciprocalspecificgravity.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.Throws(() => reciprocalspecificgravity.CompareTo(null)); + } + + [Theory] + [InlineData(1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, 1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, true)] // Same value and unit. + [InlineData(1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, 2, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, false)] // Different value. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, JapaneseHydrometerScaleUnit unitA, double valueB, JapaneseHydrometerScaleUnit unitB, bool expectEqual) + { + var a = new JapaneseHydrometerScale(valueA, unitA); + var b = new JapaneseHydrometerScale(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = JapaneseHydrometerScale.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.False(reciprocalspecificgravity.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + JapaneseHydrometerScale reciprocalspecificgravity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + Assert.False(reciprocalspecificgravity.Equals(null)); + } + + [Theory] + [InlineData(1, 2)] + [InlineData(100, 110)] + [InlineData(100, 90)] + public void Equals_WithTolerance(double firstValue, double secondValue) + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(firstValue); + var otherQuantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(secondValue); + JapaneseHydrometerScale maxTolerance = quantity > otherQuantity ? quantity - otherQuantity : otherQuantity - quantity; + var largerTolerance = maxTolerance * 1.1m; + var smallerTolerance = maxTolerance / 1.1m; + Assert.True(quantity.Equals(quantity, JapaneseHydrometerScale.Zero)); + Assert.True(quantity.Equals(quantity, maxTolerance)); + Assert.True(quantity.Equals(otherQuantity, maxTolerance)); + Assert.True(quantity.Equals(otherQuantity, largerTolerance)); + Assert.False(quantity.Equals(otherQuantity, smallerTolerance)); + } + + [Fact] + public void Equals_WithNegativeTolerance_ThrowsArgumentOutOfRangeException() + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1); + var negativeTolerance = JapaneseHydrometerScale.FromReciprocalSpecificGravities(-1); + Assert.Throws(() => quantity.Equals(quantity, negativeTolerance)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = EnumHelper.GetValues(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(JapaneseHydrometerScale.BaseDimensions is null); + } + + [Fact] + public void Units_ReturnsTheQuantityInfoUnits() + { + Assert.Equal(JapaneseHydrometerScale.Info.Units, JapaneseHydrometerScale.Units); + } + + [Fact] + public void DefaultConversionFunctions_ReturnsTheDefaultUnitConverter() + { + Assert.Equal(UnitConverter.Default, JapaneseHydrometerScale.DefaultConversionFunctions); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + using var _ = new CultureScope("en-US"); + Assert.Equal("1 °Bé heavy", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.DegreeBaumeHeavy).ToString()); + Assert.Equal("1 °Bé light", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.DegreeBaumeLight).ToString()); + Assert.Equal("1 1/SG", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity).ToString()); + Assert.Equal("1 SMV", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.SakeMeterValue).ToString()); + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 °Bé heavy", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.DegreeBaumeHeavy).ToString(swedishCulture)); + Assert.Equal("1 °Bé light", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.DegreeBaumeLight).ToString(swedishCulture)); + Assert.Equal("1 1/SG", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity).ToString(swedishCulture)); + Assert.Equal("1 SMV", new JapaneseHydrometerScale(1, JapaneseHydrometerScaleUnit.SakeMeterValue).ToString(swedishCulture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1.0); + CultureInfo formatProvider = cultureName == null + ? null + : CultureInfo.GetCultureInfo(cultureName); + + Assert.Equal(quantity.ToString("G", formatProvider), quantity.ToString(null, formatProvider)); + } + + [Theory] + [InlineData(null)] + [InlineData("g")] + public void ToString_NullProvider_EqualsCurrentCulture(string format) + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(1.0); + var expected = Comparison.GetHashCode(typeof(JapaneseHydrometerScale), quantity.As(JapaneseHydrometerScale.BaseUnit)); + Assert.Equal(expected, quantity.GetHashCode()); + } + + [Theory] + [InlineData(1.0)] + [InlineData(-1.0)] + public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) + { + var quantity = JapaneseHydrometerScale.FromReciprocalSpecificGravities(value); + Assert.Equal(JapaneseHydrometerScale.FromReciprocalSpecificGravities(-value), -quantity); + } + } +} diff --git a/UnitsNet/CustomCode/Quantities/JapaneseHydrometerScale.extra.cs b/UnitsNet/CustomCode/Quantities/JapaneseHydrometerScale.extra.cs new file mode 100644 index 0000000000..0e66877158 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/JapaneseHydrometerScale.extra.cs @@ -0,0 +1,31 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.Units; + +namespace UnitsNet +{ + public partial struct JapaneseHydrometerScale + { + private static readonly Density WaterDensityAt4C = Density.FromKilogramsPerCubicMeter(999.974950); + + /// + /// Converts this hydrometer scale reading to an equivalent density, using the density of water at 4 °C as the reference. + /// + /// The density unit to convert to. + /// A representing the equivalent density. + public Density ToDensity(DensityUnit unit = DensityUnit.CentigramPerDeciliter) + { + return (WaterDensityAt4C / ReciprocalSpecificGravities).ToUnit(unit); + } + + /// + /// Converts this hydrometer scale reading to an equivalent specific gravity. + /// + /// A representing the equivalent specific gravity. + public Ratio ToSpecificGravity() + { + return Ratio.FromDecimalFractions(1 / ReciprocalSpecificGravities); + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/JapaneseHydrometerScale.g.cs b/UnitsNet/GeneratedCode/Quantities/JapaneseHydrometerScale.g.cs new file mode 100644 index 0000000000..92cb84ae7e --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/JapaneseHydrometerScale.g.cs @@ -0,0 +1,648 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System.Globalization; +using System.Resources; +using System.Runtime.Serialization; +using UnitsNet.Debug; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// A dimensionless quantity representing hydrometer scale readings derived from reciprocal specific gravity, including degrees Baumé and Sake Meter Value. + /// + [DataContract] + [DebuggerDisplay(QuantityDebugProxy.DisplayFormat)] + [DebuggerTypeProxy(typeof(QuantityDebugProxy))] + public readonly partial struct JapaneseHydrometerScale : + ILinearQuantity, +#if NET7_0_OR_GREATER + IDivisionOperators, + IComparisonOperators, + IParsable, +#endif + IComparable, + IComparable, + IEquatable, + IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 1)] + private readonly QuantityValue _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 2)] + private readonly JapaneseHydrometerScaleUnit? _unit; + + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class JapaneseHydrometerScaleInfo: QuantityInfo + { + /// + public JapaneseHydrometerScaleInfo(string name, JapaneseHydrometerScaleUnit baseUnit, IEnumerable> unitMappings, JapaneseHydrometerScale zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public JapaneseHydrometerScaleInfo(string name, JapaneseHydrometerScaleUnit baseUnit, IEnumerable> unitMappings, JapaneseHydrometerScale zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, JapaneseHydrometerScale.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.JapaneseHydrometerScale", typeof(JapaneseHydrometerScale).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the JapaneseHydrometerScale quantity. + /// + /// A new instance of the class with the default settings. + public static JapaneseHydrometerScaleInfo CreateDefault() + { + return new JapaneseHydrometerScaleInfo(nameof(JapaneseHydrometerScale), DefaultBaseUnit, GetDefaultMappings(), new JapaneseHydrometerScale(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// Creates a new instance of the class with the default settings for the JapaneseHydrometerScale quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static JapaneseHydrometerScaleInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new JapaneseHydrometerScaleInfo(nameof(JapaneseHydrometerScale), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new JapaneseHydrometerScale(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of JapaneseHydrometerScale is ReciprocalSpecificGravity. All conversions, as defined in the , go via this value. + /// + public static JapaneseHydrometerScaleUnit DefaultBaseUnit { get; } = JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for JapaneseHydrometerScale. + public static IEnumerable> GetDefaultMappings() + { + yield return new (JapaneseHydrometerScaleUnit.DegreeBaumeHeavy, "DegreeBaumeHeavy", "DegreesBaumeHeavy", BaseUnits.Undefined, + new ConversionExpression(coefficient: new QuantityValue(-1443, 10), constantTerm: new QuantityValue(1443, 10)), + new ConversionExpression(coefficient: new QuantityValue(-10, 1443), constantTerm: 1) + ); + yield return new (JapaneseHydrometerScaleUnit.DegreeBaumeLight, "DegreeBaumeLight", "DegreesBaumeLight", BaseUnits.Undefined, + new ConversionExpression(coefficient: new QuantityValue(1443, 10), constantTerm: new QuantityValue(-1343, 10)), + new ConversionExpression(coefficient: new QuantityValue(10, 1443), constantTerm: new QuantityValue(1343, 1443)) + ); + yield return new (JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity, "ReciprocalSpecificGravity", "ReciprocalSpecificGravities", BaseUnits.Undefined); + yield return new (JapaneseHydrometerScaleUnit.SakeMeterValue, "SakeMeterValue", "SakeMeterValues", BaseUnits.Undefined, + new ConversionExpression(coefficient: 1443, constantTerm: -1443), + new ConversionExpression(coefficient: new QuantityValue(1, 1443), constantTerm: 1) + ); + } + } + + static JapaneseHydrometerScale() + { + Info = UnitsNetSetup.CreateQuantityInfo(JapaneseHydrometerScaleInfo.CreateDefault); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + public JapaneseHydrometerScale(QuantityValue value, JapaneseHydrometerScaleUnit unit) + { + _value = value; + _unit = unit; + } + + #region Static Properties + + /// + /// The containing the default generated conversion functions for instances. + /// + [Obsolete("Replaced by UnitConverter.Default")] + public static UnitConverter DefaultConversionFunctions => UnitConverter.Default; + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions => Info.BaseDimensions; + + /// + /// The base unit of JapaneseHydrometerScale, which is ReciprocalSpecificGravity. All conversions go via this value. + /// + public static JapaneseHydrometerScaleUnit BaseUnit => Info.BaseUnitInfo.Value; + + /// + /// All units of measurement for the JapaneseHydrometerScale quantity. + /// + public static IReadOnlyCollection Units => Info.Units; + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit ReciprocalSpecificGravity. + /// + public static JapaneseHydrometerScale Zero => Info.Zero; + + #endregion + + #region Properties + + /// + public QuantityValue Value => _value; + + /// + public JapaneseHydrometerScaleUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + #region Explicit implementations + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + UnitKey IQuantity.UnitKey => UnitKey.ForUnit(Unit); + +#if NETSTANDARD2_0 + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + IQuantityInstanceInfo IQuantityOfType.QuantityInfo => Info; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + Enum IQuantity.Unit => Unit; +#endif + + #endregion + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public QuantityValue DegreesBaumeHeavy => this.As(JapaneseHydrometerScaleUnit.DegreeBaumeHeavy); + + /// + /// Gets a value of this quantity converted into + /// + public QuantityValue DegreesBaumeLight => this.As(JapaneseHydrometerScaleUnit.DegreeBaumeLight); + + /// + /// Gets a value of this quantity converted into + /// + public QuantityValue ReciprocalSpecificGravities => this.As(JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + + /// + /// Gets a value of this quantity converted into + /// + public QuantityValue SakeMeterValues => this.As(JapaneseHydrometerScaleUnit.SakeMeterValue); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(JapaneseHydrometerScaleUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(JapaneseHydrometerScaleUnit unit, IFormatProvider? provider) + { + return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static JapaneseHydrometerScale FromDegreesBaumeHeavy(QuantityValue value) + { + return new JapaneseHydrometerScale(value, JapaneseHydrometerScaleUnit.DegreeBaumeHeavy); + } + + /// + /// Creates a from . + /// + public static JapaneseHydrometerScale FromDegreesBaumeLight(QuantityValue value) + { + return new JapaneseHydrometerScale(value, JapaneseHydrometerScaleUnit.DegreeBaumeLight); + } + + /// + /// Creates a from . + /// + public static JapaneseHydrometerScale FromReciprocalSpecificGravities(QuantityValue value) + { + return new JapaneseHydrometerScale(value, JapaneseHydrometerScaleUnit.ReciprocalSpecificGravity); + } + + /// + /// Creates a from . + /// + public static JapaneseHydrometerScale FromSakeMeterValues(QuantityValue value) + { + return new JapaneseHydrometerScale(value, JapaneseHydrometerScaleUnit.SakeMeterValue); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// JapaneseHydrometerScale unit value. + public static JapaneseHydrometerScale From(QuantityValue value, JapaneseHydrometerScaleUnit fromUnit) + { + return new JapaneseHydrometerScale(value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static JapaneseHydrometerScale Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static JapaneseHydrometerScale Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse(str, provider, From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out JapaneseHydrometerScale result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([NotNullWhen(true)]string? str, IFormatProvider? provider, out JapaneseHydrometerScale result) + { + return QuantityParser.Default.TryParse(str, provider, From, out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static JapaneseHydrometerScaleUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// Format to use when parsing the unit. Defaults to if null. + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static JapaneseHydrometerScaleUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value; + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out JapaneseHydrometerScaleUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing the unit. Defaults to if null. + public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out JapaneseHydrometerScaleUnit unit) + { + return UnitParser.Default.TryParse(str, Info, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static JapaneseHydrometerScale operator -(JapaneseHydrometerScale right) + { + return new JapaneseHydrometerScale(-right.Value, right.Unit); + } + + /// Get from adding two . + public static JapaneseHydrometerScale operator +(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return new JapaneseHydrometerScale(left.Value + right.As(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static JapaneseHydrometerScale operator -(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return new JapaneseHydrometerScale(left.Value - right.As(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static JapaneseHydrometerScale operator *(QuantityValue left, JapaneseHydrometerScale right) + { + return new JapaneseHydrometerScale(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static JapaneseHydrometerScale operator *(JapaneseHydrometerScale left, QuantityValue right) + { + return new JapaneseHydrometerScale(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static JapaneseHydrometerScale operator /(JapaneseHydrometerScale left, QuantityValue right) + { + return new JapaneseHydrometerScale(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static QuantityValue operator /(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.ReciprocalSpecificGravities / right.ReciprocalSpecificGravities; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.Value <= right.As(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.Value >= right.As(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.Value < right.As(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.Value > right.As(left.Unit); + } + + /// + /// Determines whether two instances are equal. + /// + /// + /// Equality is evaluated in a unit-aware manner. The right-hand operand is converted to the unit of the left-hand + /// operand and then the underlying numeric values are compared. + /// This means two quantities with numerically equal values but different units will be considered equal. + /// The operator delegates to , which implements this conversion-and-compare logic. + /// + public static bool operator ==(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return left.Equals(right); + } + + /// + /// Determines whether two instances are not equal. + /// + /// + /// This operator is the logical negation of . + /// See that operator (and ) for details on how equality is evaluated + /// (i.e., by converting one operand to the other's unit and comparing their numeric values). + /// + public static bool operator !=(JapaneseHydrometerScale left, JapaneseHydrometerScale right) + { + return !(left == right); + } + + /// + /// + /// Determines whether the specified object is equal to the current instance. + /// + /// + /// Returns false if is null or not a . + /// When is a , this method delegates to + /// , which performs a unit-aware comparison by converting the other + /// instance to this instance's unit before comparing numeric values. + /// + public override bool Equals(object? obj) + { + if (obj is not JapaneseHydrometerScale otherQuantity) + return false; + + return Equals(otherQuantity); + } + + /// + /// + /// Determines whether the current instance is equal to another instance. + /// + /// + /// Comparison is performed by converting to this instance's unit and then comparing the underlying numeric values. + /// This makes two quantities equal even when their units differ, provided the converted numeric values are equal. + /// + public bool Equals(JapaneseHydrometerScale other) + { + return _value.Equals(other.As(this.Unit)); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current JapaneseHydrometerScale. + public override int GetHashCode() + { + return Comparison.GetHashCode(typeof(JapaneseHydrometerScale), this.As(BaseUnit)); + } + + /// + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + public int CompareTo(object? obj) + { + if (obj is not JapaneseHydrometerScale otherQuantity) + throw obj is null ? new ArgumentNullException(nameof(obj)) : ExceptionHelper.CreateArgumentException(obj, nameof(obj)); + + return CompareTo(otherQuantity); + } + + /// + /// Compares the current with another and returns an integer that indicates + /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the other quantity, when converted to the same unit. + /// + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(JapaneseHydrometerScale other) + { + return _value.CompareTo(other.As(this.Unit)); + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null, null); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + public string ToString( + [StringSyntax(StringSyntaxAttribute.NumericFormat)] string? format, + IFormatProvider? provider) + { + return QuantityFormatter.Default.Format(this, format, provider); + } + + #endregion + + } +} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 67ad33f293..c74acdeb7d 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -92,6 +92,7 @@ internal static class DefaultProvider Information.Info, Irradiance.Info, Irradiation.Info, + JapaneseHydrometerScale.Info, Jerk.Info, KinematicViscosity.Info, LeakRate.Info, diff --git a/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.ja-JP.restext b/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.ja-JP.restext new file mode 100644 index 0000000000..21bd5e22d5 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.ja-JP.restext @@ -0,0 +1,3 @@ +DegreesBaumeHeavy=°Bh +DegreesBaumeLight=°Bl +SakeMeterValues=日本酒度 diff --git a/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.restext b/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.restext new file mode 100644 index 0000000000..b2ae847402 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/JapaneseHydrometerScale.restext @@ -0,0 +1,4 @@ +DegreesBaumeHeavy=°Bé heavy +DegreesBaumeLight=°Bé light +ReciprocalSpecificGravities=1/SG +SakeMeterValues=SMV diff --git a/UnitsNet/GeneratedCode/Units/JapaneseHydrometerScaleUnit.g.cs b/UnitsNet/GeneratedCode/Units/JapaneseHydrometerScaleUnit.g.cs new file mode 100644 index 0000000000..5e23f00cac --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/JapaneseHydrometerScaleUnit.g.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum JapaneseHydrometerScaleUnit + { + DegreeBaumeHeavy = 6, + DegreeBaumeLight = 9, + ReciprocalSpecificGravity = 5, + SakeMeterValue = 7, + } + + #pragma warning restore 1591 +}