From 3e99347d08915a64fb430872dadeabe8567f64b8 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Wed, 8 Feb 2023 14:00:23 -0500 Subject: [PATCH 1/4] Convert Power to double --- Common/UnitDefinitions/Power.json | 29 +- .../GeneratedCode/Quantities/Power.g.cs | 56 +-- .../UnitsNetBaseJsonConverterTest.cs | 3 +- .../UnitsNetIComparableJsonConverterTest.cs | 2 +- .../UnitsNetIQuantityJsonConverterTest.cs | 2 +- UnitsNet.Tests/CustomCode/MassFlowTests.cs | 2 +- UnitsNet.Tests/CustomCode/PowerRatioTests.cs | 4 +- UnitsNet.Tests/CustomCode/PowerTests.cs | 53 +-- .../CustomCode/SpecificEnergyTests.cs | 2 +- UnitsNet.Tests/DecimalOverloadTests.cs | 2 +- .../TestsBase/PowerTestsBase.g.cs | 151 ++++---- UnitsNet.Tests/IntOverloadTests.cs | 2 +- UnitsNet.Tests/LongOverloadTests.cs | 2 +- UnitsNet/GeneratedCode/Quantities/Power.g.cs | 322 +++++++++--------- 14 files changed, 321 insertions(+), 311 deletions(-) diff --git a/Common/UnitDefinitions/Power.json b/Common/UnitDefinitions/Power.json index ce491fa507..1e245be567 100644 --- a/Common/UnitDefinitions/Power.json +++ b/Common/UnitDefinitions/Power.json @@ -1,7 +1,6 @@ { "Name": "Power", "BaseUnit": "Watt", - "ValueType": "decimal", "XmlDocSummary": "In physics, power is the rate of doing work. It is equivalent to an amount of energy consumed per unit time.", "BaseDimensions": { "L": 2, @@ -25,8 +24,8 @@ { "SingularName": "MechanicalHorsepower", "PluralName": "MechanicalHorsepower", - "FromUnitToBaseFunc": "{x} * 745.69m", - "FromBaseToUnitFunc": "{x} / 745.69m", + "FromUnitToBaseFunc": "{x} * 745.69", + "FromBaseToUnitFunc": "{x} / 745.69", "Localization": [ { "Culture": "en-US", @@ -37,8 +36,8 @@ { "SingularName": "MetricHorsepower", "PluralName": "MetricHorsepower", - "FromUnitToBaseFunc": "{x} * 735.49875m", - "FromBaseToUnitFunc": "{x} / 735.49875m", + "FromUnitToBaseFunc": "{x} * 735.49875", + "FromBaseToUnitFunc": "{x} / 735.49875", "Localization": [ { "Culture": "en-US", @@ -49,8 +48,8 @@ { "SingularName": "ElectricalHorsepower", "PluralName": "ElectricalHorsepower", - "FromUnitToBaseFunc": "{x} * 746m", - "FromBaseToUnitFunc": "{x} / 746m", + "FromUnitToBaseFunc": "{x} * 746", + "FromBaseToUnitFunc": "{x} / 746", "Localization": [ { "Culture": "en-US", @@ -61,8 +60,8 @@ { "SingularName": "BoilerHorsepower", "PluralName": "BoilerHorsepower", - "FromUnitToBaseFunc": "{x} * 9812.5m", - "FromBaseToUnitFunc": "{x} / 9812.5m", + "FromUnitToBaseFunc": "{x} * 9812.5", + "FromBaseToUnitFunc": "{x} / 9812.5", "Localization": [ { "Culture": "en-US", @@ -73,8 +72,8 @@ { "SingularName": "HydraulicHorsepower", "PluralName": "HydraulicHorsepower", - "FromUnitToBaseFunc": "{x} * 745.69988145m", - "FromBaseToUnitFunc": "{x} / 745.69988145m", + "FromUnitToBaseFunc": "{x} * 745.69988145", + "FromBaseToUnitFunc": "{x} / 745.69988145", "Localization": [ { "Culture": "en-US", @@ -85,8 +84,8 @@ { "SingularName": "BritishThermalUnitPerHour", "PluralName": "BritishThermalUnitsPerHour", - "FromUnitToBaseFunc": "{x} * 0.29307107017m", - "FromBaseToUnitFunc": "{x} / 0.29307107017m", + "FromUnitToBaseFunc": "{x} * 0.29307107017", + "FromBaseToUnitFunc": "{x} / 0.29307107017", "Prefixes": [ "Kilo", "Mega" ], "Localization": [ { @@ -98,8 +97,8 @@ { "SingularName": "JoulePerHour", "PluralName": "JoulesPerHour", - "FromUnitToBaseFunc": "{x} / 3600m", - "FromBaseToUnitFunc": "{x} * 3600m", + "FromUnitToBaseFunc": "{x} / 3600", + "FromBaseToUnitFunc": "{x} * 3600", "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Power.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Power.g.cs index e10cb3d208..e022e04860 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Power.g.cs @@ -66,12 +66,12 @@ public Power(double value, PowerUnit unit) /// /// Represents the largest possible value of Duration /// - public static Power MaxValue { get; } = new Power(79228162514264337593543950335d, BaseUnit); + public static Power MaxValue { get; } = new Power(double.MaxValue, BaseUnit); /// /// Represents the smallest possible value of Duration /// - public static Power MinValue { get; } = new Power(-79228162514264337593543950335d, BaseUnit); + public static Power MinValue { get; } = new Power(double.MinValue, BaseUnit); /// /// Gets an instance of this quantity with a value of 0 in the base unit Second. @@ -409,26 +409,26 @@ private double GetValueInBaseUnit() { return Unit switch { - PowerUnit.BoilerHorsepower => _value * 9812.5d, - PowerUnit.BritishThermalUnitPerHour => _value * 0.29307107017d, + PowerUnit.BoilerHorsepower => _value * 9812.5, + PowerUnit.BritishThermalUnitPerHour => _value * 0.29307107017, PowerUnit.Decawatt => (_value) * 1e1d, PowerUnit.Deciwatt => (_value) * 1e-1d, - PowerUnit.ElectricalHorsepower => _value * 746d, + PowerUnit.ElectricalHorsepower => _value * 746, PowerUnit.Femtowatt => (_value) * 1e-15d, - PowerUnit.GigajoulePerHour => (_value / 3600d) * 1e9d, + PowerUnit.GigajoulePerHour => (_value / 3600) * 1e9d, PowerUnit.Gigawatt => (_value) * 1e9d, - PowerUnit.HydraulicHorsepower => _value * 745.69988145d, - PowerUnit.JoulePerHour => _value / 3600d, - PowerUnit.KilobritishThermalUnitPerHour => (_value * 0.29307107017d) * 1e3d, - PowerUnit.KilojoulePerHour => (_value / 3600d) * 1e3d, + PowerUnit.HydraulicHorsepower => _value * 745.69988145, + PowerUnit.JoulePerHour => _value / 3600, + PowerUnit.KilobritishThermalUnitPerHour => (_value * 0.29307107017) * 1e3d, + PowerUnit.KilojoulePerHour => (_value / 3600) * 1e3d, PowerUnit.Kilowatt => (_value) * 1e3d, - PowerUnit.MechanicalHorsepower => _value * 745.69d, - PowerUnit.MegabritishThermalUnitPerHour => (_value * 0.29307107017d) * 1e6d, - PowerUnit.MegajoulePerHour => (_value / 3600d) * 1e6d, + PowerUnit.MechanicalHorsepower => _value * 745.69, + PowerUnit.MegabritishThermalUnitPerHour => (_value * 0.29307107017) * 1e6d, + PowerUnit.MegajoulePerHour => (_value / 3600) * 1e6d, PowerUnit.Megawatt => (_value) * 1e6d, - PowerUnit.MetricHorsepower => _value * 735.49875d, + PowerUnit.MetricHorsepower => _value * 735.49875, PowerUnit.Microwatt => (_value) * 1e-6d, - PowerUnit.MillijoulePerHour => (_value / 3600d) * 1e-3d, + PowerUnit.MillijoulePerHour => (_value / 3600) * 1e-3d, PowerUnit.Milliwatt => (_value) * 1e-3d, PowerUnit.Nanowatt => (_value) * 1e-9d, PowerUnit.Petawatt => (_value) * 1e15d, @@ -448,26 +448,26 @@ private double GetValueAs(PowerUnit unit) return unit switch { - PowerUnit.BoilerHorsepower => baseUnitValue / 9812.5d, - PowerUnit.BritishThermalUnitPerHour => baseUnitValue / 0.29307107017d, + PowerUnit.BoilerHorsepower => baseUnitValue / 9812.5, + PowerUnit.BritishThermalUnitPerHour => baseUnitValue / 0.29307107017, PowerUnit.Decawatt => (baseUnitValue) / 1e1d, PowerUnit.Deciwatt => (baseUnitValue) / 1e-1d, - PowerUnit.ElectricalHorsepower => baseUnitValue / 746d, + PowerUnit.ElectricalHorsepower => baseUnitValue / 746, PowerUnit.Femtowatt => (baseUnitValue) / 1e-15d, - PowerUnit.GigajoulePerHour => (baseUnitValue * 3600d) / 1e9d, + PowerUnit.GigajoulePerHour => (baseUnitValue * 3600) / 1e9d, PowerUnit.Gigawatt => (baseUnitValue) / 1e9d, - PowerUnit.HydraulicHorsepower => baseUnitValue / 745.69988145d, - PowerUnit.JoulePerHour => baseUnitValue * 3600d, - PowerUnit.KilobritishThermalUnitPerHour => (baseUnitValue / 0.29307107017d) / 1e3d, - PowerUnit.KilojoulePerHour => (baseUnitValue * 3600d) / 1e3d, + PowerUnit.HydraulicHorsepower => baseUnitValue / 745.69988145, + PowerUnit.JoulePerHour => baseUnitValue * 3600, + PowerUnit.KilobritishThermalUnitPerHour => (baseUnitValue / 0.29307107017) / 1e3d, + PowerUnit.KilojoulePerHour => (baseUnitValue * 3600) / 1e3d, PowerUnit.Kilowatt => (baseUnitValue) / 1e3d, - PowerUnit.MechanicalHorsepower => baseUnitValue / 745.69d, - PowerUnit.MegabritishThermalUnitPerHour => (baseUnitValue / 0.29307107017d) / 1e6d, - PowerUnit.MegajoulePerHour => (baseUnitValue * 3600d) / 1e6d, + PowerUnit.MechanicalHorsepower => baseUnitValue / 745.69, + PowerUnit.MegabritishThermalUnitPerHour => (baseUnitValue / 0.29307107017) / 1e6d, + PowerUnit.MegajoulePerHour => (baseUnitValue * 3600) / 1e6d, PowerUnit.Megawatt => (baseUnitValue) / 1e6d, - PowerUnit.MetricHorsepower => baseUnitValue / 735.49875d, + PowerUnit.MetricHorsepower => baseUnitValue / 735.49875, PowerUnit.Microwatt => (baseUnitValue) / 1e-6d, - PowerUnit.MillijoulePerHour => (baseUnitValue * 3600d) / 1e-3d, + PowerUnit.MillijoulePerHour => (baseUnitValue * 3600) / 1e-3d, PowerUnit.Milliwatt => (baseUnitValue) / 1e-3d, PowerUnit.Nanowatt => (baseUnitValue) / 1e-9d, PowerUnit.Petawatt => (baseUnitValue) / 1e15d, diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs index f4e42ab480..df692a3f12 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs @@ -54,8 +54,7 @@ public void UnitsNetBaseJsonConverter_ConvertValueUnit_works_as_expected() Assert.NotNull(result); Assert.IsType(result); - Assert.True(Power.FromWatts(10.2365m).Equals((Power)result, 1E-5m, ComparisonType.Absolute)); - + Assert.True(Power.FromWatts(10.2365).Equals((Power)result, 1e-5, ComparisonType.Absolute)); } [Fact] diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs index 03c96a81b1..436d673975 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs @@ -119,7 +119,7 @@ public void UnitsNetIComparableJsonConverter_ReadJson_works_as_expected() Assert.NotNull(result); Assert.IsType(result); - Assert.Equal(120M, ((Power)result).Watts); + Assert.Equal(120, ((Power)result).Watts); } } } diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs index 8ed7de7c29..cf3fe62127 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs @@ -135,7 +135,7 @@ public void UnitsNetIQuantityJsonConverter_ReadJson_works_as_expected() Assert.NotNull(result); Assert.IsType(result); - Assert.Equal(10.3654M, ((Power)result).Watts); + Assert.Equal(10.3654, ((Power)result).Watts); } } } diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs index 5c64e0b394..3c0ca9836b 100644 --- a/UnitsNet.Tests/CustomCode/MassFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -108,7 +108,7 @@ public void TimeSpanTimesMassFlowEqualsMass() public void MassFlowDividedByBrakeSpecificFuelConsumptionEqualsPower() { Power power = MassFlow.FromTonnesPerDay(20) / BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(180.0); - AssertEx.EqualTolerance(20.0m / 24.0m * 1e6m / 180.0m, power.Kilowatts, 1E-11m); + AssertEx.EqualTolerance(20.0 / 24.0 * 1e6 / 180.0, power.Kilowatts, 1e-11); } [Fact] diff --git a/UnitsNet.Tests/CustomCode/PowerRatioTests.cs b/UnitsNet.Tests/CustomCode/PowerRatioTests.cs index ae0ebf6fad..adb1ee96fc 100644 --- a/UnitsNet.Tests/CustomCode/PowerRatioTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerRatioTests.cs @@ -55,8 +55,8 @@ public void ExpectPowerConvertedCorrectly(double power, double expected) public void ExpectPowerRatioConvertedCorrectly(double powerRatio, double expected) { PowerRatio pr = PowerRatio.FromDecibelWatts(powerRatio); - decimal actual = pr.ToPower().Watts; - Assert.Equal((decimal)expected, actual); + var actual = pr.ToPower().Watts; + Assert.Equal(expected, actual); } // http://www.maximintegrated.com/en/app-notes/index.mvp/id/808 diff --git a/UnitsNet.Tests/CustomCode/PowerTests.cs b/UnitsNet.Tests/CustomCode/PowerTests.cs index d51dfcf453..591260c53f 100644 --- a/UnitsNet.Tests/CustomCode/PowerTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerTests.cs @@ -9,57 +9,58 @@ namespace UnitsNet.Tests public class PowerTests : PowerTestsBase { protected override bool SupportsSIUnitSystem => false; - protected override decimal FemtowattsInOneWatt => 1e15m; - protected override decimal GigajoulesPerHourInOneWatt => 3600e-9m; + protected override double FemtowattsInOneWatt => 1e15; - protected override decimal PicowattsInOneWatt => 1e12m; + protected override double GigajoulesPerHourInOneWatt => 3600e-9; - protected override decimal NanowattsInOneWatt => 1e9m; + protected override double PicowattsInOneWatt => 1e12; - protected override decimal MicrowattsInOneWatt => 1e6m; + protected override double NanowattsInOneWatt => 1e9; - protected override decimal MillijoulesPerHourInOneWatt => 3600e3m; + protected override double MicrowattsInOneWatt => 1e6; - protected override decimal MilliwattsInOneWatt => 1e3m; + protected override double MillijoulesPerHourInOneWatt => 3600e3; - protected override decimal DeciwattsInOneWatt => 1e1m; + protected override double MilliwattsInOneWatt => 1e3; - protected override decimal WattsInOneWatt => 1; + protected override double DeciwattsInOneWatt => 1e1; - protected override decimal DecawattsInOneWatt => 1e-1m; + protected override double WattsInOneWatt => 1; - protected override decimal KilojoulesPerHourInOneWatt => 3600e-3m; + protected override double DecawattsInOneWatt => 1e-1; - protected override decimal KilowattsInOneWatt => 1e-3m; + protected override double KilojoulesPerHourInOneWatt => 3600e-3; - protected override decimal MegajoulesPerHourInOneWatt => 3600e-6m; + protected override double KilowattsInOneWatt => 1e-3; - protected override decimal MegawattsInOneWatt => 1e-6m; + protected override double MegajoulesPerHourInOneWatt => 3600e-6; - protected override decimal GigawattsInOneWatt => 1e-9m; + protected override double MegawattsInOneWatt => 1e-6; - protected override decimal TerawattsInOneWatt => 1e-12m; + protected override double GigawattsInOneWatt => 1e-9; - protected override decimal PetawattsInOneWatt => 1e-15m; + protected override double TerawattsInOneWatt => 1e-12; - protected override decimal JoulesPerHourInOneWatt => 3600; + protected override double PetawattsInOneWatt => 1e-15; - protected override decimal KilobritishThermalUnitsPerHourInOneWatt => 3.412141633e-3m; + protected override double JoulesPerHourInOneWatt => 3600; - protected override decimal BoilerHorsepowerInOneWatt => 1.0191082802547770700636942675159e-4m; + protected override double KilobritishThermalUnitsPerHourInOneWatt => 3.412141633e-3; - protected override decimal MegabritishThermalUnitsPerHourInOneWatt => 3.412141633e-6m; + protected override double BoilerHorsepowerInOneWatt => 1.0191082802547770700636942675159e-4; - protected override decimal BritishThermalUnitsPerHourInOneWatt => 3.412141633m; + protected override double MegabritishThermalUnitsPerHourInOneWatt => 3.412141633e-6; - protected override decimal ElectricalHorsepowerInOneWatt => 0.00134048257372654155495978552279m; + protected override double BritishThermalUnitsPerHourInOneWatt => 3.412141633; - protected override decimal HydraulicHorsepowerInOneWatt => 0.00134102207184949258114167291719m; + protected override double ElectricalHorsepowerInOneWatt => 0.00134048257372654155495978552279; - protected override decimal MechanicalHorsepowerInOneWatt => 0.00134103984229371454625916935992m; + protected override double HydraulicHorsepowerInOneWatt => 0.00134102207184949258114167291719; - protected override decimal MetricHorsepowerInOneWatt => 0.00135962161730390432342679032425m; + protected override double MechanicalHorsepowerInOneWatt => 0.00134103984229371454625916935992; + + protected override double MetricHorsepowerInOneWatt => 0.00135962161730390432342679032425; [Fact] public void DurationTimesPowerEqualsEnergy() diff --git a/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs index 89f34675d7..27b5c448ea 100644 --- a/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs @@ -71,7 +71,7 @@ public void DoubleDividedBySpecificEnergyEqualsBrakeSpecificFuelConsumption() public void SpecificEnergyTimesMassFlowEqualsPower() { Power power = SpecificEnergy.FromJoulesPerKilogram(10.0) * MassFlow.FromKilogramsPerSecond(20.0); - Assert.Equal(200m, power.Watts); + Assert.Equal(200, power.Watts); } [Fact] diff --git a/UnitsNet.Tests/DecimalOverloadTests.cs b/UnitsNet.Tests/DecimalOverloadTests.cs index 6b9842d0aa..841c9b162b 100644 --- a/UnitsNet.Tests/DecimalOverloadTests.cs +++ b/UnitsNet.Tests/DecimalOverloadTests.cs @@ -18,7 +18,7 @@ public static void CreatingQuantityWithDoubleBackingFieldFromDecimalReturnsCorre public static void CreatingQuantityWithDecimalBackingFieldFromDecimalReturnsCorrectValue() { Power power = Power.FromWatts(1m); - Assert.Equal(1.0m, power.Watts); + Assert.Equal(1.0, power.Watts); } } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 1ee61d30da..588ed1e4f5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -38,63 +38,63 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class PowerTestsBase : QuantityTestsBase { - protected abstract decimal BoilerHorsepowerInOneWatt { get; } - protected abstract decimal BritishThermalUnitsPerHourInOneWatt { get; } - protected abstract decimal DecawattsInOneWatt { get; } - protected abstract decimal DeciwattsInOneWatt { get; } - protected abstract decimal ElectricalHorsepowerInOneWatt { get; } - protected abstract decimal FemtowattsInOneWatt { get; } - protected abstract decimal GigajoulesPerHourInOneWatt { get; } - protected abstract decimal GigawattsInOneWatt { get; } - protected abstract decimal HydraulicHorsepowerInOneWatt { get; } - protected abstract decimal JoulesPerHourInOneWatt { get; } - protected abstract decimal KilobritishThermalUnitsPerHourInOneWatt { get; } - protected abstract decimal KilojoulesPerHourInOneWatt { get; } - protected abstract decimal KilowattsInOneWatt { get; } - protected abstract decimal MechanicalHorsepowerInOneWatt { get; } - protected abstract decimal MegabritishThermalUnitsPerHourInOneWatt { get; } - protected abstract decimal MegajoulesPerHourInOneWatt { get; } - protected abstract decimal MegawattsInOneWatt { get; } - protected abstract decimal MetricHorsepowerInOneWatt { get; } - protected abstract decimal MicrowattsInOneWatt { get; } - protected abstract decimal MillijoulesPerHourInOneWatt { get; } - protected abstract decimal MilliwattsInOneWatt { get; } - protected abstract decimal NanowattsInOneWatt { get; } - protected abstract decimal PetawattsInOneWatt { get; } - protected abstract decimal PicowattsInOneWatt { get; } - protected abstract decimal TerawattsInOneWatt { get; } - protected abstract decimal WattsInOneWatt { get; } + protected abstract double BoilerHorsepowerInOneWatt { get; } + protected abstract double BritishThermalUnitsPerHourInOneWatt { get; } + protected abstract double DecawattsInOneWatt { get; } + protected abstract double DeciwattsInOneWatt { get; } + protected abstract double ElectricalHorsepowerInOneWatt { get; } + protected abstract double FemtowattsInOneWatt { get; } + protected abstract double GigajoulesPerHourInOneWatt { get; } + protected abstract double GigawattsInOneWatt { get; } + protected abstract double HydraulicHorsepowerInOneWatt { get; } + protected abstract double JoulesPerHourInOneWatt { get; } + protected abstract double KilobritishThermalUnitsPerHourInOneWatt { get; } + protected abstract double KilojoulesPerHourInOneWatt { get; } + protected abstract double KilowattsInOneWatt { get; } + protected abstract double MechanicalHorsepowerInOneWatt { get; } + protected abstract double MegabritishThermalUnitsPerHourInOneWatt { get; } + protected abstract double MegajoulesPerHourInOneWatt { get; } + protected abstract double MegawattsInOneWatt { get; } + protected abstract double MetricHorsepowerInOneWatt { get; } + protected abstract double MicrowattsInOneWatt { get; } + protected abstract double MillijoulesPerHourInOneWatt { get; } + protected abstract double MilliwattsInOneWatt { get; } + protected abstract double NanowattsInOneWatt { get; } + protected abstract double PetawattsInOneWatt { get; } + protected abstract double PicowattsInOneWatt { get; } + protected abstract double TerawattsInOneWatt { get; } + protected abstract double WattsInOneWatt { get; } // ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual decimal BoilerHorsepowerTolerance { get { return 1e-9m; } } - protected virtual decimal BritishThermalUnitsPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal DecawattsTolerance { get { return 1e-9m; } } - protected virtual decimal DeciwattsTolerance { get { return 1e-9m; } } - protected virtual decimal ElectricalHorsepowerTolerance { get { return 1e-9m; } } - protected virtual decimal FemtowattsTolerance { get { return 1e-9m; } } - protected virtual decimal GigajoulesPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal GigawattsTolerance { get { return 1e-9m; } } - protected virtual decimal HydraulicHorsepowerTolerance { get { return 1e-9m; } } - protected virtual decimal JoulesPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal KilobritishThermalUnitsPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal KilojoulesPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal KilowattsTolerance { get { return 1e-9m; } } - protected virtual decimal MechanicalHorsepowerTolerance { get { return 1e-9m; } } - protected virtual decimal MegabritishThermalUnitsPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal MegajoulesPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal MegawattsTolerance { get { return 1e-9m; } } - protected virtual decimal MetricHorsepowerTolerance { get { return 1e-9m; } } - protected virtual decimal MicrowattsTolerance { get { return 1e-9m; } } - protected virtual decimal MillijoulesPerHourTolerance { get { return 1e-9m; } } - protected virtual decimal MilliwattsTolerance { get { return 1e-9m; } } - protected virtual decimal NanowattsTolerance { get { return 1e-9m; } } - protected virtual decimal PetawattsTolerance { get { return 1e-9m; } } - protected virtual decimal PicowattsTolerance { get { return 1e-9m; } } - protected virtual decimal TerawattsTolerance { get { return 1e-9m; } } - protected virtual decimal WattsTolerance { get { return 1e-9m; } } + protected virtual double BoilerHorsepowerTolerance { get { return 1e-5; } } + protected virtual double BritishThermalUnitsPerHourTolerance { get { return 1e-5; } } + protected virtual double DecawattsTolerance { get { return 1e-5; } } + protected virtual double DeciwattsTolerance { get { return 1e-5; } } + protected virtual double ElectricalHorsepowerTolerance { get { return 1e-5; } } + protected virtual double FemtowattsTolerance { get { return 1e-5; } } + protected virtual double GigajoulesPerHourTolerance { get { return 1e-5; } } + protected virtual double GigawattsTolerance { get { return 1e-5; } } + protected virtual double HydraulicHorsepowerTolerance { get { return 1e-5; } } + protected virtual double JoulesPerHourTolerance { get { return 1e-5; } } + protected virtual double KilobritishThermalUnitsPerHourTolerance { get { return 1e-5; } } + protected virtual double KilojoulesPerHourTolerance { get { return 1e-5; } } + protected virtual double KilowattsTolerance { get { return 1e-5; } } + protected virtual double MechanicalHorsepowerTolerance { get { return 1e-5; } } + protected virtual double MegabritishThermalUnitsPerHourTolerance { get { return 1e-5; } } + protected virtual double MegajoulesPerHourTolerance { get { return 1e-5; } } + protected virtual double MegawattsTolerance { get { return 1e-5; } } + protected virtual double MetricHorsepowerTolerance { get { return 1e-5; } } + protected virtual double MicrowattsTolerance { get { return 1e-5; } } + protected virtual double MillijoulesPerHourTolerance { get { return 1e-5; } } + protected virtual double MilliwattsTolerance { get { return 1e-5; } } + protected virtual double NanowattsTolerance { get { return 1e-5; } } + protected virtual double PetawattsTolerance { get { return 1e-5; } } + protected virtual double PicowattsTolerance { get { return 1e-5; } } + protected virtual double TerawattsTolerance { get { return 1e-5; } } + protected virtual double WattsTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global - protected (decimal UnitsInBaseUnit, decimal Tolerence) GetConversionFactor(PowerUnit unit) + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(PowerUnit unit) { return unit switch { @@ -163,10 +163,22 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() { var quantity = new Power(); Assert.Equal(0, quantity.Value); - Assert.Equal(0m, ((IDecimalQuantity)quantity).Value); Assert.Equal(PowerUnit.Watt, quantity.Unit); } + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new Power(double.PositiveInfinity, PowerUnit.Watt)); + Assert.Throws(() => new Power(double.NegativeInfinity, PowerUnit.Watt)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new Power(double.NaN, PowerUnit.Watt)); + } + [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { @@ -343,6 +355,19 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() } + [Fact] + public void FromWatts_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => Power.FromWatts(double.PositiveInfinity)); + Assert.Throws(() => Power.FromWatts(double.NegativeInfinity)); + } + + [Fact] + public void FromWatts_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => Power.FromWatts(double.NaN)); + } + [Fact] public void As() { @@ -1174,7 +1199,7 @@ public void CompareToThrowsOnNull() [InlineData(1, PowerUnit.Watt, 2, PowerUnit.Watt, false)] // Different value. [InlineData(2, PowerUnit.Watt, 1, PowerUnit.BoilerHorsepower, false)] // Different value and unit. [InlineData(1, PowerUnit.Watt, 1, PowerUnit.BoilerHorsepower, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(decimal valueA, PowerUnit unitA, decimal valueB, PowerUnit unitB, bool expectEqual) + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PowerUnit unitA, double valueB, PowerUnit unitB, bool expectEqual) { var a = new Power(valueA, unitA); var b = new Power(valueB, unitB); @@ -1335,10 +1360,10 @@ public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCul try { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 W", new Power(0.123456m, PowerUnit.Watt).ToString("s1")); - Assert.Equal("0.12 W", new Power(0.123456m, PowerUnit.Watt).ToString("s2")); - Assert.Equal("0.123 W", new Power(0.123456m, PowerUnit.Watt).ToString("s3")); - Assert.Equal("0.1235 W", new Power(0.123456m, PowerUnit.Watt).ToString("s4")); + Assert.Equal("0.1 W", new Power(0.123456, PowerUnit.Watt).ToString("s1")); + Assert.Equal("0.12 W", new Power(0.123456, PowerUnit.Watt).ToString("s2")); + Assert.Equal("0.123 W", new Power(0.123456, PowerUnit.Watt).ToString("s3")); + Assert.Equal("0.1235 W", new Power(0.123456, PowerUnit.Watt).ToString("s4")); } finally { @@ -1350,10 +1375,10 @@ public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCul public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() { var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 W", new Power(0.123456m, PowerUnit.Watt).ToString("s1", culture)); - Assert.Equal("0.12 W", new Power(0.123456m, PowerUnit.Watt).ToString("s2", culture)); - Assert.Equal("0.123 W", new Power(0.123456m, PowerUnit.Watt).ToString("s3", culture)); - Assert.Equal("0.1235 W", new Power(0.123456m, PowerUnit.Watt).ToString("s4", culture)); + Assert.Equal("0.1 W", new Power(0.123456, PowerUnit.Watt).ToString("s1", culture)); + Assert.Equal("0.12 W", new Power(0.123456, PowerUnit.Watt).ToString("s2", culture)); + Assert.Equal("0.123 W", new Power(0.123456, PowerUnit.Watt).ToString("s3", culture)); + Assert.Equal("0.1235 W", new Power(0.123456, PowerUnit.Watt).ToString("s4", culture)); } [Theory] diff --git a/UnitsNet.Tests/IntOverloadTests.cs b/UnitsNet.Tests/IntOverloadTests.cs index 9d059dcc46..bf63007ba7 100644 --- a/UnitsNet.Tests/IntOverloadTests.cs +++ b/UnitsNet.Tests/IntOverloadTests.cs @@ -18,7 +18,7 @@ public static void CreatingQuantityWithDoubleBackingFieldFromIntReturnsCorrectVa public static void CreatingQuantityWithIntBackingFieldFromIntReturnsCorrectValue() { Power power = Power.FromWatts(1); - Assert.Equal(1.0m, power.Watts); + Assert.Equal(1.0, power.Watts); } } } diff --git a/UnitsNet.Tests/LongOverloadTests.cs b/UnitsNet.Tests/LongOverloadTests.cs index ba5c00a538..fd54377f08 100644 --- a/UnitsNet.Tests/LongOverloadTests.cs +++ b/UnitsNet.Tests/LongOverloadTests.cs @@ -18,7 +18,7 @@ public static void CreatingQuantityWithDoubleBackingFieldFromLongReturnsCorrectV public static void CreatingQuantityWithLongBackingFieldFromLongReturnsCorrectValue() { Power power = Power.FromWatts(1L); - Assert.Equal(1.0m, power.Watts); + Assert.Equal(1.0, power.Watts); } } } diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index 0231219be2..68f6a32f3f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -36,13 +36,13 @@ namespace UnitsNet /// In physics, power is the rate of doing work. It is equivalent to an amount of energy consumed per unit time. /// [DataContract] - public readonly partial struct Power : IArithmeticQuantity, IDecimalQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Power : IArithmeticQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. /// [DataMember(Name = "Value", Order = 0)] - private readonly decimal _value; + private readonly double _value; /// /// The unit this quantity was constructed with. @@ -98,9 +98,9 @@ static Power() /// The numeric value to construct this quantity with. /// The unit representation to construct this quantity with. /// If value is NaN or Infinity. - public Power(decimal value, PowerUnit unit) + public Power(double value, PowerUnit unit) { - _value = value; + _value = Guard.EnsureValidNumber(value, nameof(value)); _unit = unit; } @@ -112,14 +112,14 @@ public Power(decimal value, PowerUnit unit) /// The unit system to create the quantity with. /// The given is null. /// No unit was found for the given . - public Power(decimal value, UnitSystem unitSystem) + public Power(double value, UnitSystem unitSystem) { if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; + _value = Guard.EnsureValidNumber(value, nameof(value)); _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); } @@ -163,14 +163,11 @@ public Power(decimal value, UnitSystem unitSystem) /// /// The numeric value this quantity was constructed with. /// - public decimal Value => _value; + public double Value => _value; /// QuantityValue IQuantity.Value => _value; - /// - decimal IDecimalQuantity.Value => _value; - Enum IQuantity.Unit => Unit; /// @@ -192,134 +189,134 @@ public Power(decimal value, UnitSystem unitSystem) #region Conversion Properties /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal BoilerHorsepower => As(PowerUnit.BoilerHorsepower); + public double BoilerHorsepower => As(PowerUnit.BoilerHorsepower); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal BritishThermalUnitsPerHour => As(PowerUnit.BritishThermalUnitPerHour); + public double BritishThermalUnitsPerHour => As(PowerUnit.BritishThermalUnitPerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Decawatts => As(PowerUnit.Decawatt); + public double Decawatts => As(PowerUnit.Decawatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Deciwatts => As(PowerUnit.Deciwatt); + public double Deciwatts => As(PowerUnit.Deciwatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal ElectricalHorsepower => As(PowerUnit.ElectricalHorsepower); + public double ElectricalHorsepower => As(PowerUnit.ElectricalHorsepower); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Femtowatts => As(PowerUnit.Femtowatt); + public double Femtowatts => As(PowerUnit.Femtowatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal GigajoulesPerHour => As(PowerUnit.GigajoulePerHour); + public double GigajoulesPerHour => As(PowerUnit.GigajoulePerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Gigawatts => As(PowerUnit.Gigawatt); + public double Gigawatts => As(PowerUnit.Gigawatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal HydraulicHorsepower => As(PowerUnit.HydraulicHorsepower); + public double HydraulicHorsepower => As(PowerUnit.HydraulicHorsepower); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal JoulesPerHour => As(PowerUnit.JoulePerHour); + public double JoulesPerHour => As(PowerUnit.JoulePerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal KilobritishThermalUnitsPerHour => As(PowerUnit.KilobritishThermalUnitPerHour); + public double KilobritishThermalUnitsPerHour => As(PowerUnit.KilobritishThermalUnitPerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal KilojoulesPerHour => As(PowerUnit.KilojoulePerHour); + public double KilojoulesPerHour => As(PowerUnit.KilojoulePerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Kilowatts => As(PowerUnit.Kilowatt); + public double Kilowatts => As(PowerUnit.Kilowatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal MechanicalHorsepower => As(PowerUnit.MechanicalHorsepower); + public double MechanicalHorsepower => As(PowerUnit.MechanicalHorsepower); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal MegabritishThermalUnitsPerHour => As(PowerUnit.MegabritishThermalUnitPerHour); + public double MegabritishThermalUnitsPerHour => As(PowerUnit.MegabritishThermalUnitPerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal MegajoulesPerHour => As(PowerUnit.MegajoulePerHour); + public double MegajoulesPerHour => As(PowerUnit.MegajoulePerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Megawatts => As(PowerUnit.Megawatt); + public double Megawatts => As(PowerUnit.Megawatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal MetricHorsepower => As(PowerUnit.MetricHorsepower); + public double MetricHorsepower => As(PowerUnit.MetricHorsepower); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Microwatts => As(PowerUnit.Microwatt); + public double Microwatts => As(PowerUnit.Microwatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal MillijoulesPerHour => As(PowerUnit.MillijoulePerHour); + public double MillijoulesPerHour => As(PowerUnit.MillijoulePerHour); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Milliwatts => As(PowerUnit.Milliwatt); + public double Milliwatts => As(PowerUnit.Milliwatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Nanowatts => As(PowerUnit.Nanowatt); + public double Nanowatts => As(PowerUnit.Nanowatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Petawatts => As(PowerUnit.Petawatt); + public double Petawatts => As(PowerUnit.Petawatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Picowatts => As(PowerUnit.Picowatt); + public double Picowatts => As(PowerUnit.Picowatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Terawatts => As(PowerUnit.Terawatt); + public double Terawatts => As(PowerUnit.Terawatt); /// - /// Gets a value of this quantity converted into + /// Gets a value of this quantity converted into /// - public decimal Watts => As(PowerUnit.Watt); + public double Watts => As(PowerUnit.Watt); #endregion @@ -450,7 +447,7 @@ public static string GetAbbreviation(PowerUnit unit, IFormatProvider? provider) /// If value is NaN or Infinity. public static Power FromBoilerHorsepower(QuantityValue boilerhorsepower) { - decimal value = (decimal) boilerhorsepower; + double value = (double) boilerhorsepower; return new Power(value, PowerUnit.BoilerHorsepower); } @@ -460,7 +457,7 @@ public static Power FromBoilerHorsepower(QuantityValue boilerhorsepower) /// If value is NaN or Infinity. public static Power FromBritishThermalUnitsPerHour(QuantityValue britishthermalunitsperhour) { - decimal value = (decimal) britishthermalunitsperhour; + double value = (double) britishthermalunitsperhour; return new Power(value, PowerUnit.BritishThermalUnitPerHour); } @@ -470,7 +467,7 @@ public static Power FromBritishThermalUnitsPerHour(QuantityValue britishthermalu /// If value is NaN or Infinity. public static Power FromDecawatts(QuantityValue decawatts) { - decimal value = (decimal) decawatts; + double value = (double) decawatts; return new Power(value, PowerUnit.Decawatt); } @@ -480,7 +477,7 @@ public static Power FromDecawatts(QuantityValue decawatts) /// If value is NaN or Infinity. public static Power FromDeciwatts(QuantityValue deciwatts) { - decimal value = (decimal) deciwatts; + double value = (double) deciwatts; return new Power(value, PowerUnit.Deciwatt); } @@ -490,7 +487,7 @@ public static Power FromDeciwatts(QuantityValue deciwatts) /// If value is NaN or Infinity. public static Power FromElectricalHorsepower(QuantityValue electricalhorsepower) { - decimal value = (decimal) electricalhorsepower; + double value = (double) electricalhorsepower; return new Power(value, PowerUnit.ElectricalHorsepower); } @@ -500,7 +497,7 @@ public static Power FromElectricalHorsepower(QuantityValue electricalhorsepower) /// If value is NaN or Infinity. public static Power FromFemtowatts(QuantityValue femtowatts) { - decimal value = (decimal) femtowatts; + double value = (double) femtowatts; return new Power(value, PowerUnit.Femtowatt); } @@ -510,7 +507,7 @@ public static Power FromFemtowatts(QuantityValue femtowatts) /// If value is NaN or Infinity. public static Power FromGigajoulesPerHour(QuantityValue gigajoulesperhour) { - decimal value = (decimal) gigajoulesperhour; + double value = (double) gigajoulesperhour; return new Power(value, PowerUnit.GigajoulePerHour); } @@ -520,7 +517,7 @@ public static Power FromGigajoulesPerHour(QuantityValue gigajoulesperhour) /// If value is NaN or Infinity. public static Power FromGigawatts(QuantityValue gigawatts) { - decimal value = (decimal) gigawatts; + double value = (double) gigawatts; return new Power(value, PowerUnit.Gigawatt); } @@ -530,7 +527,7 @@ public static Power FromGigawatts(QuantityValue gigawatts) /// If value is NaN or Infinity. public static Power FromHydraulicHorsepower(QuantityValue hydraulichorsepower) { - decimal value = (decimal) hydraulichorsepower; + double value = (double) hydraulichorsepower; return new Power(value, PowerUnit.HydraulicHorsepower); } @@ -540,7 +537,7 @@ public static Power FromHydraulicHorsepower(QuantityValue hydraulichorsepower) /// If value is NaN or Infinity. public static Power FromJoulesPerHour(QuantityValue joulesperhour) { - decimal value = (decimal) joulesperhour; + double value = (double) joulesperhour; return new Power(value, PowerUnit.JoulePerHour); } @@ -550,7 +547,7 @@ public static Power FromJoulesPerHour(QuantityValue joulesperhour) /// If value is NaN or Infinity. public static Power FromKilobritishThermalUnitsPerHour(QuantityValue kilobritishthermalunitsperhour) { - decimal value = (decimal) kilobritishthermalunitsperhour; + double value = (double) kilobritishthermalunitsperhour; return new Power(value, PowerUnit.KilobritishThermalUnitPerHour); } @@ -560,7 +557,7 @@ public static Power FromKilobritishThermalUnitsPerHour(QuantityValue kilobritish /// If value is NaN or Infinity. public static Power FromKilojoulesPerHour(QuantityValue kilojoulesperhour) { - decimal value = (decimal) kilojoulesperhour; + double value = (double) kilojoulesperhour; return new Power(value, PowerUnit.KilojoulePerHour); } @@ -570,7 +567,7 @@ public static Power FromKilojoulesPerHour(QuantityValue kilojoulesperhour) /// If value is NaN or Infinity. public static Power FromKilowatts(QuantityValue kilowatts) { - decimal value = (decimal) kilowatts; + double value = (double) kilowatts; return new Power(value, PowerUnit.Kilowatt); } @@ -580,7 +577,7 @@ public static Power FromKilowatts(QuantityValue kilowatts) /// If value is NaN or Infinity. public static Power FromMechanicalHorsepower(QuantityValue mechanicalhorsepower) { - decimal value = (decimal) mechanicalhorsepower; + double value = (double) mechanicalhorsepower; return new Power(value, PowerUnit.MechanicalHorsepower); } @@ -590,7 +587,7 @@ public static Power FromMechanicalHorsepower(QuantityValue mechanicalhorsepower) /// If value is NaN or Infinity. public static Power FromMegabritishThermalUnitsPerHour(QuantityValue megabritishthermalunitsperhour) { - decimal value = (decimal) megabritishthermalunitsperhour; + double value = (double) megabritishthermalunitsperhour; return new Power(value, PowerUnit.MegabritishThermalUnitPerHour); } @@ -600,7 +597,7 @@ public static Power FromMegabritishThermalUnitsPerHour(QuantityValue megabritish /// If value is NaN or Infinity. public static Power FromMegajoulesPerHour(QuantityValue megajoulesperhour) { - decimal value = (decimal) megajoulesperhour; + double value = (double) megajoulesperhour; return new Power(value, PowerUnit.MegajoulePerHour); } @@ -610,7 +607,7 @@ public static Power FromMegajoulesPerHour(QuantityValue megajoulesperhour) /// If value is NaN or Infinity. public static Power FromMegawatts(QuantityValue megawatts) { - decimal value = (decimal) megawatts; + double value = (double) megawatts; return new Power(value, PowerUnit.Megawatt); } @@ -620,7 +617,7 @@ public static Power FromMegawatts(QuantityValue megawatts) /// If value is NaN or Infinity. public static Power FromMetricHorsepower(QuantityValue metrichorsepower) { - decimal value = (decimal) metrichorsepower; + double value = (double) metrichorsepower; return new Power(value, PowerUnit.MetricHorsepower); } @@ -630,7 +627,7 @@ public static Power FromMetricHorsepower(QuantityValue metrichorsepower) /// If value is NaN or Infinity. public static Power FromMicrowatts(QuantityValue microwatts) { - decimal value = (decimal) microwatts; + double value = (double) microwatts; return new Power(value, PowerUnit.Microwatt); } @@ -640,7 +637,7 @@ public static Power FromMicrowatts(QuantityValue microwatts) /// If value is NaN or Infinity. public static Power FromMillijoulesPerHour(QuantityValue millijoulesperhour) { - decimal value = (decimal) millijoulesperhour; + double value = (double) millijoulesperhour; return new Power(value, PowerUnit.MillijoulePerHour); } @@ -650,7 +647,7 @@ public static Power FromMillijoulesPerHour(QuantityValue millijoulesperhour) /// If value is NaN or Infinity. public static Power FromMilliwatts(QuantityValue milliwatts) { - decimal value = (decimal) milliwatts; + double value = (double) milliwatts; return new Power(value, PowerUnit.Milliwatt); } @@ -660,7 +657,7 @@ public static Power FromMilliwatts(QuantityValue milliwatts) /// If value is NaN or Infinity. public static Power FromNanowatts(QuantityValue nanowatts) { - decimal value = (decimal) nanowatts; + double value = (double) nanowatts; return new Power(value, PowerUnit.Nanowatt); } @@ -670,7 +667,7 @@ public static Power FromNanowatts(QuantityValue nanowatts) /// If value is NaN or Infinity. public static Power FromPetawatts(QuantityValue petawatts) { - decimal value = (decimal) petawatts; + double value = (double) petawatts; return new Power(value, PowerUnit.Petawatt); } @@ -680,7 +677,7 @@ public static Power FromPetawatts(QuantityValue petawatts) /// If value is NaN or Infinity. public static Power FromPicowatts(QuantityValue picowatts) { - decimal value = (decimal) picowatts; + double value = (double) picowatts; return new Power(value, PowerUnit.Picowatt); } @@ -690,7 +687,7 @@ public static Power FromPicowatts(QuantityValue picowatts) /// If value is NaN or Infinity. public static Power FromTerawatts(QuantityValue terawatts) { - decimal value = (decimal) terawatts; + double value = (double) terawatts; return new Power(value, PowerUnit.Terawatt); } @@ -700,7 +697,7 @@ public static Power FromTerawatts(QuantityValue terawatts) /// If value is NaN or Infinity. public static Power FromWatts(QuantityValue watts) { - decimal value = (decimal) watts; + double value = (double) watts; return new Power(value, PowerUnit.Watt); } @@ -712,7 +709,7 @@ public static Power FromWatts(QuantityValue watts) /// Power unit value. public static Power From(QuantityValue value, PowerUnit fromUnit) { - return new Power((decimal)value, fromUnit); + return new Power((double)value, fromUnit); } #endregion @@ -882,25 +879,25 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power } /// Get from multiplying value and . - public static Power operator *(decimal left, Power right) + public static Power operator *(double left, Power right) { return new Power(left * right.Value, right.Unit); } /// Get from multiplying value and . - public static Power operator *(Power left, decimal right) + public static Power operator *(Power left, double right) { return new Power(left.Value * right, left.Unit); } /// Get from dividing by value. - public static Power operator /(Power left, decimal right) + public static Power operator /(Power left, double right) { return new Power(left.Value / right, left.Unit); } /// Get ratio value from dividing by . - public static decimal operator /(Power left, Power right) + public static double operator /(Power left, Power right) { return left.Watts / right.Watts; } @@ -938,16 +935,16 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] public static bool operator ==(Power left, Power right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] public static bool operator !=(Power left, Power right) { return !(left == right); @@ -955,8 +952,8 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] public override bool Equals(object? obj) { if (obj is null || !(obj is Power otherQuantity)) @@ -967,8 +964,8 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + /// Consider using to check equality across different units and to specify a floating-point number error tolerance. + [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] public bool Equals(Power other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1045,20 +1042,20 @@ public int CompareTo(Power other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating-point operations and using decimal internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. - public bool Equals(Power other, decimal tolerance, ComparisonType comparisonType) + public bool Equals(Power other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); - decimal thisValue = this.Value; - decimal otherValueInThisUnits = other.As(this.Unit); + double thisValue = this.Value; + double otherValueInThisUnits = other.As(this.Unit); return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); } @@ -1080,7 +1077,7 @@ public override int GetHashCode() /// Convert to the unit representation . /// /// Value converted to the specified unit. - public decimal As(PowerUnit unit) + public double As(PowerUnit unit) { if (Unit == unit) return Value; @@ -1088,13 +1085,8 @@ public decimal As(PowerUnit unit) return ToUnit(unit).Value; } - double IQuantity.As(PowerUnit unit) - { - return (double)As(unit); - } - /// - public decimal As(UnitSystem unitSystem) + public double As(UnitSystem unitSystem) { if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); @@ -1108,12 +1100,6 @@ public decimal As(UnitSystem unitSystem) return As(firstUnitInfo.Value); } - /// - double IQuantity.As(UnitSystem unitSystem) - { - return (double)As(unitSystem); - } - /// double IQuantity.As(Enum unit) { @@ -1181,58 +1167,58 @@ private bool TryToUnit(PowerUnit unit, [NotNullWhen(true)] out Power? converted) Power? convertedOrNull = (Unit, unit) switch { // PowerUnit -> BaseUnit - (PowerUnit.BoilerHorsepower, PowerUnit.Watt) => new Power(_value * 9812.5m, PowerUnit.Watt), - (PowerUnit.BritishThermalUnitPerHour, PowerUnit.Watt) => new Power(_value * 0.29307107017m, PowerUnit.Watt), - (PowerUnit.Decawatt, PowerUnit.Watt) => new Power((_value) * 1e1m, PowerUnit.Watt), - (PowerUnit.Deciwatt, PowerUnit.Watt) => new Power((_value) * 1e-1m, PowerUnit.Watt), - (PowerUnit.ElectricalHorsepower, PowerUnit.Watt) => new Power(_value * 746m, PowerUnit.Watt), - (PowerUnit.Femtowatt, PowerUnit.Watt) => new Power((_value) * 1e-15m, PowerUnit.Watt), - (PowerUnit.GigajoulePerHour, PowerUnit.Watt) => new Power((_value / 3600m) * 1e9m, PowerUnit.Watt), - (PowerUnit.Gigawatt, PowerUnit.Watt) => new Power((_value) * 1e9m, PowerUnit.Watt), - (PowerUnit.HydraulicHorsepower, PowerUnit.Watt) => new Power(_value * 745.69988145m, PowerUnit.Watt), - (PowerUnit.JoulePerHour, PowerUnit.Watt) => new Power(_value / 3600m, PowerUnit.Watt), - (PowerUnit.KilobritishThermalUnitPerHour, PowerUnit.Watt) => new Power((_value * 0.29307107017m) * 1e3m, PowerUnit.Watt), - (PowerUnit.KilojoulePerHour, PowerUnit.Watt) => new Power((_value / 3600m) * 1e3m, PowerUnit.Watt), - (PowerUnit.Kilowatt, PowerUnit.Watt) => new Power((_value) * 1e3m, PowerUnit.Watt), - (PowerUnit.MechanicalHorsepower, PowerUnit.Watt) => new Power(_value * 745.69m, PowerUnit.Watt), - (PowerUnit.MegabritishThermalUnitPerHour, PowerUnit.Watt) => new Power((_value * 0.29307107017m) * 1e6m, PowerUnit.Watt), - (PowerUnit.MegajoulePerHour, PowerUnit.Watt) => new Power((_value / 3600m) * 1e6m, PowerUnit.Watt), - (PowerUnit.Megawatt, PowerUnit.Watt) => new Power((_value) * 1e6m, PowerUnit.Watt), - (PowerUnit.MetricHorsepower, PowerUnit.Watt) => new Power(_value * 735.49875m, PowerUnit.Watt), - (PowerUnit.Microwatt, PowerUnit.Watt) => new Power((_value) * 1e-6m, PowerUnit.Watt), - (PowerUnit.MillijoulePerHour, PowerUnit.Watt) => new Power((_value / 3600m) * 1e-3m, PowerUnit.Watt), - (PowerUnit.Milliwatt, PowerUnit.Watt) => new Power((_value) * 1e-3m, PowerUnit.Watt), - (PowerUnit.Nanowatt, PowerUnit.Watt) => new Power((_value) * 1e-9m, PowerUnit.Watt), - (PowerUnit.Petawatt, PowerUnit.Watt) => new Power((_value) * 1e15m, PowerUnit.Watt), - (PowerUnit.Picowatt, PowerUnit.Watt) => new Power((_value) * 1e-12m, PowerUnit.Watt), - (PowerUnit.Terawatt, PowerUnit.Watt) => new Power((_value) * 1e12m, PowerUnit.Watt), + (PowerUnit.BoilerHorsepower, PowerUnit.Watt) => new Power(_value * 9812.5, PowerUnit.Watt), + (PowerUnit.BritishThermalUnitPerHour, PowerUnit.Watt) => new Power(_value * 0.29307107017, PowerUnit.Watt), + (PowerUnit.Decawatt, PowerUnit.Watt) => new Power((_value) * 1e1d, PowerUnit.Watt), + (PowerUnit.Deciwatt, PowerUnit.Watt) => new Power((_value) * 1e-1d, PowerUnit.Watt), + (PowerUnit.ElectricalHorsepower, PowerUnit.Watt) => new Power(_value * 746, PowerUnit.Watt), + (PowerUnit.Femtowatt, PowerUnit.Watt) => new Power((_value) * 1e-15d, PowerUnit.Watt), + (PowerUnit.GigajoulePerHour, PowerUnit.Watt) => new Power((_value / 3600) * 1e9d, PowerUnit.Watt), + (PowerUnit.Gigawatt, PowerUnit.Watt) => new Power((_value) * 1e9d, PowerUnit.Watt), + (PowerUnit.HydraulicHorsepower, PowerUnit.Watt) => new Power(_value * 745.69988145, PowerUnit.Watt), + (PowerUnit.JoulePerHour, PowerUnit.Watt) => new Power(_value / 3600, PowerUnit.Watt), + (PowerUnit.KilobritishThermalUnitPerHour, PowerUnit.Watt) => new Power((_value * 0.29307107017) * 1e3d, PowerUnit.Watt), + (PowerUnit.KilojoulePerHour, PowerUnit.Watt) => new Power((_value / 3600) * 1e3d, PowerUnit.Watt), + (PowerUnit.Kilowatt, PowerUnit.Watt) => new Power((_value) * 1e3d, PowerUnit.Watt), + (PowerUnit.MechanicalHorsepower, PowerUnit.Watt) => new Power(_value * 745.69, PowerUnit.Watt), + (PowerUnit.MegabritishThermalUnitPerHour, PowerUnit.Watt) => new Power((_value * 0.29307107017) * 1e6d, PowerUnit.Watt), + (PowerUnit.MegajoulePerHour, PowerUnit.Watt) => new Power((_value / 3600) * 1e6d, PowerUnit.Watt), + (PowerUnit.Megawatt, PowerUnit.Watt) => new Power((_value) * 1e6d, PowerUnit.Watt), + (PowerUnit.MetricHorsepower, PowerUnit.Watt) => new Power(_value * 735.49875, PowerUnit.Watt), + (PowerUnit.Microwatt, PowerUnit.Watt) => new Power((_value) * 1e-6d, PowerUnit.Watt), + (PowerUnit.MillijoulePerHour, PowerUnit.Watt) => new Power((_value / 3600) * 1e-3d, PowerUnit.Watt), + (PowerUnit.Milliwatt, PowerUnit.Watt) => new Power((_value) * 1e-3d, PowerUnit.Watt), + (PowerUnit.Nanowatt, PowerUnit.Watt) => new Power((_value) * 1e-9d, PowerUnit.Watt), + (PowerUnit.Petawatt, PowerUnit.Watt) => new Power((_value) * 1e15d, PowerUnit.Watt), + (PowerUnit.Picowatt, PowerUnit.Watt) => new Power((_value) * 1e-12d, PowerUnit.Watt), + (PowerUnit.Terawatt, PowerUnit.Watt) => new Power((_value) * 1e12d, PowerUnit.Watt), // BaseUnit -> PowerUnit - (PowerUnit.Watt, PowerUnit.BoilerHorsepower) => new Power(_value / 9812.5m, PowerUnit.BoilerHorsepower), - (PowerUnit.Watt, PowerUnit.BritishThermalUnitPerHour) => new Power(_value / 0.29307107017m, PowerUnit.BritishThermalUnitPerHour), - (PowerUnit.Watt, PowerUnit.Decawatt) => new Power((_value) / 1e1m, PowerUnit.Decawatt), - (PowerUnit.Watt, PowerUnit.Deciwatt) => new Power((_value) / 1e-1m, PowerUnit.Deciwatt), - (PowerUnit.Watt, PowerUnit.ElectricalHorsepower) => new Power(_value / 746m, PowerUnit.ElectricalHorsepower), - (PowerUnit.Watt, PowerUnit.Femtowatt) => new Power((_value) / 1e-15m, PowerUnit.Femtowatt), - (PowerUnit.Watt, PowerUnit.GigajoulePerHour) => new Power((_value * 3600m) / 1e9m, PowerUnit.GigajoulePerHour), - (PowerUnit.Watt, PowerUnit.Gigawatt) => new Power((_value) / 1e9m, PowerUnit.Gigawatt), - (PowerUnit.Watt, PowerUnit.HydraulicHorsepower) => new Power(_value / 745.69988145m, PowerUnit.HydraulicHorsepower), - (PowerUnit.Watt, PowerUnit.JoulePerHour) => new Power(_value * 3600m, PowerUnit.JoulePerHour), - (PowerUnit.Watt, PowerUnit.KilobritishThermalUnitPerHour) => new Power((_value / 0.29307107017m) / 1e3m, PowerUnit.KilobritishThermalUnitPerHour), - (PowerUnit.Watt, PowerUnit.KilojoulePerHour) => new Power((_value * 3600m) / 1e3m, PowerUnit.KilojoulePerHour), - (PowerUnit.Watt, PowerUnit.Kilowatt) => new Power((_value) / 1e3m, PowerUnit.Kilowatt), - (PowerUnit.Watt, PowerUnit.MechanicalHorsepower) => new Power(_value / 745.69m, PowerUnit.MechanicalHorsepower), - (PowerUnit.Watt, PowerUnit.MegabritishThermalUnitPerHour) => new Power((_value / 0.29307107017m) / 1e6m, PowerUnit.MegabritishThermalUnitPerHour), - (PowerUnit.Watt, PowerUnit.MegajoulePerHour) => new Power((_value * 3600m) / 1e6m, PowerUnit.MegajoulePerHour), - (PowerUnit.Watt, PowerUnit.Megawatt) => new Power((_value) / 1e6m, PowerUnit.Megawatt), - (PowerUnit.Watt, PowerUnit.MetricHorsepower) => new Power(_value / 735.49875m, PowerUnit.MetricHorsepower), - (PowerUnit.Watt, PowerUnit.Microwatt) => new Power((_value) / 1e-6m, PowerUnit.Microwatt), - (PowerUnit.Watt, PowerUnit.MillijoulePerHour) => new Power((_value * 3600m) / 1e-3m, PowerUnit.MillijoulePerHour), - (PowerUnit.Watt, PowerUnit.Milliwatt) => new Power((_value) / 1e-3m, PowerUnit.Milliwatt), - (PowerUnit.Watt, PowerUnit.Nanowatt) => new Power((_value) / 1e-9m, PowerUnit.Nanowatt), - (PowerUnit.Watt, PowerUnit.Petawatt) => new Power((_value) / 1e15m, PowerUnit.Petawatt), - (PowerUnit.Watt, PowerUnit.Picowatt) => new Power((_value) / 1e-12m, PowerUnit.Picowatt), - (PowerUnit.Watt, PowerUnit.Terawatt) => new Power((_value) / 1e12m, PowerUnit.Terawatt), + (PowerUnit.Watt, PowerUnit.BoilerHorsepower) => new Power(_value / 9812.5, PowerUnit.BoilerHorsepower), + (PowerUnit.Watt, PowerUnit.BritishThermalUnitPerHour) => new Power(_value / 0.29307107017, PowerUnit.BritishThermalUnitPerHour), + (PowerUnit.Watt, PowerUnit.Decawatt) => new Power((_value) / 1e1d, PowerUnit.Decawatt), + (PowerUnit.Watt, PowerUnit.Deciwatt) => new Power((_value) / 1e-1d, PowerUnit.Deciwatt), + (PowerUnit.Watt, PowerUnit.ElectricalHorsepower) => new Power(_value / 746, PowerUnit.ElectricalHorsepower), + (PowerUnit.Watt, PowerUnit.Femtowatt) => new Power((_value) / 1e-15d, PowerUnit.Femtowatt), + (PowerUnit.Watt, PowerUnit.GigajoulePerHour) => new Power((_value * 3600) / 1e9d, PowerUnit.GigajoulePerHour), + (PowerUnit.Watt, PowerUnit.Gigawatt) => new Power((_value) / 1e9d, PowerUnit.Gigawatt), + (PowerUnit.Watt, PowerUnit.HydraulicHorsepower) => new Power(_value / 745.69988145, PowerUnit.HydraulicHorsepower), + (PowerUnit.Watt, PowerUnit.JoulePerHour) => new Power(_value * 3600, PowerUnit.JoulePerHour), + (PowerUnit.Watt, PowerUnit.KilobritishThermalUnitPerHour) => new Power((_value / 0.29307107017) / 1e3d, PowerUnit.KilobritishThermalUnitPerHour), + (PowerUnit.Watt, PowerUnit.KilojoulePerHour) => new Power((_value * 3600) / 1e3d, PowerUnit.KilojoulePerHour), + (PowerUnit.Watt, PowerUnit.Kilowatt) => new Power((_value) / 1e3d, PowerUnit.Kilowatt), + (PowerUnit.Watt, PowerUnit.MechanicalHorsepower) => new Power(_value / 745.69, PowerUnit.MechanicalHorsepower), + (PowerUnit.Watt, PowerUnit.MegabritishThermalUnitPerHour) => new Power((_value / 0.29307107017) / 1e6d, PowerUnit.MegabritishThermalUnitPerHour), + (PowerUnit.Watt, PowerUnit.MegajoulePerHour) => new Power((_value * 3600) / 1e6d, PowerUnit.MegajoulePerHour), + (PowerUnit.Watt, PowerUnit.Megawatt) => new Power((_value) / 1e6d, PowerUnit.Megawatt), + (PowerUnit.Watt, PowerUnit.MetricHorsepower) => new Power(_value / 735.49875, PowerUnit.MetricHorsepower), + (PowerUnit.Watt, PowerUnit.Microwatt) => new Power((_value) / 1e-6d, PowerUnit.Microwatt), + (PowerUnit.Watt, PowerUnit.MillijoulePerHour) => new Power((_value * 3600) / 1e-3d, PowerUnit.MillijoulePerHour), + (PowerUnit.Watt, PowerUnit.Milliwatt) => new Power((_value) / 1e-3d, PowerUnit.Milliwatt), + (PowerUnit.Watt, PowerUnit.Nanowatt) => new Power((_value) / 1e-9d, PowerUnit.Nanowatt), + (PowerUnit.Watt, PowerUnit.Petawatt) => new Power((_value) / 1e15d, PowerUnit.Petawatt), + (PowerUnit.Watt, PowerUnit.Picowatt) => new Power((_value) / 1e-12d, PowerUnit.Picowatt), + (PowerUnit.Watt, PowerUnit.Terawatt) => new Power((_value) / 1e12d, PowerUnit.Terawatt), _ => null }; From 23d1dd592b7018574bf26a70892f2002f04d384a Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Fri, 10 Feb 2023 10:17:03 -0500 Subject: [PATCH 2/4] Test fixes --- .../UnitsNetBaseJsonConverterTest.cs | 6 +++--- .../UnitsNetIQuantityJsonConverterTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs index df692a3f12..8119df0815 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs @@ -33,10 +33,10 @@ public void UnitsNetBaseJsonConverter_ConvertIQuantity_works_with_double_type() [Fact] public void UnitsNetBaseJsonConverter_ConvertIQuantity_works_with_decimal_type() { - var result = _sut.Test_ConvertDecimalIQuantity(Power.FromWatts(10.2365m)); + var result = _sut.Test_ConvertDecimalIQuantity(Information.FromBits(64m)); - Assert.Equal("PowerUnit.Watt", result.Unit); - Assert.Equal(10.2365m, result.Value); + Assert.Equal("InformationUnit.Bit", result.Unit); + Assert.Equal(64m, result.Value); } [Fact] diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs index cf3fe62127..aa0106de94 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs @@ -78,10 +78,10 @@ public void UnitsNetIQuantityJsonConverter_WriteJson_works_with_decimal_quantity using (var stringWriter = new StringWriter(result)) using(var writer = new JsonTextWriter(stringWriter)) { - _sut.WriteJson(writer, Power.FromWatts(value), JsonSerializer.CreateDefault()); + _sut.WriteJson(writer, Information.FromBits(value), JsonSerializer.CreateDefault()); } - Assert.Equal($"{{\"Unit\":\"PowerUnit.Watt\",\"Value\":{expectedValue},\"ValueString\":\"{expectedValueString}\",\"ValueType\":\"decimal\"}}", + Assert.Equal($"{{\"Unit\":\"InformationUnit.Bit\",\"Value\":{expectedValue},\"ValueString\":\"{expectedValueString}\",\"ValueType\":\"decimal\"}}", result.ToString()); } From aee504bef7ac61969d6869cfc9efc793dcc34c89 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 18 Feb 2024 15:43:36 +0100 Subject: [PATCH 3/4] Remove tests combining UnitSystem and decimal No more decimal quantities support UnitSystem after removing Power. The remaining 2 decimal quantities Information and BitRate don't support UnitSystem, and we also plan to change them from decimal to double. --- UnitsNet.Tests/CustomCode/IQuantityTests.cs | 7 ------- UnitsNet.Tests/IValueQuantityTests.cs | 14 -------------- 2 files changed, 21 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/IQuantityTests.cs b/UnitsNet.Tests/CustomCode/IQuantityTests.cs index 710cb4df17..abae93ba96 100644 --- a/UnitsNet.Tests/CustomCode/IQuantityTests.cs +++ b/UnitsNet.Tests/CustomCode/IQuantityTests.cs @@ -93,12 +93,5 @@ public void IQuantityTUnitDecimal_AsEnum_ReturnsDecimal() IQuantity decimalQuantity = Information.FromKilobytes(1234.5); Assert.IsType(decimalQuantity.As(InformationUnit.Byte)); } - - [Fact] - public void IQuantityTUnitDecimal_AsUnitSystem_ReturnsDecimal() - { - IQuantity decimalQuantity = Power.FromMegawatts(1234.5); - Assert.IsType(decimalQuantity.As(UnitSystem.SI)); - } } } diff --git a/UnitsNet.Tests/IValueQuantityTests.cs b/UnitsNet.Tests/IValueQuantityTests.cs index a6379e33af..a0a8a1b318 100644 --- a/UnitsNet.Tests/IValueQuantityTests.cs +++ b/UnitsNet.Tests/IValueQuantityTests.cs @@ -44,13 +44,6 @@ public void IValueQuantityTDecimal_AsEnum_ReturnsDecimal() Assert.IsType(decimalQuantity.As(InformationUnit.Byte)); } - [Fact] - public void IValueQuantityTDecimal_AsUnitSystem_ReturnsDecimal() - { - IValueQuantity decimalQuantity = Power.FromMegawatts(1234.5); - Assert.IsType(decimalQuantity.As(UnitSystem.SI)); - } - [Fact] public void IValueQuantityTDouble_ToUnitEnum_ReturnsIValueQuantityTDouble() { @@ -71,12 +64,5 @@ public void IValueQuantityTDecimal_ToUnitEnum_ReturnsIValueQuantityTDecimal() IValueQuantity decimalQuantity = Information.FromKilobytes(1234.5); Assert.IsAssignableFrom>(decimalQuantity.ToUnit(InformationUnit.Bit)); } - - [Fact] - public void IValueQuantityTDecimal_ToUnitUnitSystem_ReturnsIValueQuantityTDecimal() - { - IValueQuantity decimalQuantity = Power.FromWatts(1234.5); - Assert.IsAssignableFrom>(decimalQuantity.ToUnit(UnitSystem.SI)); - } } } From 0254899a97839d0c336717308b6d6cc6a5ec2d6a Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 18 Feb 2024 15:49:13 +0100 Subject: [PATCH 4/4] Remove old redundant Int/Long/DecimalOverloadTests --- UnitsNet.Tests/DecimalOverloadTests.cs | 24 ------------------------ UnitsNet.Tests/IntOverloadTests.cs | 24 ------------------------ UnitsNet.Tests/LongOverloadTests.cs | 24 ------------------------ 3 files changed, 72 deletions(-) delete mode 100644 UnitsNet.Tests/DecimalOverloadTests.cs delete mode 100644 UnitsNet.Tests/IntOverloadTests.cs delete mode 100644 UnitsNet.Tests/LongOverloadTests.cs diff --git a/UnitsNet.Tests/DecimalOverloadTests.cs b/UnitsNet.Tests/DecimalOverloadTests.cs deleted file mode 100644 index 841c9b162b..0000000000 --- a/UnitsNet.Tests/DecimalOverloadTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 Xunit; - -namespace UnitsNet.Tests -{ - public class DecimalOverloadTests - { - [Fact] - public static void CreatingQuantityWithDoubleBackingFieldFromDecimalReturnsCorrectValue() - { - Acceleration acceleration = Acceleration.FromMetersPerSecondSquared(1m); - Assert.Equal(1.0, acceleration.MetersPerSecondSquared); - } - - [Fact] - public static void CreatingQuantityWithDecimalBackingFieldFromDecimalReturnsCorrectValue() - { - Power power = Power.FromWatts(1m); - Assert.Equal(1.0, power.Watts); - } - } -} diff --git a/UnitsNet.Tests/IntOverloadTests.cs b/UnitsNet.Tests/IntOverloadTests.cs deleted file mode 100644 index bf63007ba7..0000000000 --- a/UnitsNet.Tests/IntOverloadTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 Xunit; - -namespace UnitsNet.Tests -{ - public class IntOverloadTests - { - [Fact] - public static void CreatingQuantityWithDoubleBackingFieldFromIntReturnsCorrectValue() - { - Acceleration acceleration = Acceleration.FromMetersPerSecondSquared(1); - Assert.Equal(1.0, acceleration.MetersPerSecondSquared); - } - - [Fact] - public static void CreatingQuantityWithIntBackingFieldFromIntReturnsCorrectValue() - { - Power power = Power.FromWatts(1); - Assert.Equal(1.0, power.Watts); - } - } -} diff --git a/UnitsNet.Tests/LongOverloadTests.cs b/UnitsNet.Tests/LongOverloadTests.cs deleted file mode 100644 index fd54377f08..0000000000 --- a/UnitsNet.Tests/LongOverloadTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 Xunit; - -namespace UnitsNet.Tests -{ - public class LongOverloadTests - { - [Fact] - public static void CreatingQuantityWithDoubleBackingFieldFromLongReturnsCorrectValue() - { - Acceleration acceleration = Acceleration.FromMetersPerSecondSquared(1L); - Assert.Equal(1.0, acceleration.MetersPerSecondSquared); - } - - [Fact] - public static void CreatingQuantityWithLongBackingFieldFromLongReturnsCorrectValue() - { - Power power = Power.FromWatts(1L); - Assert.Equal(1.0, power.Watts); - } - } -}