From 4c53aa7eceb11ff1508992bc13c9cd424ef10c97 Mon Sep 17 00:00:00 2001 From: Javier Rennola Date: Tue, 3 Mar 2020 15:33:43 +0100 Subject: [PATCH 1/2] created electric potential change rate --- .../ElectricPotentialChangeRate.json | 89 ++ ...tricPotentialChangeRateExtensionsTest.g.cs | 108 ++ ...ElectricPotentialChangeRateExtensions.g.cs | 110 ++ .../ElectricPotentialChangeRateTests.cs | 47 + .../GeneratedCode/IQuantityTests.g.cs | 4 + .../ElectricPotentialChangeRateTestsBase.g.cs | 620 +++++++++ .../ElectricPotentialChangeRate.g.cs | 903 +++++++++++++ .../GeneratedCode/Quantity.g.cs | 6 + .../GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 20 + .../ElectricPotentialChangeRateUnit.g.cs | 52 + .../ElectricPotentialChangeRate.g.cs | 1173 +++++++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 7 + UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 20 + UnitsNet/GeneratedCode/UnitConverter.g.cs | 39 + .../ElectricPotentialChangeRateUnit.g.cs | 52 + 17 files changed, 3252 insertions(+) create mode 100644 Common/UnitDefinitions/ElectricPotentialChangeRate.json create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialChangeRateExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialChangeRateExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs diff --git a/Common/UnitDefinitions/ElectricPotentialChangeRate.json b/Common/UnitDefinitions/ElectricPotentialChangeRate.json new file mode 100644 index 0000000000..1245353d5d --- /dev/null +++ b/Common/UnitDefinitions/ElectricPotentialChangeRate.json @@ -0,0 +1,89 @@ +{ + "Name": "ElectricPotentialChangeRate", + "BaseUnit": "VoltPerSecond", + "XmlDoc": "ElectricPotential change rate is the ratio of the electric potential change to the time during which the change occurred (value of electric potential changes per unit time).", + "BaseDimensions": { + "L": 2, + "M": 1, + "T": -4, + "I": -1 + }, + "Units": [ + { + "SingularName": "VoltPerSecond", + "PluralName": "VoltsPerSeconds", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "V/s" ] + } + ] + }, + { + "SingularName": "VoltPerMicrosecond", + "PluralName": "VoltsPerMicroseconds", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Microsecond", + "I": "Ampere" + }, + "FromUnitToBaseFunc": "x*1E6", + "FromBaseToUnitFunc": "x/1E6", + "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "V/μs" ] + } + ] + }, + { + "SingularName": "VoltPerMinute", + "PluralName": "VoltsPerMinutes", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Minute", + "I": "Ampere" + }, + "FromUnitToBaseFunc": "x/60", + "FromBaseToUnitFunc": "x*60", + "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "V/min" ] + } + ] + }, + { + "SingularName": "VoltPerHour", + "PluralName": "VoltsPerHours", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Hour", + "I": "Ampere" + }, + "FromUnitToBaseFunc": "x/3600", + "FromBaseToUnitFunc": "x*3600", + "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "V/h" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialChangeRateExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialChangeRateExtensionsTest.g.cs new file mode 100644 index 0000000000..ce9ca9e848 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialChangeRateExtensionsTest.g.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricPotentialChangeRate; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricPotentialChangeRateExtensionsTests + { + [Fact] + public void NumberToKilovoltsPerHoursTest() => + Assert.Equal(ElectricPotentialChangeRate.FromKilovoltsPerHours(2), 2.KilovoltsPerHours()); + + [Fact] + public void NumberToKilovoltsPerMicrosecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromKilovoltsPerMicroseconds(2), 2.KilovoltsPerMicroseconds()); + + [Fact] + public void NumberToKilovoltsPerMinutesTest() => + Assert.Equal(ElectricPotentialChangeRate.FromKilovoltsPerMinutes(2), 2.KilovoltsPerMinutes()); + + [Fact] + public void NumberToKilovoltsPerSecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromKilovoltsPerSeconds(2), 2.KilovoltsPerSeconds()); + + [Fact] + public void NumberToMegavoltsPerHoursTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMegavoltsPerHours(2), 2.MegavoltsPerHours()); + + [Fact] + public void NumberToMegavoltsPerMicrosecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMegavoltsPerMicroseconds(2), 2.MegavoltsPerMicroseconds()); + + [Fact] + public void NumberToMegavoltsPerMinutesTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMegavoltsPerMinutes(2), 2.MegavoltsPerMinutes()); + + [Fact] + public void NumberToMegavoltsPerSecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMegavoltsPerSeconds(2), 2.MegavoltsPerSeconds()); + + [Fact] + public void NumberToMicrovoltsPerHoursTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMicrovoltsPerHours(2), 2.MicrovoltsPerHours()); + + [Fact] + public void NumberToMicrovoltsPerMicrosecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMicrovoltsPerMicroseconds(2), 2.MicrovoltsPerMicroseconds()); + + [Fact] + public void NumberToMicrovoltsPerMinutesTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMicrovoltsPerMinutes(2), 2.MicrovoltsPerMinutes()); + + [Fact] + public void NumberToMicrovoltsPerSecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMicrovoltsPerSeconds(2), 2.MicrovoltsPerSeconds()); + + [Fact] + public void NumberToMillivoltsPerHoursTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMillivoltsPerHours(2), 2.MillivoltsPerHours()); + + [Fact] + public void NumberToMillivoltsPerMicrosecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMillivoltsPerMicroseconds(2), 2.MillivoltsPerMicroseconds()); + + [Fact] + public void NumberToMillivoltsPerMinutesTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMillivoltsPerMinutes(2), 2.MillivoltsPerMinutes()); + + [Fact] + public void NumberToMillivoltsPerSecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromMillivoltsPerSeconds(2), 2.MillivoltsPerSeconds()); + + [Fact] + public void NumberToVoltsPerHoursTest() => + Assert.Equal(ElectricPotentialChangeRate.FromVoltsPerHours(2), 2.VoltsPerHours()); + + [Fact] + public void NumberToVoltsPerMicrosecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromVoltsPerMicroseconds(2), 2.VoltsPerMicroseconds()); + + [Fact] + public void NumberToVoltsPerMinutesTest() => + Assert.Equal(ElectricPotentialChangeRate.FromVoltsPerMinutes(2), 2.VoltsPerMinutes()); + + [Fact] + public void NumberToVoltsPerSecondsTest() => + Assert.Equal(ElectricPotentialChangeRate.FromVoltsPerSeconds(2), 2.VoltsPerSeconds()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialChangeRateExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialChangeRateExtensions.g.cs new file mode 100644 index 0000000000..d8465b9958 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialChangeRateExtensions.g.cs @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.NumberExtensions.NumberToElectricPotentialChangeRate +{ + /// + /// A number to ElectricPotentialChangeRate Extensions + /// + public static class NumberToElectricPotentialChangeRateExtensions + { + /// + public static ElectricPotentialChangeRate KilovoltsPerHours(this T value) => + ElectricPotentialChangeRate.FromKilovoltsPerHours(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate KilovoltsPerMicroseconds(this T value) => + ElectricPotentialChangeRate.FromKilovoltsPerMicroseconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate KilovoltsPerMinutes(this T value) => + ElectricPotentialChangeRate.FromKilovoltsPerMinutes(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate KilovoltsPerSeconds(this T value) => + ElectricPotentialChangeRate.FromKilovoltsPerSeconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MegavoltsPerHours(this T value) => + ElectricPotentialChangeRate.FromMegavoltsPerHours(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MegavoltsPerMicroseconds(this T value) => + ElectricPotentialChangeRate.FromMegavoltsPerMicroseconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MegavoltsPerMinutes(this T value) => + ElectricPotentialChangeRate.FromMegavoltsPerMinutes(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MegavoltsPerSeconds(this T value) => + ElectricPotentialChangeRate.FromMegavoltsPerSeconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MicrovoltsPerHours(this T value) => + ElectricPotentialChangeRate.FromMicrovoltsPerHours(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MicrovoltsPerMicroseconds(this T value) => + ElectricPotentialChangeRate.FromMicrovoltsPerMicroseconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MicrovoltsPerMinutes(this T value) => + ElectricPotentialChangeRate.FromMicrovoltsPerMinutes(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MicrovoltsPerSeconds(this T value) => + ElectricPotentialChangeRate.FromMicrovoltsPerSeconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MillivoltsPerHours(this T value) => + ElectricPotentialChangeRate.FromMillivoltsPerHours(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MillivoltsPerMicroseconds(this T value) => + ElectricPotentialChangeRate.FromMillivoltsPerMicroseconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MillivoltsPerMinutes(this T value) => + ElectricPotentialChangeRate.FromMillivoltsPerMinutes(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate MillivoltsPerSeconds(this T value) => + ElectricPotentialChangeRate.FromMillivoltsPerSeconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate VoltsPerHours(this T value) => + ElectricPotentialChangeRate.FromVoltsPerHours(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate VoltsPerMicroseconds(this T value) => + ElectricPotentialChangeRate.FromVoltsPerMicroseconds(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate VoltsPerMinutes(this T value) => + ElectricPotentialChangeRate.FromVoltsPerMinutes(Convert.ToDouble(value)); + + /// + public static ElectricPotentialChangeRate VoltsPerSeconds(this T value) => + ElectricPotentialChangeRate.FromVoltsPerSeconds(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs new file mode 100644 index 0000000000..c4e756e241 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricPotentialChangeRateTests : ElectricPotentialChangeRateTestsBase + { + protected override double KilovoltsPerHoursInOneVoltPerSecond => 3.6; + protected override double KilovoltsPerMicrosecondsInOneVoltPerSecond => 1E-09; + protected override double KilovoltsPerMinutesInOneVoltPerSecond => 6E-2; + protected override double KilovoltsPerSecondsInOneVoltPerSecond => 0.001; + protected override double MegavoltsPerHoursInOneVoltPerSecond => 36E-4; + protected override double MegavoltsPerMicrosecondsInOneVoltPerSecond => 1E-12; + protected override double MegavoltsPerMinutesInOneVoltPerSecond => 6E-05; + protected override double MegavoltsPerSecondsInOneVoltPerSecond => 1E-06; + protected override double MicrovoltsPerHoursInOneVoltPerSecond => 36E8; + protected override double MicrovoltsPerMicrosecondsInOneVoltPerSecond => 1; + protected override double MicrovoltsPerMinutesInOneVoltPerSecond => 6E7; + protected override double MicrovoltsPerSecondsInOneVoltPerSecond => 1E6; + protected override double MillivoltsPerHoursInOneVoltPerSecond => 36E5; + protected override double MillivoltsPerMicrosecondsInOneVoltPerSecond => 0.001; + protected override double MillivoltsPerMinutesInOneVoltPerSecond => 6E4; + protected override double MillivoltsPerSecondsInOneVoltPerSecond => 1000; + protected override double VoltsPerHoursInOneVoltPerSecond => 3600; + protected override double VoltsPerMicrosecondsInOneVoltPerSecond => 1E-06; + protected override double VoltsPerMinutesInOneVoltPerSecond => 60; + protected override double VoltsPerSecondsInOneVoltPerSecond => 1; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index f37067ab01..9d58a715be 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -62,6 +62,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, ElectricInductanceUnit.Nanohenry, Quantity.From(3, ElectricInductanceUnit.Nanohenry)); Assertion(3, ElectricPotentialUnit.Volt, Quantity.From(3, ElectricPotentialUnit.Volt)); Assertion(3, ElectricPotentialAcUnit.VoltAc, Quantity.From(3, ElectricPotentialAcUnit.VoltAc)); + Assertion(3, ElectricPotentialChangeRateUnit.VoltPerSecond, Quantity.From(3, ElectricPotentialChangeRateUnit.VoltPerSecond)); Assertion(3, ElectricPotentialDcUnit.VoltDc, Quantity.From(3, ElectricPotentialDcUnit.VoltDc)); Assertion(3, ElectricResistanceUnit.Ohm, Quantity.From(3, ElectricResistanceUnit.Ohm)); Assertion(3, ElectricResistivityUnit.PicoohmMeter, Quantity.From(3, ElectricResistivityUnit.PicoohmMeter)); @@ -168,6 +169,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricInductance.Info, ElectricInductance.Zero); Assertion(ElectricPotential.Info, ElectricPotential.Zero); Assertion(ElectricPotentialAc.Info, ElectricPotentialAc.Zero); + Assertion(ElectricPotentialChangeRate.Info, ElectricPotentialChangeRate.Zero); Assertion(ElectricPotentialDc.Info, ElectricPotentialDc.Zero); Assertion(ElectricResistance.Info, ElectricResistance.Zero); Assertion(ElectricResistivity.Info, ElectricResistivity.Zero); @@ -274,6 +276,7 @@ public void Type_EqualsStaticQuantityTypeProperty() Assertion(ElectricInductance.QuantityType, ElectricInductance.Zero); Assertion(ElectricPotential.QuantityType, ElectricPotential.Zero); Assertion(ElectricPotentialAc.QuantityType, ElectricPotentialAc.Zero); + Assertion(ElectricPotentialChangeRate.QuantityType, ElectricPotentialChangeRate.Zero); Assertion(ElectricPotentialDc.QuantityType, ElectricPotentialDc.Zero); Assertion(ElectricResistance.QuantityType, ElectricResistance.Zero); Assertion(ElectricResistivity.QuantityType, ElectricResistivity.Zero); @@ -380,6 +383,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricInductance.BaseDimensions, ElectricInductance.Zero); Assertion(ElectricPotential.BaseDimensions, ElectricPotential.Zero); Assertion(ElectricPotentialAc.BaseDimensions, ElectricPotentialAc.Zero); + Assertion(ElectricPotentialChangeRate.BaseDimensions, ElectricPotentialChangeRate.Zero); Assertion(ElectricPotentialDc.BaseDimensions, ElectricPotentialDc.Zero); Assertion(ElectricResistance.BaseDimensions, ElectricResistance.Zero); Assertion(ElectricResistivity.BaseDimensions, ElectricResistivity.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs new file mode 100644 index 0000000000..007422d221 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -0,0 +1,620 @@ +//------------------------------------------------------------------------------ +// +// 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.Globalization; +using System.Linq; +using System.Threading; +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 ElectricPotentialChangeRate. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricPotentialChangeRateTestsBase + { + protected abstract double KilovoltsPerHoursInOneVoltPerSecond { get; } + protected abstract double KilovoltsPerMicrosecondsInOneVoltPerSecond { get; } + protected abstract double KilovoltsPerMinutesInOneVoltPerSecond { get; } + protected abstract double KilovoltsPerSecondsInOneVoltPerSecond { get; } + protected abstract double MegavoltsPerHoursInOneVoltPerSecond { get; } + protected abstract double MegavoltsPerMicrosecondsInOneVoltPerSecond { get; } + protected abstract double MegavoltsPerMinutesInOneVoltPerSecond { get; } + protected abstract double MegavoltsPerSecondsInOneVoltPerSecond { get; } + protected abstract double MicrovoltsPerHoursInOneVoltPerSecond { get; } + protected abstract double MicrovoltsPerMicrosecondsInOneVoltPerSecond { get; } + protected abstract double MicrovoltsPerMinutesInOneVoltPerSecond { get; } + protected abstract double MicrovoltsPerSecondsInOneVoltPerSecond { get; } + protected abstract double MillivoltsPerHoursInOneVoltPerSecond { get; } + protected abstract double MillivoltsPerMicrosecondsInOneVoltPerSecond { get; } + protected abstract double MillivoltsPerMinutesInOneVoltPerSecond { get; } + protected abstract double MillivoltsPerSecondsInOneVoltPerSecond { get; } + protected abstract double VoltsPerHoursInOneVoltPerSecond { get; } + protected abstract double VoltsPerMicrosecondsInOneVoltPerSecond { get; } + protected abstract double VoltsPerMinutesInOneVoltPerSecond { get; } + protected abstract double VoltsPerSecondsInOneVoltPerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double KilovoltsPerHoursTolerance { get { return 1e-5; } } + protected virtual double KilovoltsPerMicrosecondsTolerance { get { return 1e-5; } } + protected virtual double KilovoltsPerMinutesTolerance { get { return 1e-5; } } + protected virtual double KilovoltsPerSecondsTolerance { get { return 1e-5; } } + protected virtual double MegavoltsPerHoursTolerance { get { return 1e-5; } } + protected virtual double MegavoltsPerMicrosecondsTolerance { get { return 1e-5; } } + protected virtual double MegavoltsPerMinutesTolerance { get { return 1e-5; } } + protected virtual double MegavoltsPerSecondsTolerance { get { return 1e-5; } } + protected virtual double MicrovoltsPerHoursTolerance { get { return 1e-5; } } + protected virtual double MicrovoltsPerMicrosecondsTolerance { get { return 1e-5; } } + protected virtual double MicrovoltsPerMinutesTolerance { get { return 1e-5; } } + protected virtual double MicrovoltsPerSecondsTolerance { get { return 1e-5; } } + protected virtual double MillivoltsPerHoursTolerance { get { return 1e-5; } } + protected virtual double MillivoltsPerMicrosecondsTolerance { get { return 1e-5; } } + protected virtual double MillivoltsPerMinutesTolerance { get { return 1e-5; } } + protected virtual double MillivoltsPerSecondsTolerance { get { return 1e-5; } } + protected virtual double VoltsPerHoursTolerance { get { return 1e-5; } } + protected virtual double VoltsPerMicrosecondsTolerance { get { return 1e-5; } } + protected virtual double VoltsPerMinutesTolerance { get { return 1e-5; } } + protected virtual double VoltsPerSecondsTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void Ctor_WithUndefinedUnit_ThrowsArgumentException() + { + Assert.Throws(() => new ElectricPotentialChangeRate((double)0.0, ElectricPotentialChangeRateUnit.Undefined)); + } + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricPotentialChangeRate(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, quantity.Unit); + } + + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new ElectricPotentialChangeRate(double.PositiveInfinity, ElectricPotentialChangeRateUnit.VoltPerSecond)); + Assert.Throws(() => new ElectricPotentialChangeRate(double.NegativeInfinity, ElectricPotentialChangeRateUnit.VoltPerSecond)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new ElectricPotentialChangeRate(double.NaN, ElectricPotentialChangeRateUnit.VoltPerSecond)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricPotentialChangeRate(value: 1.0, unitSystem: null)); + } + + [Fact] + public void ElectricPotentialChangeRate_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerSecond); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricPotentialChangeRate.Zero, quantityInfo.Zero); + Assert.Equal("ElectricPotentialChangeRate", quantityInfo.Name); + Assert.Equal(QuantityType.ElectricPotentialChangeRate, quantityInfo.QuantityType); + + var units = EnumUtils.GetEnumValues().Except(new[] {ElectricPotentialChangeRateUnit.Undefined}).ToArray(); + var unitNames = units.Select(x => x.ToString()); + + // Obsolete members +#pragma warning disable 618 + Assert.Equal(units, quantityInfo.Units); + Assert.Equal(unitNames, quantityInfo.UnitNames); +#pragma warning restore 618 + } + + [Fact] + public void VoltPerSecondToElectricPotentialChangeRateUnits() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + AssertEx.EqualTolerance(KilovoltsPerHoursInOneVoltPerSecond, voltpersecond.KilovoltsPerHours, KilovoltsPerHoursTolerance); + AssertEx.EqualTolerance(KilovoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.KilovoltsPerMicroseconds, KilovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(KilovoltsPerMinutesInOneVoltPerSecond, voltpersecond.KilovoltsPerMinutes, KilovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(KilovoltsPerSecondsInOneVoltPerSecond, voltpersecond.KilovoltsPerSeconds, KilovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MegavoltsPerHoursInOneVoltPerSecond, voltpersecond.MegavoltsPerHours, MegavoltsPerHoursTolerance); + AssertEx.EqualTolerance(MegavoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.MegavoltsPerMicroseconds, MegavoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MegavoltsPerMinutesInOneVoltPerSecond, voltpersecond.MegavoltsPerMinutes, MegavoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MegavoltsPerSecondsInOneVoltPerSecond, voltpersecond.MegavoltsPerSeconds, MegavoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MicrovoltsPerHoursInOneVoltPerSecond, voltpersecond.MicrovoltsPerHours, MicrovoltsPerHoursTolerance); + AssertEx.EqualTolerance(MicrovoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.MicrovoltsPerMicroseconds, MicrovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MicrovoltsPerMinutesInOneVoltPerSecond, voltpersecond.MicrovoltsPerMinutes, MicrovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MicrovoltsPerSecondsInOneVoltPerSecond, voltpersecond.MicrovoltsPerSeconds, MicrovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MillivoltsPerHoursInOneVoltPerSecond, voltpersecond.MillivoltsPerHours, MillivoltsPerHoursTolerance); + AssertEx.EqualTolerance(MillivoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.MillivoltsPerMicroseconds, MillivoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MillivoltsPerMinutesInOneVoltPerSecond, voltpersecond.MillivoltsPerMinutes, MillivoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MillivoltsPerSecondsInOneVoltPerSecond, voltpersecond.MillivoltsPerSeconds, MillivoltsPerSecondsTolerance); + AssertEx.EqualTolerance(VoltsPerHoursInOneVoltPerSecond, voltpersecond.VoltsPerHours, VoltsPerHoursTolerance); + AssertEx.EqualTolerance(VoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.VoltsPerMicroseconds, VoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(VoltsPerMinutesInOneVoltPerSecond, voltpersecond.VoltsPerMinutes, VoltsPerMinutesTolerance); + AssertEx.EqualTolerance(VoltsPerSecondsInOneVoltPerSecond, voltpersecond.VoltsPerSeconds, VoltsPerSecondsTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.KilovoltPerHour); + AssertEx.EqualTolerance(1, quantity00.KilovoltsPerHours, KilovoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, quantity00.Unit); + + var quantity01 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + AssertEx.EqualTolerance(1, quantity01.KilovoltsPerMicroseconds, KilovoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, quantity01.Unit); + + var quantity02 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.KilovoltPerMinute); + AssertEx.EqualTolerance(1, quantity02.KilovoltsPerMinutes, KilovoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, quantity02.Unit); + + var quantity03 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.KilovoltPerSecond); + AssertEx.EqualTolerance(1, quantity03.KilovoltsPerSeconds, KilovoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, quantity03.Unit); + + var quantity04 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MegavoltPerHour); + AssertEx.EqualTolerance(1, quantity04.MegavoltsPerHours, MegavoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerHour, quantity04.Unit); + + var quantity05 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + AssertEx.EqualTolerance(1, quantity05.MegavoltsPerMicroseconds, MegavoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, quantity05.Unit); + + var quantity06 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MegavoltPerMinute); + AssertEx.EqualTolerance(1, quantity06.MegavoltsPerMinutes, MegavoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMinute, quantity06.Unit); + + var quantity07 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MegavoltPerSecond); + AssertEx.EqualTolerance(1, quantity07.MegavoltsPerSeconds, MegavoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerSecond, quantity07.Unit); + + var quantity08 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MicrovoltPerHour); + AssertEx.EqualTolerance(1, quantity08.MicrovoltsPerHours, MicrovoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, quantity08.Unit); + + var quantity09 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + AssertEx.EqualTolerance(1, quantity09.MicrovoltsPerMicroseconds, MicrovoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, quantity09.Unit); + + var quantity10 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + AssertEx.EqualTolerance(1, quantity10.MicrovoltsPerMinutes, MicrovoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, quantity10.Unit); + + var quantity11 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + AssertEx.EqualTolerance(1, quantity11.MicrovoltsPerSeconds, MicrovoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, quantity11.Unit); + + var quantity12 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MillivoltPerHour); + AssertEx.EqualTolerance(1, quantity12.MillivoltsPerHours, MillivoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerHour, quantity12.Unit); + + var quantity13 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + AssertEx.EqualTolerance(1, quantity13.MillivoltsPerMicroseconds, MillivoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, quantity13.Unit); + + var quantity14 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MillivoltPerMinute); + AssertEx.EqualTolerance(1, quantity14.MillivoltsPerMinutes, MillivoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMinute, quantity14.Unit); + + var quantity15 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.MillivoltPerSecond); + AssertEx.EqualTolerance(1, quantity15.MillivoltsPerSeconds, MillivoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerSecond, quantity15.Unit); + + var quantity16 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.VoltPerHour); + AssertEx.EqualTolerance(1, quantity16.VoltsPerHours, VoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, quantity16.Unit); + + var quantity17 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + AssertEx.EqualTolerance(1, quantity17.VoltsPerMicroseconds, VoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, quantity17.Unit); + + var quantity18 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.VoltPerMinute); + AssertEx.EqualTolerance(1, quantity18.VoltsPerMinutes, VoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, quantity18.Unit); + + var quantity19 = ElectricPotentialChangeRate.From(1, ElectricPotentialChangeRateUnit.VoltPerSecond); + AssertEx.EqualTolerance(1, quantity19.VoltsPerSeconds, VoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, quantity19.Unit); + + } + + [Fact] + public void FromVoltsPerSeconds_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => ElectricPotentialChangeRate.FromVoltsPerSeconds(double.PositiveInfinity)); + Assert.Throws(() => ElectricPotentialChangeRate.FromVoltsPerSeconds(double.NegativeInfinity)); + } + + [Fact] + public void FromVoltsPerSeconds_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => ElectricPotentialChangeRate.FromVoltsPerSeconds(double.NaN)); + } + + [Fact] + public void As() + { + var voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + AssertEx.EqualTolerance(KilovoltsPerHoursInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.KilovoltPerHour), KilovoltsPerHoursTolerance); + AssertEx.EqualTolerance(KilovoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond), KilovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(KilovoltsPerMinutesInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.KilovoltPerMinute), KilovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(KilovoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.KilovoltPerSecond), KilovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MegavoltsPerHoursInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MegavoltPerHour), MegavoltsPerHoursTolerance); + AssertEx.EqualTolerance(MegavoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond), MegavoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MegavoltsPerMinutesInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MegavoltPerMinute), MegavoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MegavoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MegavoltPerSecond), MegavoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MicrovoltsPerHoursInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MicrovoltPerHour), MicrovoltsPerHoursTolerance); + AssertEx.EqualTolerance(MicrovoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond), MicrovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MicrovoltsPerMinutesInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MicrovoltPerMinute), MicrovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MicrovoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MicrovoltPerSecond), MicrovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(MillivoltsPerHoursInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MillivoltPerHour), MillivoltsPerHoursTolerance); + AssertEx.EqualTolerance(MillivoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond), MillivoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(MillivoltsPerMinutesInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MillivoltPerMinute), MillivoltsPerMinutesTolerance); + AssertEx.EqualTolerance(MillivoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.MillivoltPerSecond), MillivoltsPerSecondsTolerance); + AssertEx.EqualTolerance(VoltsPerHoursInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.VoltPerHour), VoltsPerHoursTolerance); + AssertEx.EqualTolerance(VoltsPerMicrosecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.VoltPerMicrosecond), VoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(VoltsPerMinutesInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.VoltPerMinute), VoltsPerMinutesTolerance); + AssertEx.EqualTolerance(VoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.VoltPerSecond), VoltsPerSecondsTolerance); + } + + [Fact] + public void ToUnit() + { + var voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + + var kilovoltperhourQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerHour); + AssertEx.EqualTolerance(KilovoltsPerHoursInOneVoltPerSecond, (double)kilovoltperhourQuantity.Value, KilovoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, kilovoltperhourQuantity.Unit); + + var kilovoltpermicrosecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + AssertEx.EqualTolerance(KilovoltsPerMicrosecondsInOneVoltPerSecond, (double)kilovoltpermicrosecondQuantity.Value, KilovoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, kilovoltpermicrosecondQuantity.Unit); + + var kilovoltperminuteQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerMinute); + AssertEx.EqualTolerance(KilovoltsPerMinutesInOneVoltPerSecond, (double)kilovoltperminuteQuantity.Value, KilovoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, kilovoltperminuteQuantity.Unit); + + var kilovoltpersecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerSecond); + AssertEx.EqualTolerance(KilovoltsPerSecondsInOneVoltPerSecond, (double)kilovoltpersecondQuantity.Value, KilovoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, kilovoltpersecondQuantity.Unit); + + var megavoltperhourQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerHour); + AssertEx.EqualTolerance(MegavoltsPerHoursInOneVoltPerSecond, (double)megavoltperhourQuantity.Value, MegavoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerHour, megavoltperhourQuantity.Unit); + + var megavoltpermicrosecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + AssertEx.EqualTolerance(MegavoltsPerMicrosecondsInOneVoltPerSecond, (double)megavoltpermicrosecondQuantity.Value, MegavoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, megavoltpermicrosecondQuantity.Unit); + + var megavoltperminuteQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerMinute); + AssertEx.EqualTolerance(MegavoltsPerMinutesInOneVoltPerSecond, (double)megavoltperminuteQuantity.Value, MegavoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMinute, megavoltperminuteQuantity.Unit); + + var megavoltpersecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerSecond); + AssertEx.EqualTolerance(MegavoltsPerSecondsInOneVoltPerSecond, (double)megavoltpersecondQuantity.Value, MegavoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerSecond, megavoltpersecondQuantity.Unit); + + var microvoltperhourQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerHour); + AssertEx.EqualTolerance(MicrovoltsPerHoursInOneVoltPerSecond, (double)microvoltperhourQuantity.Value, MicrovoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, microvoltperhourQuantity.Unit); + + var microvoltpermicrosecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + AssertEx.EqualTolerance(MicrovoltsPerMicrosecondsInOneVoltPerSecond, (double)microvoltpermicrosecondQuantity.Value, MicrovoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, microvoltpermicrosecondQuantity.Unit); + + var microvoltperminuteQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + AssertEx.EqualTolerance(MicrovoltsPerMinutesInOneVoltPerSecond, (double)microvoltperminuteQuantity.Value, MicrovoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, microvoltperminuteQuantity.Unit); + + var microvoltpersecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + AssertEx.EqualTolerance(MicrovoltsPerSecondsInOneVoltPerSecond, (double)microvoltpersecondQuantity.Value, MicrovoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, microvoltpersecondQuantity.Unit); + + var millivoltperhourQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerHour); + AssertEx.EqualTolerance(MillivoltsPerHoursInOneVoltPerSecond, (double)millivoltperhourQuantity.Value, MillivoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerHour, millivoltperhourQuantity.Unit); + + var millivoltpermicrosecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + AssertEx.EqualTolerance(MillivoltsPerMicrosecondsInOneVoltPerSecond, (double)millivoltpermicrosecondQuantity.Value, MillivoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, millivoltpermicrosecondQuantity.Unit); + + var millivoltperminuteQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerMinute); + AssertEx.EqualTolerance(MillivoltsPerMinutesInOneVoltPerSecond, (double)millivoltperminuteQuantity.Value, MillivoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMinute, millivoltperminuteQuantity.Unit); + + var millivoltpersecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerSecond); + AssertEx.EqualTolerance(MillivoltsPerSecondsInOneVoltPerSecond, (double)millivoltpersecondQuantity.Value, MillivoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerSecond, millivoltpersecondQuantity.Unit); + + var voltperhourQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.VoltPerHour); + AssertEx.EqualTolerance(VoltsPerHoursInOneVoltPerSecond, (double)voltperhourQuantity.Value, VoltsPerHoursTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, voltperhourQuantity.Unit); + + var voltpermicrosecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + AssertEx.EqualTolerance(VoltsPerMicrosecondsInOneVoltPerSecond, (double)voltpermicrosecondQuantity.Value, VoltsPerMicrosecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, voltpermicrosecondQuantity.Unit); + + var voltperminuteQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.VoltPerMinute); + AssertEx.EqualTolerance(VoltsPerMinutesInOneVoltPerSecond, (double)voltperminuteQuantity.Value, VoltsPerMinutesTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, voltperminuteQuantity.Unit); + + var voltpersecondQuantity = voltpersecond.ToUnit(ElectricPotentialChangeRateUnit.VoltPerSecond); + AssertEx.EqualTolerance(VoltsPerSecondsInOneVoltPerSecond, (double)voltpersecondQuantity.Value, VoltsPerSecondsTolerance); + Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, voltpersecondQuantity.Unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromKilovoltsPerHours(voltpersecond.KilovoltsPerHours).VoltsPerSeconds, KilovoltsPerHoursTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromKilovoltsPerMicroseconds(voltpersecond.KilovoltsPerMicroseconds).VoltsPerSeconds, KilovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromKilovoltsPerMinutes(voltpersecond.KilovoltsPerMinutes).VoltsPerSeconds, KilovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromKilovoltsPerSeconds(voltpersecond.KilovoltsPerSeconds).VoltsPerSeconds, KilovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMegavoltsPerHours(voltpersecond.MegavoltsPerHours).VoltsPerSeconds, MegavoltsPerHoursTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMegavoltsPerMicroseconds(voltpersecond.MegavoltsPerMicroseconds).VoltsPerSeconds, MegavoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMegavoltsPerMinutes(voltpersecond.MegavoltsPerMinutes).VoltsPerSeconds, MegavoltsPerMinutesTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMegavoltsPerSeconds(voltpersecond.MegavoltsPerSeconds).VoltsPerSeconds, MegavoltsPerSecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMicrovoltsPerHours(voltpersecond.MicrovoltsPerHours).VoltsPerSeconds, MicrovoltsPerHoursTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMicrovoltsPerMicroseconds(voltpersecond.MicrovoltsPerMicroseconds).VoltsPerSeconds, MicrovoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMicrovoltsPerMinutes(voltpersecond.MicrovoltsPerMinutes).VoltsPerSeconds, MicrovoltsPerMinutesTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMicrovoltsPerSeconds(voltpersecond.MicrovoltsPerSeconds).VoltsPerSeconds, MicrovoltsPerSecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMillivoltsPerHours(voltpersecond.MillivoltsPerHours).VoltsPerSeconds, MillivoltsPerHoursTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMillivoltsPerMicroseconds(voltpersecond.MillivoltsPerMicroseconds).VoltsPerSeconds, MillivoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMillivoltsPerMinutes(voltpersecond.MillivoltsPerMinutes).VoltsPerSeconds, MillivoltsPerMinutesTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromMillivoltsPerSeconds(voltpersecond.MillivoltsPerSeconds).VoltsPerSeconds, MillivoltsPerSecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromVoltsPerHours(voltpersecond.VoltsPerHours).VoltsPerSeconds, VoltsPerHoursTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromVoltsPerMicroseconds(voltpersecond.VoltsPerMicroseconds).VoltsPerSeconds, VoltsPerMicrosecondsTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromVoltsPerMinutes(voltpersecond.VoltsPerMinutes).VoltsPerSeconds, VoltsPerMinutesTolerance); + AssertEx.EqualTolerance(1, ElectricPotentialChangeRate.FromVoltsPerSeconds(voltpersecond.VoltsPerSeconds).VoltsPerSeconds, VoltsPerSecondsTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricPotentialChangeRate v = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + AssertEx.EqualTolerance(-1, -v.VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(2, (ElectricPotentialChangeRate.FromVoltsPerSeconds(3)-v).VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(2, (v + v).VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(10, (v*10).VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(10, (10*v).VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(2, (ElectricPotentialChangeRate.FromVoltsPerSeconds(10)/5).VoltsPerSeconds, VoltsPerSecondsTolerance); + AssertEx.EqualTolerance(2, ElectricPotentialChangeRate.FromVoltsPerSeconds(10)/ElectricPotentialChangeRate.FromVoltsPerSeconds(5), VoltsPerSecondsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricPotentialChangeRate oneVoltPerSecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + ElectricPotentialChangeRate twoVoltsPerSeconds = ElectricPotentialChangeRate.FromVoltsPerSeconds(2); + + Assert.True(oneVoltPerSecond < twoVoltsPerSeconds); + Assert.True(oneVoltPerSecond <= twoVoltsPerSeconds); + Assert.True(twoVoltsPerSeconds > oneVoltPerSecond); + Assert.True(twoVoltsPerSeconds >= oneVoltPerSecond); + + Assert.False(oneVoltPerSecond > twoVoltsPerSeconds); + Assert.False(oneVoltPerSecond >= twoVoltsPerSeconds); + Assert.False(twoVoltsPerSeconds < oneVoltPerSecond); + Assert.False(twoVoltsPerSeconds <= oneVoltPerSecond); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.Equal(0, voltpersecond.CompareTo(voltpersecond)); + Assert.True(voltpersecond.CompareTo(ElectricPotentialChangeRate.Zero) > 0); + Assert.True(ElectricPotentialChangeRate.Zero.CompareTo(voltpersecond) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.Throws(() => voltpersecond.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.Throws(() => voltpersecond.CompareTo(null)); + } + + [Fact] + public void EqualityOperators() + { + var a = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + var b = ElectricPotentialChangeRate.FromVoltsPerSeconds(2); + + // ReSharper disable EqualExpressionComparison + + Assert.True(a == a); + Assert.False(a != a); + + Assert.True(a != b); + Assert.False(a == b); + + Assert.False(a == null); + Assert.False(null == a); + +// ReSharper restore EqualExpressionComparison + } + + [Fact] + public void EqualsIsImplemented() + { + var a = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + var b = ElectricPotentialChangeRate.FromVoltsPerSeconds(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + Assert.False(a.Equals(null)); + } + + [Fact] + public void EqualsRelativeToleranceIsImplemented() + { + var v = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.True(v.Equals(ElectricPotentialChangeRate.FromVoltsPerSeconds(1), VoltsPerSecondsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricPotentialChangeRate.Zero, VoltsPerSecondsTolerance, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.False(voltpersecond.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricPotentialChangeRate voltpersecond = ElectricPotentialChangeRate.FromVoltsPerSeconds(1); + Assert.False(voltpersecond.Equals(null)); + } + + [Fact] + public void UnitsDoesNotContainUndefined() + { + Assert.DoesNotContain(ElectricPotentialChangeRateUnit.Undefined, ElectricPotentialChangeRate.Units); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricPotentialChangeRateUnit)).Cast(); + foreach(var unit in units) + { + if(unit == ElectricPotentialChangeRateUnit.Undefined) + continue; + + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricPotentialChangeRate.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentUICulture; + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 kV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerHour).ToString()); + Assert.Equal("1 kV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond).ToString()); + Assert.Equal("1 kV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerMinute).ToString()); + Assert.Equal("1 kV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerSecond).ToString()); + Assert.Equal("1 MV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerHour).ToString()); + Assert.Equal("1 MV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond).ToString()); + Assert.Equal("1 MV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerMinute).ToString()); + Assert.Equal("1 MV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerSecond).ToString()); + Assert.Equal("1 µV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerHour).ToString()); + Assert.Equal("1 µV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond).ToString()); + Assert.Equal("1 µV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerMinute).ToString()); + Assert.Equal("1 µV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerSecond).ToString()); + Assert.Equal("1 mV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerHour).ToString()); + Assert.Equal("1 mV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond).ToString()); + Assert.Equal("1 mV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerMinute).ToString()); + Assert.Equal("1 mV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerSecond).ToString()); + Assert.Equal("1 V/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerHour).ToString()); + Assert.Equal("1 V/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerMicrosecond).ToString()); + Assert.Equal("1 V/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerMinute).ToString()); + Assert.Equal("1 V/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString()); + } + finally + { + Thread.CurrentThread.CurrentUICulture = prevCulture; + } + } + + [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 kV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerHour).ToString(swedishCulture)); + Assert.Equal("1 kV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond).ToString(swedishCulture)); + Assert.Equal("1 kV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerMinute).ToString(swedishCulture)); + Assert.Equal("1 kV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.KilovoltPerSecond).ToString(swedishCulture)); + Assert.Equal("1 MV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerHour).ToString(swedishCulture)); + Assert.Equal("1 MV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond).ToString(swedishCulture)); + Assert.Equal("1 MV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerMinute).ToString(swedishCulture)); + Assert.Equal("1 MV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MegavoltPerSecond).ToString(swedishCulture)); + Assert.Equal("1 µV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerHour).ToString(swedishCulture)); + Assert.Equal("1 µV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond).ToString(swedishCulture)); + Assert.Equal("1 µV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerMinute).ToString(swedishCulture)); + Assert.Equal("1 µV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MicrovoltPerSecond).ToString(swedishCulture)); + Assert.Equal("1 mV/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerHour).ToString(swedishCulture)); + Assert.Equal("1 mV/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond).ToString(swedishCulture)); + Assert.Equal("1 mV/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerMinute).ToString(swedishCulture)); + Assert.Equal("1 mV/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.MillivoltPerSecond).ToString(swedishCulture)); + Assert.Equal("1 V/h", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerHour).ToString(swedishCulture)); + Assert.Equal("1 V/μs", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerMicrosecond).ToString(swedishCulture)); + Assert.Equal("1 V/min", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerMinute).ToString(swedishCulture)); + Assert.Equal("1 V/s", new ElectricPotentialChangeRate(1, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentUICulture; + try + { + CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s1")); + Assert.Equal("0.12 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s2")); + Assert.Equal("0.123 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s3")); + Assert.Equal("0.1235 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s4")); + } + finally + { + CultureInfo.CurrentUICulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s1", culture)); + Assert.Equal("0.12 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s2", culture)); + Assert.Equal("0.123 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s3", culture)); + Assert.Equal("0.1235 V/s", new ElectricPotentialChangeRate(0.123456, ElectricPotentialChangeRateUnit.VoltPerSecond).ToString("s4", culture)); + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs new file mode 100644 index 0000000000..4d6fccf637 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -0,0 +1,903 @@ +//------------------------------------------------------------------------------ +// +// 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.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// ElectricPotential change rate is the ratio of the electric potential change to the time during which the change occurred (value of electric potential changes per unit time). + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class ElectricPotentialChangeRate : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricPotentialChangeRateUnit? _unit; + + static ElectricPotentialChangeRate() + { + BaseDimensions = new BaseDimensions(2, 1, -4, -1, 0, 0, 0); + Info = new QuantityInfo(QuantityType.ElectricPotentialChangeRate, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit VoltPerSecond. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public ElectricPotentialChangeRate() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// 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. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit unit) + { + if(unit == ElectricPotentialChangeRateUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of ElectricPotentialChangeRate, which is VoltPerSecond. All conversions go via this value. + /// + public static ElectricPotentialChangeRateUnit BaseUnit { get; } = ElectricPotentialChangeRateUnit.VoltPerSecond; + + /// + /// Represents the largest possible value of ElectricPotentialChangeRate + /// + public static ElectricPotentialChangeRate MaxValue { get; } = new ElectricPotentialChangeRate(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricPotentialChangeRate + /// + public static ElectricPotentialChangeRate MinValue { get; } = new ElectricPotentialChangeRate(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.ElectricPotentialChangeRate; + + /// + /// All units of measurement for the ElectricPotentialChangeRate quantity. + /// + public static ElectricPotentialChangeRateUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialChangeRateUnit)).Cast().Except(new ElectricPotentialChangeRateUnit[]{ ElectricPotentialChangeRateUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerSecond. + /// + public static ElectricPotentialChangeRate Zero { get; } = new ElectricPotentialChangeRate(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public ElectricPotentialChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => ElectricPotentialChangeRate.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricPotentialChangeRate.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerHours. + /// + public double KilovoltsPerHours => As(ElectricPotentialChangeRateUnit.KilovoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerMicroseconds. + /// + public double KilovoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerMinutes. + /// + public double KilovoltsPerMinutes => As(ElectricPotentialChangeRateUnit.KilovoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerSeconds. + /// + public double KilovoltsPerSeconds => As(ElectricPotentialChangeRateUnit.KilovoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerHours. + /// + public double MegavoltsPerHours => As(ElectricPotentialChangeRateUnit.MegavoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerMicroseconds. + /// + public double MegavoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerMinutes. + /// + public double MegavoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MegavoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerSeconds. + /// + public double MegavoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MegavoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerHours. + /// + public double MicrovoltsPerHours => As(ElectricPotentialChangeRateUnit.MicrovoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerMicroseconds. + /// + public double MicrovoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerMinutes. + /// + public double MicrovoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerSeconds. + /// + public double MicrovoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerHours. + /// + public double MillivoltsPerHours => As(ElectricPotentialChangeRateUnit.MillivoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerMicroseconds. + /// + public double MillivoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerMinutes. + /// + public double MillivoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MillivoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerSeconds. + /// + public double MillivoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MillivoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerHours. + /// + public double VoltsPerHours => As(ElectricPotentialChangeRateUnit.VoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerMicroseconds. + /// + public double VoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerMinutes. + /// + public double VoltsPerMinutes => As(ElectricPotentialChangeRateUnit.VoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerSeconds. + /// + public double VoltsPerSeconds => As(ElectricPotentialChangeRateUnit.VoltPerSecond); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricPotentialChangeRateUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(ElectricPotentialChangeRateUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerHours. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromKilovoltsPerHours(double kilovoltsperhours) + { + double value = (double) kilovoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromKilovoltsPerMicroseconds(double kilovoltspermicroseconds) + { + double value = (double) kilovoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerMinutes. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromKilovoltsPerMinutes(double kilovoltsperminutes) + { + double value = (double) kilovoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerSeconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromKilovoltsPerSeconds(double kilovoltsperseconds) + { + double value = (double) kilovoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerHours. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMegavoltsPerHours(double megavoltsperhours) + { + double value = (double) megavoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMegavoltsPerMicroseconds(double megavoltspermicroseconds) + { + double value = (double) megavoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerMinutes. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMegavoltsPerMinutes(double megavoltsperminutes) + { + double value = (double) megavoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerSeconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMegavoltsPerSeconds(double megavoltsperseconds) + { + double value = (double) megavoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerHours. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMicrovoltsPerHours(double microvoltsperhours) + { + double value = (double) microvoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMicrovoltsPerMicroseconds(double microvoltspermicroseconds) + { + double value = (double) microvoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerMinutes. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMicrovoltsPerMinutes(double microvoltsperminutes) + { + double value = (double) microvoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerSeconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMicrovoltsPerSeconds(double microvoltsperseconds) + { + double value = (double) microvoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerHours. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMillivoltsPerHours(double millivoltsperhours) + { + double value = (double) millivoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMillivoltsPerMicroseconds(double millivoltspermicroseconds) + { + double value = (double) millivoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerMinutes. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMillivoltsPerMinutes(double millivoltsperminutes) + { + double value = (double) millivoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerSeconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromMillivoltsPerSeconds(double millivoltsperseconds) + { + double value = (double) millivoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerHours. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromVoltsPerHours(double voltsperhours) + { + double value = (double) voltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromVoltsPerMicroseconds(double voltspermicroseconds) + { + double value = (double) voltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerMinutes. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromVoltsPerMinutes(double voltsperminutes) + { + double value = (double) voltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerSeconds. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricPotentialChangeRate FromVoltsPerSeconds(double voltsperseconds) + { + double value = (double) voltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerSecond); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricPotentialChangeRate unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricPotentialChangeRate From(double value, ElectricPotentialChangeRateUnit fromUnit) + { + return new ElectricPotentialChangeRate((double)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", new CultureInfo("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 ElectricPotentialChangeRate 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", new CultureInfo("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. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static ElectricPotentialChangeRate Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + 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", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out ElectricPotentialChangeRate 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", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricPotentialChangeRate result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + 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", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricPotentialChangeRateUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static ElectricPotentialChangeRateUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out ElectricPotentialChangeRateUnit 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", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricPotentialChangeRateUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is ElectricPotentialChangeRate objElectricPotentialChangeRate)) throw new ArgumentException("Expected type ElectricPotentialChangeRate.", nameof(obj)); + + return CompareTo(objElectricPotentialChangeRate); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(ElectricPotentialChangeRate other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is ElectricPotentialChangeRate objElectricPotentialChangeRate)) + return false; + + return Equals(objElectricPotentialChangeRate); + } + + public bool Equals(ElectricPotentialChangeRate other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another ElectricPotentialChangeRate within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.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(ElectricPotentialChangeRate other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current ElectricPotentialChangeRate. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((ElectricPotentialChangeRateUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricPotentialChangeRateUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this ElectricPotentialChangeRate to another ElectricPotentialChangeRate with the unit representation . + /// + /// A ElectricPotentialChangeRate with the specified unit. + public ElectricPotentialChangeRate ToUnit(ElectricPotentialChangeRateUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new ElectricPotentialChangeRate(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case ElectricPotentialChangeRateUnit.KilovoltPerHour: return (_value/3600) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond: return (_value*1E6) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMinute: return (_value/60) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerSecond: return (_value) * 1e3d; + case ElectricPotentialChangeRateUnit.MegavoltPerHour: return (_value/3600) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond: return (_value*1E6) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMinute: return (_value/60) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerSecond: return (_value) * 1e6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerHour: return (_value/3600) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond: return (_value*1E6) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMinute: return (_value/60) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerSecond: return (_value) * 1e-6d; + case ElectricPotentialChangeRateUnit.MillivoltPerHour: return (_value/3600) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond: return (_value*1E6) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMinute: return (_value/60) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerSecond: return (_value) * 1e-3d; + case ElectricPotentialChangeRateUnit.VoltPerHour: return _value/3600; + case ElectricPotentialChangeRateUnit.VoltPerMicrosecond: return _value*1E6; + case ElectricPotentialChangeRateUnit.VoltPerMinute: return _value/60; + case ElectricPotentialChangeRateUnit.VoltPerSecond: return _value; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(ElectricPotentialChangeRateUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case ElectricPotentialChangeRateUnit.KilovoltPerHour: return (baseUnitValue*3600) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond: return (baseUnitValue/1E6) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMinute: return (baseUnitValue*60) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerSecond: return (baseUnitValue) / 1e3d; + case ElectricPotentialChangeRateUnit.MegavoltPerHour: return (baseUnitValue*3600) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond: return (baseUnitValue/1E6) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMinute: return (baseUnitValue*60) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerSecond: return (baseUnitValue) / 1e6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerHour: return (baseUnitValue*3600) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond: return (baseUnitValue/1E6) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMinute: return (baseUnitValue*60) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerSecond: return (baseUnitValue) / 1e-6d; + case ElectricPotentialChangeRateUnit.MillivoltPerHour: return (baseUnitValue*3600) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond: return (baseUnitValue/1E6) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMinute: return (baseUnitValue*60) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerSecond: return (baseUnitValue) / 1e-3d; + case ElectricPotentialChangeRateUnit.VoltPerHour: return baseUnitValue*3600; + case ElectricPotentialChangeRateUnit.VoltPerMicrosecond: return baseUnitValue/1E6; + case ElectricPotentialChangeRateUnit.VoltPerMinute: return baseUnitValue*60; + case ElectricPotentialChangeRateUnit.VoltPerSecond: return baseUnitValue; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs index d691be5233..1b3d5f547e 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -125,6 +125,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case ElectricPotentialAcUnit electricPotentialAcUnit: quantity = ElectricPotentialAc.From(value, electricPotentialAcUnit); return true; + case ElectricPotentialChangeRateUnit electricPotentialChangeRateUnit: + quantity = ElectricPotentialChangeRate.From(value, electricPotentialChangeRateUnit); + return true; case ElectricPotentialDcUnit electricPotentialDcUnit: quantity = ElectricPotentialDc.From(value, electricPotentialDcUnit); return true; @@ -472,6 +475,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(ElectricPotentialAc)) return parser.TryParse(quantityString, formatProvider, ElectricPotentialAc.From, out quantity); + if (quantityType == typeof(ElectricPotentialChangeRate)) + return parser.TryParse(quantityString, formatProvider, ElectricPotentialChangeRate.From, out quantity); + if (quantityType == typeof(ElectricPotentialDc)) return parser.TryParse(quantityString, formatProvider, ElectricPotentialDc.From, out quantity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index c449278e29..a6e4cec3e9 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -57,6 +57,7 @@ public enum QuantityType ElectricInductance, ElectricPotential, ElectricPotentialAc, + ElectricPotentialChangeRate, ElectricPotentialDc, ElectricResistance, ElectricResistivity, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index b15b146a18..890821bbef 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -285,6 +285,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.MicrovoltAc, new string[]{"µVac"}), ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.MillivoltAc, new string[]{"mVac"}), ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.VoltAc, new string[]{"Vac"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerHour, new string[]{"kV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, new string[]{"kV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerMinute, new string[]{"kV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerSecond, new string[]{"kV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerHour, new string[]{"MV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, new string[]{"MV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerMinute, new string[]{"MV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerSecond, new string[]{"MV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerHour, new string[]{"µV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, new string[]{"µV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerMinute, new string[]{"µV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerSecond, new string[]{"µV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerHour, new string[]{"mV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, new string[]{"mV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerMinute, new string[]{"mV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerSecond, new string[]{"mV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerHour, new string[]{"V/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerMicrosecond, new string[]{"V/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerMinute, new string[]{"V/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerSecond, new string[]{"V/s"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.KilovoltDc, new string[]{"kVdc"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.MegavoltDc, new string[]{"MVdc"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.MicrovoltDc, new string[]{"µVdc"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs new file mode 100644 index 0000000000..61b66535e6 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricPotentialChangeRateUnit + { + Undefined = 0, + KilovoltPerHour, + KilovoltPerMicrosecond, + KilovoltPerMinute, + KilovoltPerSecond, + MegavoltPerHour, + MegavoltPerMicrosecond, + MegavoltPerMinute, + MegavoltPerSecond, + MicrovoltPerHour, + MicrovoltPerMicrosecond, + MicrovoltPerMinute, + MicrovoltPerSecond, + MillivoltPerHour, + MillivoltPerMicrosecond, + MillivoltPerMinute, + MillivoltPerSecond, + VoltPerHour, + VoltPerMicrosecond, + VoltPerMinute, + VoltPerSecond, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs new file mode 100644 index 0000000000..9dbe58e823 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -0,0 +1,1173 @@ +//------------------------------------------------------------------------------ +// +// 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.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// ElectricPotential change rate is the ratio of the electric potential change to the time during which the change occurred (value of electric potential changes per unit time). + /// + public partial struct ElectricPotentialChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricPotentialChangeRateUnit? _unit; + + static ElectricPotentialChangeRate() + { + BaseDimensions = new BaseDimensions(2, 1, -4, -1, 0, 0, 0); + + Info = new QuantityInfo(QuantityType.ElectricPotentialChangeRate, + new UnitInfo[] { + new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerHour, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerMinute, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerSecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerHour, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerMinute, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerSecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerHour, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerHour, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerMinute, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerSecond, BaseUnits.Undefined), + new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerHour, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere)), + new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere)), + new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerMinute, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere)), + new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerSecond, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// 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. + /// If value is NaN or Infinity. + public ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit unit) + { + if(unit == ElectricPotentialChangeRateUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to construct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) + { + if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of ElectricPotentialChangeRate, which is VoltPerSecond. All conversions go via this value. + /// + public static ElectricPotentialChangeRateUnit BaseUnit { get; } = ElectricPotentialChangeRateUnit.VoltPerSecond; + + /// + /// Represents the largest possible value of ElectricPotentialChangeRate + /// + public static ElectricPotentialChangeRate MaxValue { get; } = new ElectricPotentialChangeRate(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricPotentialChangeRate + /// + public static ElectricPotentialChangeRate MinValue { get; } = new ElectricPotentialChangeRate(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.ElectricPotentialChangeRate; + + /// + /// All units of measurement for the ElectricPotentialChangeRate quantity. + /// + public static ElectricPotentialChangeRateUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialChangeRateUnit)).Cast().Except(new ElectricPotentialChangeRateUnit[]{ ElectricPotentialChangeRateUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerSecond. + /// + public static ElectricPotentialChangeRate Zero { get; } = new ElectricPotentialChangeRate(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public ElectricPotentialChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => ElectricPotentialChangeRate.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricPotentialChangeRate.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerHours. + /// + public double KilovoltsPerHours => As(ElectricPotentialChangeRateUnit.KilovoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerMicroseconds. + /// + public double KilovoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerMinutes. + /// + public double KilovoltsPerMinutes => As(ElectricPotentialChangeRateUnit.KilovoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in KilovoltsPerSeconds. + /// + public double KilovoltsPerSeconds => As(ElectricPotentialChangeRateUnit.KilovoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerHours. + /// + public double MegavoltsPerHours => As(ElectricPotentialChangeRateUnit.MegavoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerMicroseconds. + /// + public double MegavoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerMinutes. + /// + public double MegavoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MegavoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MegavoltsPerSeconds. + /// + public double MegavoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MegavoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerHours. + /// + public double MicrovoltsPerHours => As(ElectricPotentialChangeRateUnit.MicrovoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerMicroseconds. + /// + public double MicrovoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerMinutes. + /// + public double MicrovoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MicrovoltsPerSeconds. + /// + public double MicrovoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerHours. + /// + public double MillivoltsPerHours => As(ElectricPotentialChangeRateUnit.MillivoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerMicroseconds. + /// + public double MillivoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerMinutes. + /// + public double MillivoltsPerMinutes => As(ElectricPotentialChangeRateUnit.MillivoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in MillivoltsPerSeconds. + /// + public double MillivoltsPerSeconds => As(ElectricPotentialChangeRateUnit.MillivoltPerSecond); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerHours. + /// + public double VoltsPerHours => As(ElectricPotentialChangeRateUnit.VoltPerHour); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerMicroseconds. + /// + public double VoltsPerMicroseconds => As(ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerMinutes. + /// + public double VoltsPerMinutes => As(ElectricPotentialChangeRateUnit.VoltPerMinute); + + /// + /// Get ElectricPotentialChangeRate in VoltsPerSeconds. + /// + public double VoltsPerSeconds => As(ElectricPotentialChangeRateUnit.VoltPerSecond); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricPotentialChangeRateUnit 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(ElectricPotentialChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerHours. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromKilovoltsPerHours(QuantityValue kilovoltsperhours) + { + double value = (double) kilovoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromKilovoltsPerMicroseconds(QuantityValue kilovoltspermicroseconds) + { + double value = (double) kilovoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerMinutes. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromKilovoltsPerMinutes(QuantityValue kilovoltsperminutes) + { + double value = (double) kilovoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from KilovoltsPerSeconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromKilovoltsPerSeconds(QuantityValue kilovoltsperseconds) + { + double value = (double) kilovoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.KilovoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerHours. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMegavoltsPerHours(QuantityValue megavoltsperhours) + { + double value = (double) megavoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMegavoltsPerMicroseconds(QuantityValue megavoltspermicroseconds) + { + double value = (double) megavoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerMinutes. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMegavoltsPerMinutes(QuantityValue megavoltsperminutes) + { + double value = (double) megavoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MegavoltsPerSeconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMegavoltsPerSeconds(QuantityValue megavoltsperseconds) + { + double value = (double) megavoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MegavoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerHours. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMicrovoltsPerHours(QuantityValue microvoltsperhours) + { + double value = (double) microvoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMicrovoltsPerMicroseconds(QuantityValue microvoltspermicroseconds) + { + double value = (double) microvoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerMinutes. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMicrovoltsPerMinutes(QuantityValue microvoltsperminutes) + { + double value = (double) microvoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MicrovoltsPerSeconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMicrovoltsPerSeconds(QuantityValue microvoltsperseconds) + { + double value = (double) microvoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MicrovoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerHours. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMillivoltsPerHours(QuantityValue millivoltsperhours) + { + double value = (double) millivoltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMillivoltsPerMicroseconds(QuantityValue millivoltspermicroseconds) + { + double value = (double) millivoltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerMinutes. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMillivoltsPerMinutes(QuantityValue millivoltsperminutes) + { + double value = (double) millivoltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from MillivoltsPerSeconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromMillivoltsPerSeconds(QuantityValue millivoltsperseconds) + { + double value = (double) millivoltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.MillivoltPerSecond); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerHours. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromVoltsPerHours(QuantityValue voltsperhours) + { + double value = (double) voltsperhours; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerHour); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerMicroseconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromVoltsPerMicroseconds(QuantityValue voltspermicroseconds) + { + double value = (double) voltspermicroseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerMicrosecond); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerMinutes. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromVoltsPerMinutes(QuantityValue voltsperminutes) + { + double value = (double) voltsperminutes; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerMinute); + } + /// + /// Get ElectricPotentialChangeRate from VoltsPerSeconds. + /// + /// If value is NaN or Infinity. + public static ElectricPotentialChangeRate FromVoltsPerSeconds(QuantityValue voltsperseconds) + { + double value = (double) voltsperseconds; + return new ElectricPotentialChangeRate(value, ElectricPotentialChangeRateUnit.VoltPerSecond); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricPotentialChangeRate unit value. + public static ElectricPotentialChangeRate From(QuantityValue value, ElectricPotentialChangeRateUnit fromUnit) + { + return new ElectricPotentialChangeRate((double)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", new CultureInfo("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 ElectricPotentialChangeRate 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", new CultureInfo("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 ElectricPotentialChangeRate Parse(string str, [CanBeNull] 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", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out ElectricPotentialChangeRate 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", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialChangeRate 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", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricPotentialChangeRateUnit 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 number and unit. Defaults to if null. + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricPotentialChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out ElectricPotentialChangeRateUnit 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", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricPotentialChangeRateUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricPotentialChangeRate operator -(ElectricPotentialChangeRate right) + { + return new ElectricPotentialChangeRate(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricPotentialChangeRate operator +(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return new ElectricPotentialChangeRate(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static ElectricPotentialChangeRate operator -(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return new ElectricPotentialChangeRate(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static ElectricPotentialChangeRate operator *(double left, ElectricPotentialChangeRate right) + { + return new ElectricPotentialChangeRate(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricPotentialChangeRate operator *(ElectricPotentialChangeRate left, double right) + { + return new ElectricPotentialChangeRate(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricPotentialChangeRate operator /(ElectricPotentialChangeRate left, double right) + { + return new ElectricPotentialChangeRate(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.VoltsPerSeconds / right.VoltsPerSeconds; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is ElectricPotentialChangeRate objElectricPotentialChangeRate)) throw new ArgumentException("Expected type ElectricPotentialChangeRate.", nameof(obj)); + + return CompareTo(objElectricPotentialChangeRate); + } + + /// + public int CompareTo(ElectricPotentialChangeRate other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is ElectricPotentialChangeRate objElectricPotentialChangeRate)) + return false; + + return Equals(objElectricPotentialChangeRate); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(ElectricPotentialChangeRate other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another ElectricPotentialChangeRate within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.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(ElectricPotentialChangeRate other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current ElectricPotentialChangeRate. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricPotentialChangeRateUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialChangeRateUnit unitAsElectricPotentialChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricPotentialChangeRateUnit); + } + + /// + /// Converts this ElectricPotentialChangeRate to another ElectricPotentialChangeRate with the unit representation . + /// + /// A ElectricPotentialChangeRate with the specified unit. + public ElectricPotentialChangeRate ToUnit(ElectricPotentialChangeRateUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricPotentialChangeRate(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricPotentialChangeRateUnit unitAsElectricPotentialChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsElectricPotentialChangeRateUnit); + } + + /// + public ElectricPotentialChangeRate ToUnit(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(ElectricPotentialChangeRateUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case ElectricPotentialChangeRateUnit.KilovoltPerHour: return (_value/3600) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond: return (_value*1E6) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMinute: return (_value/60) * 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerSecond: return (_value) * 1e3d; + case ElectricPotentialChangeRateUnit.MegavoltPerHour: return (_value/3600) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond: return (_value*1E6) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMinute: return (_value/60) * 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerSecond: return (_value) * 1e6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerHour: return (_value/3600) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond: return (_value*1E6) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMinute: return (_value/60) * 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerSecond: return (_value) * 1e-6d; + case ElectricPotentialChangeRateUnit.MillivoltPerHour: return (_value/3600) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond: return (_value*1E6) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMinute: return (_value/60) * 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerSecond: return (_value) * 1e-3d; + case ElectricPotentialChangeRateUnit.VoltPerHour: return _value/3600; + case ElectricPotentialChangeRateUnit.VoltPerMicrosecond: return _value*1E6; + case ElectricPotentialChangeRateUnit.VoltPerMinute: return _value/60; + case ElectricPotentialChangeRateUnit.VoltPerSecond: return _value; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + internal ElectricPotentialChangeRate ToBaseUnit() + { + var baseUnitValue = GetValueInBaseUnit(); + return new ElectricPotentialChangeRate(baseUnitValue, BaseUnit); + } + + private double GetValueAs(ElectricPotentialChangeRateUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case ElectricPotentialChangeRateUnit.KilovoltPerHour: return (baseUnitValue*3600) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond: return (baseUnitValue/1E6) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerMinute: return (baseUnitValue*60) / 1e3d; + case ElectricPotentialChangeRateUnit.KilovoltPerSecond: return (baseUnitValue) / 1e3d; + case ElectricPotentialChangeRateUnit.MegavoltPerHour: return (baseUnitValue*3600) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond: return (baseUnitValue/1E6) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerMinute: return (baseUnitValue*60) / 1e6d; + case ElectricPotentialChangeRateUnit.MegavoltPerSecond: return (baseUnitValue) / 1e6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerHour: return (baseUnitValue*3600) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond: return (baseUnitValue/1E6) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerMinute: return (baseUnitValue*60) / 1e-6d; + case ElectricPotentialChangeRateUnit.MicrovoltPerSecond: return (baseUnitValue) / 1e-6d; + case ElectricPotentialChangeRateUnit.MillivoltPerHour: return (baseUnitValue*3600) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond: return (baseUnitValue/1E6) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerMinute: return (baseUnitValue*60) / 1e-3d; + case ElectricPotentialChangeRateUnit.MillivoltPerSecond: return (baseUnitValue) / 1e-3d; + case ElectricPotentialChangeRateUnit.VoltPerHour: return baseUnitValue*3600; + case ElectricPotentialChangeRateUnit.VoltPerMicrosecond: return baseUnitValue/1E6; + case ElectricPotentialChangeRateUnit.VoltPerMinute: return baseUnitValue*60; + case ElectricPotentialChangeRateUnit.VoltPerSecond: return baseUnitValue; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] IFormatProvider provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricPotentialChangeRate)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricPotentialChangeRate)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricPotentialChangeRate)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(ElectricPotentialChangeRate)) + return this; + else if(conversionType == typeof(ElectricPotentialChangeRateUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return ElectricPotentialChangeRate.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return ElectricPotentialChangeRate.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricPotentialChangeRate)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index ec6b01b431..f1d8016b23 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -96,6 +96,8 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return ElectricPotential.From(value, ElectricPotential.BaseUnit); case QuantityType.ElectricPotentialAc: return ElectricPotentialAc.From(value, ElectricPotentialAc.BaseUnit); + case QuantityType.ElectricPotentialChangeRate: + return ElectricPotentialChangeRate.From(value, ElectricPotentialChangeRate.BaseUnit); case QuantityType.ElectricPotentialDc: return ElectricPotentialDc.From(value, ElectricPotentialDc.BaseUnit); case QuantityType.ElectricResistance: @@ -338,6 +340,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit case ElectricPotentialAcUnit electricPotentialAcUnit: quantity = ElectricPotentialAc.From(value, electricPotentialAcUnit); return true; + case ElectricPotentialChangeRateUnit electricPotentialChangeRateUnit: + quantity = ElectricPotentialChangeRate.From(value, electricPotentialChangeRateUnit); + return true; case ElectricPotentialDcUnit electricPotentialDcUnit: quantity = ElectricPotentialDc.From(value, electricPotentialDcUnit); return true; @@ -634,6 +639,8 @@ public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type qua return parser.TryParse(quantityString, formatProvider, ElectricPotential.From, out quantity); case Type _ when quantityType == typeof(ElectricPotentialAc): return parser.TryParse(quantityString, formatProvider, ElectricPotentialAc.From, out quantity); + case Type _ when quantityType == typeof(ElectricPotentialChangeRate): + return parser.TryParse(quantityString, formatProvider, ElectricPotentialChangeRate.From, out quantity); case Type _ when quantityType == typeof(ElectricPotentialDc): return parser.TryParse(quantityString, formatProvider, ElectricPotentialDc.From, out quantity); case Type _ when quantityType == typeof(ElectricResistance): diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 4c151b7c9e..b3f1f342fe 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -59,6 +59,7 @@ public enum QuantityType ElectricInductance, ElectricPotential, ElectricPotentialAc, + ElectricPotentialChangeRate, ElectricPotentialDc, ElectricResistance, ElectricResistivity, diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index ba4dad859a..51f54bad4a 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -285,6 +285,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.MicrovoltAc, new string[]{"µVac"}), ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.MillivoltAc, new string[]{"mVac"}), ("en-US", typeof(ElectricPotentialAcUnit), (int)ElectricPotentialAcUnit.VoltAc, new string[]{"Vac"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerHour, new string[]{"kV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, new string[]{"kV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerMinute, new string[]{"kV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.KilovoltPerSecond, new string[]{"kV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerHour, new string[]{"MV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, new string[]{"MV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerMinute, new string[]{"MV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MegavoltPerSecond, new string[]{"MV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerHour, new string[]{"µV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, new string[]{"µV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerMinute, new string[]{"µV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MicrovoltPerSecond, new string[]{"µV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerHour, new string[]{"mV/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, new string[]{"mV/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerMinute, new string[]{"mV/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.MillivoltPerSecond, new string[]{"mV/s"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerHour, new string[]{"V/h"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerMicrosecond, new string[]{"V/μs"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerMinute, new string[]{"V/min"}), + ("en-US", typeof(ElectricPotentialChangeRateUnit), (int)ElectricPotentialChangeRateUnit.VoltPerSecond, new string[]{"V/s"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.KilovoltDc, new string[]{"kVdc"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.MegavoltDc, new string[]{"MVdc"}), ("en-US", typeof(ElectricPotentialDcUnit), (int)ElectricPotentialDcUnit.MicrovoltDc, new string[]{"µVdc"}), diff --git a/UnitsNet/GeneratedCode/UnitConverter.g.cs b/UnitsNet/GeneratedCode/UnitConverter.g.cs index dc42fe5d81..0e25bab244 100644 --- a/UnitsNet/GeneratedCode/UnitConverter.g.cs +++ b/UnitsNet/GeneratedCode/UnitConverter.g.cs @@ -434,6 +434,45 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(ElectricPotentialAc.BaseUnit, ElectricPotentialAcUnit.MillivoltAc, q => q.ToUnit(ElectricPotentialAcUnit.MillivoltAc)); unitConverter.SetConversionFunction(ElectricPotentialAcUnit.MillivoltAc, ElectricPotentialAc.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(ElectricPotentialAc.BaseUnit, ElectricPotentialAc.BaseUnit, q => q); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.KilovoltPerHour, q => q.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerHour)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.KilovoltPerHour, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.KilovoltPerMinute, q => q.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerMinute)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.KilovoltPerMinute, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.KilovoltPerSecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.KilovoltPerSecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.KilovoltPerSecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MegavoltPerHour, q => q.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerHour)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MegavoltPerHour, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MegavoltPerMinute, q => q.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerMinute)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MegavoltPerMinute, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MegavoltPerSecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MegavoltPerSecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MegavoltPerSecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MicrovoltPerHour, q => q.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerHour)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MicrovoltPerHour, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MicrovoltPerMinute, q => q.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerMinute)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MicrovoltPerSecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MicrovoltPerSecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MillivoltPerHour, q => q.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerHour)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MillivoltPerHour, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MillivoltPerMinute, q => q.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerMinute)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MillivoltPerMinute, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.MillivoltPerSecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.MillivoltPerSecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.MillivoltPerSecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.VoltPerHour, q => q.ToUnit(ElectricPotentialChangeRateUnit.VoltPerHour)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.VoltPerHour, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.VoltPerMicrosecond, q => q.ToUnit(ElectricPotentialChangeRateUnit.VoltPerMicrosecond)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRateUnit.VoltPerMinute, q => q.ToUnit(ElectricPotentialChangeRateUnit.VoltPerMinute)); + unitConverter.SetConversionFunction(ElectricPotentialChangeRateUnit.VoltPerMinute, ElectricPotentialChangeRate.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(ElectricPotentialChangeRate.BaseUnit, ElectricPotentialChangeRate.BaseUnit, q => q); unitConverter.SetConversionFunction(ElectricPotentialDc.BaseUnit, ElectricPotentialDcUnit.KilovoltDc, q => q.ToUnit(ElectricPotentialDcUnit.KilovoltDc)); unitConverter.SetConversionFunction(ElectricPotentialDcUnit.KilovoltDc, ElectricPotentialDc.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(ElectricPotentialDc.BaseUnit, ElectricPotentialDcUnit.MegavoltDc, q => q.ToUnit(ElectricPotentialDcUnit.MegavoltDc)); diff --git a/UnitsNet/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs new file mode 100644 index 0000000000..61b66535e6 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricPotentialChangeRateUnit.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricPotentialChangeRateUnit + { + Undefined = 0, + KilovoltPerHour, + KilovoltPerMicrosecond, + KilovoltPerMinute, + KilovoltPerSecond, + MegavoltPerHour, + MegavoltPerMicrosecond, + MegavoltPerMinute, + MegavoltPerSecond, + MicrovoltPerHour, + MicrovoltPerMicrosecond, + MicrovoltPerMinute, + MicrovoltPerSecond, + MillivoltPerHour, + MillivoltPerMicrosecond, + MillivoltPerMinute, + MillivoltPerSecond, + VoltPerHour, + VoltPerMicrosecond, + VoltPerMinute, + VoltPerSecond, + } + + #pragma warning restore 1591 +} From 6c21b5a81ffcb5d94136f0ccbcc48f9f6a139d44 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Wed, 4 Mar 2020 21:17:02 +0100 Subject: [PATCH 2/2] Use consistent scientific notation in test values --- .../ElectricPotentialChangeRateTests.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs index c4e756e241..8dbc073ccd 100644 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs @@ -24,23 +24,23 @@ namespace UnitsNet.Tests.CustomCode public class ElectricPotentialChangeRateTests : ElectricPotentialChangeRateTestsBase { protected override double KilovoltsPerHoursInOneVoltPerSecond => 3.6; - protected override double KilovoltsPerMicrosecondsInOneVoltPerSecond => 1E-09; - protected override double KilovoltsPerMinutesInOneVoltPerSecond => 6E-2; + protected override double KilovoltsPerMicrosecondsInOneVoltPerSecond => 1e-09; + protected override double KilovoltsPerMinutesInOneVoltPerSecond => 6e-2; protected override double KilovoltsPerSecondsInOneVoltPerSecond => 0.001; - protected override double MegavoltsPerHoursInOneVoltPerSecond => 36E-4; - protected override double MegavoltsPerMicrosecondsInOneVoltPerSecond => 1E-12; - protected override double MegavoltsPerMinutesInOneVoltPerSecond => 6E-05; - protected override double MegavoltsPerSecondsInOneVoltPerSecond => 1E-06; - protected override double MicrovoltsPerHoursInOneVoltPerSecond => 36E8; + protected override double MegavoltsPerHoursInOneVoltPerSecond => 3.6e-3; + protected override double MegavoltsPerMicrosecondsInOneVoltPerSecond => 1e-12; + protected override double MegavoltsPerMinutesInOneVoltPerSecond => 6e-05; + protected override double MegavoltsPerSecondsInOneVoltPerSecond => 1e-06; + protected override double MicrovoltsPerHoursInOneVoltPerSecond => 3.6e9; protected override double MicrovoltsPerMicrosecondsInOneVoltPerSecond => 1; - protected override double MicrovoltsPerMinutesInOneVoltPerSecond => 6E7; - protected override double MicrovoltsPerSecondsInOneVoltPerSecond => 1E6; - protected override double MillivoltsPerHoursInOneVoltPerSecond => 36E5; + protected override double MicrovoltsPerMinutesInOneVoltPerSecond => 6e7; + protected override double MicrovoltsPerSecondsInOneVoltPerSecond => 1e6; + protected override double MillivoltsPerHoursInOneVoltPerSecond => 3.6e6; protected override double MillivoltsPerMicrosecondsInOneVoltPerSecond => 0.001; - protected override double MillivoltsPerMinutesInOneVoltPerSecond => 6E4; + protected override double MillivoltsPerMinutesInOneVoltPerSecond => 6e4; protected override double MillivoltsPerSecondsInOneVoltPerSecond => 1000; protected override double VoltsPerHoursInOneVoltPerSecond => 3600; - protected override double VoltsPerMicrosecondsInOneVoltPerSecond => 1E-06; + protected override double VoltsPerMicrosecondsInOneVoltPerSecond => 1e-06; protected override double VoltsPerMinutesInOneVoltPerSecond => 60; protected override double VoltsPerSecondsInOneVoltPerSecond => 1; }