From e812dd91353e8bac33f1acf7b4668000f7b79e4a Mon Sep 17 00:00:00 2001 From: Chef904 Date: Thu, 29 Aug 2024 15:09:01 +0200 Subject: [PATCH 1/7] chore: Add EnergyEfficiency units and definitions --- .DS_Store | Bin 0 -> 6148 bytes Common/.DS_Store | Bin 0 -> 6148 bytes Common/UnitDefinitions/EnergyEfficiency.json | 42 + Common/UnitEnumValues.g.json | 20 + .../EnergyEfficiency/EnergyEfficiency.nfproj | 42 + ...sNet.NanoFramework.EnergyEfficiency.nuspec | 26 + .../EnergyEfficiency/packages.config | 4 + .../Quantities/EnergyEfficiency.g.cs | 380 +++++ .../Units/EnergyEfficiencyUnit.g.cs | 49 + .../GeneratedCode/UnitsNet.nanoFramework.sln | 8 + ...umberToEnergyEfficiencyExtensionsTest.g.cs | 100 ++ .../NumberToEnergyEfficiencyExtensions.g.cs | 180 +++ .../CustomCode/EnergyEfficiencyTests.cs | 28 + .../GeneratedCode/IQuantityTests.g.cs | 3 + .../TestsBase/EnergyEfficiencyTestsBase.g.cs | 1218 ++++++++++++++++ UnitsNet/.DS_Store | Bin 0 -> 6148 bytes .../Quantities/EnergyEfficiency.g.cs | 1272 +++++++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 5 + .../Resources/EnergyEfficiency.restext | 18 + .../Units/EnergyEfficiencyUnit.g.cs | 49 + 20 files changed, 3444 insertions(+) create mode 100644 .DS_Store create mode 100644 Common/.DS_Store create mode 100644 Common/UnitDefinitions/EnergyEfficiency.json create mode 100644 UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj create mode 100644 UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec create mode 100644 UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs create mode 100644 UnitsNet/.DS_Store create mode 100644 UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs create mode 100644 UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext create mode 100644 UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b99db7d0ef16290d7bf4aeb85ae500e1ca33ac17 GIT binary patch literal 6148 zcmeHKyG{c^3>-s*BGIIz++W}iRw1-Bh#o;GkV39V=&$0t_%y~3A)*Tf1r3ZNdv<-E zUELJt7=SHb*O$Noz?|-gHxEF{(We4$6h!l z#;1cJMgZcB=`gNimLN7y5PRX6$PCSrN=&NNh+#=*zExc>921ici<@~)-E1|XSlrHh zi*i^`RFncz;820n+%CNTU(>&t{|`ypNdYPFrxdW+>UOo{D^+iuyqx#iM!%!2`1J0?au=EmFcMHFRS^EIFM!Z9)E%m0wXR|QTzhxC;NedYbk=I8KWx(;#Nc= zfiadr0Xn;NacWL16JO6S!x?I{r@=UV3Su3=^DTIaqcm%^-esX!T3IavweppJug8AY z&qisdKfIt{CtAnBtlkgKqQSUV-#FAs){m0G&;&%`04|s3Q4;ELM~{*)HLXXLcc;^8rLnbraNK){9~1pzb(Z)94b~jb=oOVYTMW~iIKYx= zh&is${xFGkatF`ZgtLj5Spimn6<8Jp-2GLlEz5#=ovZ*WurLMaeo!!C&v9a&v9E<=%Kc8sr# zyO5q`E?EIq;JX5p`vG-&|BwF8|BVwDtN<(UKNXOruHWroZ|-gVu}gYu73>;DAiv!5 lX9z0hDTXgS#hWk#v@5EBJ;%9av;h1^z{tP_E3i-nJ^*%`T37%8 literal 0 HcmV?d00001 diff --git a/Common/UnitDefinitions/EnergyEfficiency.json b/Common/UnitDefinitions/EnergyEfficiency.json new file mode 100644 index 0000000000..0967cd7c57 --- /dev/null +++ b/Common/UnitDefinitions/EnergyEfficiency.json @@ -0,0 +1,42 @@ +{ + "Name": "EnergyEfficiency", + "BaseUnit": "WattHourPerKilometer", + "XmlDocSummary": "", + "BaseDimensions": { + "Wh/km": 1 + }, + "Units": [ + { + "SingularName": "WattHourPerKilometer", + "PluralName": "WattHoursPerKilometer", + "BaseUnits": { + "Wh/km": "WattHourPerKilometer" + }, + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Wh/km" ] + } + ] + }, + { + "SingularName": "WattHourPerMeter", + "PluralName": "WattHoursPerMeter", + "BaseUnits": { + "Wh/km": "WattHourPerMeter" + }, + "FromUnitToBaseFunc": "{x} / 1e3", + "FromBaseToUnitFunc": "{x} * 1e3", + "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Wh/m" ] + } + ] + } + ] +} diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index e58a8e2198..bb2bab3486 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1862,5 +1862,25 @@ "Sievert": 9, "Kilosievert": 3, "Megasievert": 6 + }, + "EnergyEfficiency": { + "FemtowattHourPerKilometer": 7, + "FemtowattHourPerMeter": 9, + "GigawattHourPerKilometer": 10, + "GigawattHourPerMeter": 2, + "KilowattHourPerKilometer": 5, + "KilowattHourPerMeter": 3, + "MegawattHourPerKilometer": 1, + "MegawattHourPerMeter": 6, + "MicrowattHourPerKilometer": 4, + "MicrowattHourPerMeter": 8, + "MilliwattHourPerKilometer": 12, + "MilliwattHourPerMeter": 15, + "NanowattHourPerKilometer": 11, + "NanowattHourPerMeter": 16, + "PicowattHourPerKilometer": 14, + "PicowattHourPerMeter": 19, + "WattHourPerKilometer": 13, + "WattHourPerMeter": 20 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj new file mode 100644 index 0000000000..5d33ce3268 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {31f3d11e-76d2-1914-ebad-28e0cb77326b} + Library + Properties + 512 + UnitsNet + UnitsNet.EnergyEfficiency + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec new file mode 100644 index 0000000000..d7a09bc51b --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.EnergyEfficiency + 5.57.0 + Units.NET EnergyEfficiency - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds EnergyEfficiency units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. + https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png + + + Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). + en-US + nanoframework energyefficiency unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs new file mode 100644 index 0000000000..5ff1658afb --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -0,0 +1,380 @@ +//------------------------------------------------------------------------------ +// +// 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 UnitsNet.Units; + +namespace UnitsNet +{ + /// + /// + /// + /// + public struct EnergyEfficiency + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly EnergyEfficiencyUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public EnergyEfficiencyUnit Unit => _unit; + + /// + /// 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 EnergyEfficiency(double value, EnergyEfficiencyUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of EnergyEfficiency, which is Second. All conversions go via this value. + /// + public static EnergyEfficiencyUnit BaseUnit { get; } = EnergyEfficiencyUnit.WattHourPerKilometer; + + /// + /// Represents the largest possible value of EnergyEfficiency. + /// + public static EnergyEfficiency MaxValue { get; } = new EnergyEfficiency(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of EnergyEfficiency. + /// + public static EnergyEfficiency MinValue { get; } = new EnergyEfficiency(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static EnergyEfficiency Zero { get; } = new EnergyEfficiency(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double FemtowattHoursPerKilometer => As(EnergyEfficiencyUnit.FemtowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double FemtowattHoursPerMeter => As(EnergyEfficiencyUnit.FemtowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double GigawattHoursPerKilometer => As(EnergyEfficiencyUnit.GigawattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double GigawattHoursPerMeter => As(EnergyEfficiencyUnit.GigawattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerKilometer => As(EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MegawattHoursPerKilometer => As(EnergyEfficiencyUnit.MegawattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MegawattHoursPerMeter => As(EnergyEfficiencyUnit.MegawattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrowattHoursPerKilometer => As(EnergyEfficiencyUnit.MicrowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrowattHoursPerMeter => As(EnergyEfficiencyUnit.MicrowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MilliwattHoursPerKilometer => As(EnergyEfficiencyUnit.MilliwattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MilliwattHoursPerMeter => As(EnergyEfficiencyUnit.MilliwattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double NanowattHoursPerKilometer => As(EnergyEfficiencyUnit.NanowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double NanowattHoursPerMeter => As(EnergyEfficiencyUnit.NanowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double PicowattHoursPerKilometer => As(EnergyEfficiencyUnit.PicowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double PicowattHoursPerMeter => As(EnergyEfficiencyUnit.PicowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerKilometer => As(EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerMeter => As(EnergyEfficiencyUnit.WattHourPerMeter); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromFemtowattHoursPerKilometer(double femtowatthoursperkilometer) => new EnergyEfficiency(femtowatthoursperkilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromFemtowattHoursPerMeter(double femtowatthourspermeter) => new EnergyEfficiency(femtowatthourspermeter, EnergyEfficiencyUnit.FemtowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromGigawattHoursPerKilometer(double gigawatthoursperkilometer) => new EnergyEfficiency(gigawatthoursperkilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromGigawattHoursPerMeter(double gigawatthourspermeter) => new EnergyEfficiency(gigawatthourspermeter, EnergyEfficiencyUnit.GigawattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerKilometer(double kilowatthoursperkilometer) => new EnergyEfficiency(kilowatthoursperkilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerMeter(double kilowatthourspermeter) => new EnergyEfficiency(kilowatthourspermeter, EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMegawattHoursPerKilometer(double megawatthoursperkilometer) => new EnergyEfficiency(megawatthoursperkilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMegawattHoursPerMeter(double megawatthourspermeter) => new EnergyEfficiency(megawatthourspermeter, EnergyEfficiencyUnit.MegawattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMicrowattHoursPerKilometer(double microwatthoursperkilometer) => new EnergyEfficiency(microwatthoursperkilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMicrowattHoursPerMeter(double microwatthourspermeter) => new EnergyEfficiency(microwatthourspermeter, EnergyEfficiencyUnit.MicrowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMilliwattHoursPerKilometer(double milliwatthoursperkilometer) => new EnergyEfficiency(milliwatthoursperkilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMilliwattHoursPerMeter(double milliwatthourspermeter) => new EnergyEfficiency(milliwatthourspermeter, EnergyEfficiencyUnit.MilliwattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromNanowattHoursPerKilometer(double nanowatthoursperkilometer) => new EnergyEfficiency(nanowatthoursperkilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromNanowattHoursPerMeter(double nanowatthourspermeter) => new EnergyEfficiency(nanowatthourspermeter, EnergyEfficiencyUnit.NanowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromPicowattHoursPerKilometer(double picowatthoursperkilometer) => new EnergyEfficiency(picowatthoursperkilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromPicowattHoursPerMeter(double picowatthourspermeter) => new EnergyEfficiency(picowatthourspermeter, EnergyEfficiencyUnit.PicowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerKilometer(double watthoursperkilometer) => new EnergyEfficiency(watthoursperkilometer, EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerMeter(double watthourspermeter) => new EnergyEfficiency(watthourspermeter, EnergyEfficiencyUnit.WattHourPerMeter); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// EnergyEfficiency unit value. + public static EnergyEfficiency From(double value, EnergyEfficiencyUnit fromUnit) + { + return new EnergyEfficiency(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(EnergyEfficiencyUnit unit) => GetValueAs(unit); + + /// + /// Converts this EnergyEfficiency to another EnergyEfficiency with the unit representation . + /// + /// A EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit unit) + { + var convertedValue = GetValueAs(unit); + return new EnergyEfficiency(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 GetValueInBaseUnit() + { + return Unit switch + { + EnergyEfficiencyUnit.FemtowattHourPerKilometer => (_value) * 1e-15d, + EnergyEfficiencyUnit.FemtowattHourPerMeter => (_value / 1e3) * 1e-15d, + EnergyEfficiencyUnit.GigawattHourPerKilometer => (_value) * 1e9d, + EnergyEfficiencyUnit.GigawattHourPerMeter => (_value / 1e3) * 1e9d, + EnergyEfficiencyUnit.KilowattHourPerKilometer => (_value) * 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (_value / 1e3) * 1e3d, + EnergyEfficiencyUnit.MegawattHourPerKilometer => (_value) * 1e6d, + EnergyEfficiencyUnit.MegawattHourPerMeter => (_value / 1e3) * 1e6d, + EnergyEfficiencyUnit.MicrowattHourPerKilometer => (_value) * 1e-6d, + EnergyEfficiencyUnit.MicrowattHourPerMeter => (_value / 1e3) * 1e-6d, + EnergyEfficiencyUnit.MilliwattHourPerKilometer => (_value) * 1e-3d, + EnergyEfficiencyUnit.MilliwattHourPerMeter => (_value / 1e3) * 1e-3d, + EnergyEfficiencyUnit.NanowattHourPerKilometer => (_value) * 1e-9d, + EnergyEfficiencyUnit.NanowattHourPerMeter => (_value / 1e3) * 1e-9d, + EnergyEfficiencyUnit.PicowattHourPerKilometer => (_value) * 1e-12d, + EnergyEfficiencyUnit.PicowattHourPerMeter => (_value / 1e3) * 1e-12d, + EnergyEfficiencyUnit.WattHourPerKilometer => _value, + EnergyEfficiencyUnit.WattHourPerMeter => _value / 1e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(EnergyEfficiencyUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + EnergyEfficiencyUnit.FemtowattHourPerKilometer => (baseUnitValue) / 1e-15d, + EnergyEfficiencyUnit.FemtowattHourPerMeter => (baseUnitValue * 1e3) / 1e-15d, + EnergyEfficiencyUnit.GigawattHourPerKilometer => (baseUnitValue) / 1e9d, + EnergyEfficiencyUnit.GigawattHourPerMeter => (baseUnitValue * 1e3) / 1e9d, + EnergyEfficiencyUnit.KilowattHourPerKilometer => (baseUnitValue) / 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (baseUnitValue * 1e3) / 1e3d, + EnergyEfficiencyUnit.MegawattHourPerKilometer => (baseUnitValue) / 1e6d, + EnergyEfficiencyUnit.MegawattHourPerMeter => (baseUnitValue * 1e3) / 1e6d, + EnergyEfficiencyUnit.MicrowattHourPerKilometer => (baseUnitValue) / 1e-6d, + EnergyEfficiencyUnit.MicrowattHourPerMeter => (baseUnitValue * 1e3) / 1e-6d, + EnergyEfficiencyUnit.MilliwattHourPerKilometer => (baseUnitValue) / 1e-3d, + EnergyEfficiencyUnit.MilliwattHourPerMeter => (baseUnitValue * 1e3) / 1e-3d, + EnergyEfficiencyUnit.NanowattHourPerKilometer => (baseUnitValue) / 1e-9d, + EnergyEfficiencyUnit.NanowattHourPerMeter => (baseUnitValue * 1e3) / 1e-9d, + EnergyEfficiencyUnit.PicowattHourPerKilometer => (baseUnitValue) / 1e-12d, + EnergyEfficiencyUnit.PicowattHourPerMeter => (baseUnitValue * 1e3) / 1e-12d, + EnergyEfficiencyUnit.WattHourPerKilometer => baseUnitValue, + EnergyEfficiencyUnit.WattHourPerMeter => baseUnitValue * 1e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs new file mode 100644 index 0000000000..6dc17b9e06 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiencyUnit + { + FemtowattHourPerKilometer = 7, + FemtowattHourPerMeter = 9, + GigawattHourPerKilometer = 10, + GigawattHourPerMeter = 2, + KilowattHourPerKilometer = 5, + KilowattHourPerMeter = 3, + MegawattHourPerKilometer = 1, + MegawattHourPerMeter = 6, + MicrowattHourPerKilometer = 4, + MicrowattHourPerMeter = 8, + MilliwattHourPerKilometer = 12, + MilliwattHourPerMeter = 15, + NanowattHourPerKilometer = 11, + NanowattHourPerMeter = 16, + PicowattHourPerKilometer = 14, + PicowattHourPerMeter = 19, + WattHourPerKilometer = 13, + WattHourPerMeter = 20, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index d64098f57d..1f1969a38e 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -76,6 +76,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Energy", "Energy\Energy.nfp EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "EnergyDensity", "EnergyDensity\EnergyDensity.nfproj", "{c5025916-5039-97c2-b450-af1420f5fb08}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "EnergyEfficiency", "EnergyEfficiency\EnergyEfficiency.nfproj", "{31f3d11e-76d2-1914-ebad-28e0cb77326b}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Entropy", "Entropy\Entropy.nfproj", "{816884bb-a5f6-5c07-967b-bb8f21d724b7}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Force", "Force\Force.nfproj", "{5517dacf-b1ff-6515-e5b6-b5081f92f407}" @@ -478,6 +480,12 @@ Global {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.ActiveCfg = Release|Any CPU {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.Build.0 = Release|Any CPU {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.Deploy.0 = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.Build.0 = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.ActiveCfg = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.Build.0 = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.Deploy.0 = Release|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.Build.0 = Debug|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs new file mode 100644 index 0000000000..1060ea6392 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToEnergyEfficiency; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToEnergyEfficiencyExtensionsTests + { + [Fact] + public void NumberToFemtowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromFemtowattHoursPerKilometer(2), 2.FemtowattHoursPerKilometer()); + + [Fact] + public void NumberToFemtowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromFemtowattHoursPerMeter(2), 2.FemtowattHoursPerMeter()); + + [Fact] + public void NumberToGigawattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromGigawattHoursPerKilometer(2), 2.GigawattHoursPerKilometer()); + + [Fact] + public void NumberToGigawattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromGigawattHoursPerMeter(2), 2.GigawattHoursPerMeter()); + + [Fact] + public void NumberToKilowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromKilowattHoursPerKilometer(2), 2.KilowattHoursPerKilometer()); + + [Fact] + public void NumberToKilowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromKilowattHoursPerMeter(2), 2.KilowattHoursPerMeter()); + + [Fact] + public void NumberToMegawattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromMegawattHoursPerKilometer(2), 2.MegawattHoursPerKilometer()); + + [Fact] + public void NumberToMegawattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromMegawattHoursPerMeter(2), 2.MegawattHoursPerMeter()); + + [Fact] + public void NumberToMicrowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromMicrowattHoursPerKilometer(2), 2.MicrowattHoursPerKilometer()); + + [Fact] + public void NumberToMicrowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromMicrowattHoursPerMeter(2), 2.MicrowattHoursPerMeter()); + + [Fact] + public void NumberToMilliwattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromMilliwattHoursPerKilometer(2), 2.MilliwattHoursPerKilometer()); + + [Fact] + public void NumberToMilliwattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromMilliwattHoursPerMeter(2), 2.MilliwattHoursPerMeter()); + + [Fact] + public void NumberToNanowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromNanowattHoursPerKilometer(2), 2.NanowattHoursPerKilometer()); + + [Fact] + public void NumberToNanowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromNanowattHoursPerMeter(2), 2.NanowattHoursPerMeter()); + + [Fact] + public void NumberToPicowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromPicowattHoursPerKilometer(2), 2.PicowattHoursPerKilometer()); + + [Fact] + public void NumberToPicowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromPicowattHoursPerMeter(2), 2.PicowattHoursPerMeter()); + + [Fact] + public void NumberToWattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromWattHoursPerKilometer(2), 2.WattHoursPerKilometer()); + + [Fact] + public void NumberToWattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromWattHoursPerMeter(2), 2.WattHoursPerMeter()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs new file mode 100644 index 0000000000..0c4777a409 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs @@ -0,0 +1,180 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +#if NET7_0_OR_GREATER +using System.Numerics; +#endif + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToEnergyEfficiency +{ + /// + /// A number to EnergyEfficiency Extensions + /// + public static class NumberToEnergyEfficiencyExtensions + { + /// + public static EnergyEfficiency FemtowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromFemtowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency FemtowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromFemtowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency GigawattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromGigawattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency GigawattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromGigawattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency KilowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromKilowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency KilowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromKilowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MegawattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMegawattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MegawattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMegawattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MicrowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMicrowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MicrowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMicrowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MilliwattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMilliwattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency MilliwattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromMilliwattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency NanowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromNanowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency NanowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromNanowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency PicowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromPicowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency PicowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromPicowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency WattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromWattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency WattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromWattHoursPerMeter(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs new file mode 100644 index 0000000000..cf0b53c170 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs @@ -0,0 +1,28 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiencyTests : EnergyEfficiencyTestsBase + { + // Override properties in base class here + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 7dc41682e2..aa6405a08f 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -71,6 +71,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, Quantity.From(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)); Assertion(3, EnergyUnit.WattHour, Quantity.From(3, EnergyUnit.WattHour)); Assertion(3, EnergyDensityUnit.WattHourPerCubicMeter, Quantity.From(3, EnergyDensityUnit.WattHourPerCubicMeter)); + Assertion(3, EnergyEfficiencyUnit.WattHourPerMeter, Quantity.From(3, EnergyEfficiencyUnit.WattHourPerMeter)); Assertion(3, EntropyUnit.MegajoulePerKelvin, Quantity.From(3, EntropyUnit.MegajoulePerKelvin)); Assertion(3, ForceUnit.TonneForce, Quantity.From(3, ForceUnit.TonneForce)); Assertion(3, ForceChangeRateUnit.PoundForcePerSecond, Quantity.From(3, ForceChangeRateUnit.PoundForcePerSecond)); @@ -202,6 +203,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricSurfaceChargeDensity.Info, ElectricSurfaceChargeDensity.Zero); Assertion(Energy.Info, Energy.Zero); Assertion(EnergyDensity.Info, EnergyDensity.Zero); + Assertion(EnergyEfficiency.Info, EnergyEfficiency.Zero); Assertion(Entropy.Info, Entropy.Zero); Assertion(Force.Info, Force.Zero); Assertion(ForceChangeRate.Info, ForceChangeRate.Zero); @@ -333,6 +335,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricSurfaceChargeDensity.BaseDimensions, ElectricSurfaceChargeDensity.Zero); Assertion(Energy.BaseDimensions, Energy.Zero); Assertion(EnergyDensity.BaseDimensions, EnergyDensity.Zero); + Assertion(EnergyEfficiency.BaseDimensions, EnergyEfficiency.Zero); Assertion(Entropy.BaseDimensions, Entropy.Zero); Assertion(Force.BaseDimensions, Force.Zero); Assertion(ForceChangeRate.BaseDimensions, ForceChangeRate.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs new file mode 100644 index 0000000000..51d2ddc637 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs @@ -0,0 +1,1218 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of EnergyEfficiency. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class EnergyEfficiencyTestsBase : QuantityTestsBase + { + protected abstract double FemtowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double FemtowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double GigawattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double GigawattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double KilowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double KilowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double MegawattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double MegawattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double MicrowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double MicrowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double MilliwattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double MilliwattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double NanowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double NanowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double PicowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double PicowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double WattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double WattHoursPerMeterInOneWattHourPerKilometer { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double FemtowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double FemtowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double GigawattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double GigawattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double KilowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double KilowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double MegawattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double MegawattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double MicrowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double MicrowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double MilliwattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double MilliwattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double NanowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double NanowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double PicowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double PicowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double WattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double WattHoursPerMeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(EnergyEfficiencyUnit unit) + { + return unit switch + { + EnergyEfficiencyUnit.FemtowattHourPerKilometer => (FemtowattHoursPerKilometerInOneWattHourPerKilometer, FemtowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.FemtowattHourPerMeter => (FemtowattHoursPerMeterInOneWattHourPerKilometer, FemtowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.GigawattHourPerKilometer => (GigawattHoursPerKilometerInOneWattHourPerKilometer, GigawattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.GigawattHourPerMeter => (GigawattHoursPerMeterInOneWattHourPerKilometer, GigawattHoursPerMeterTolerance), + EnergyEfficiencyUnit.KilowattHourPerKilometer => (KilowattHoursPerKilometerInOneWattHourPerKilometer, KilowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.KilowattHourPerMeter => (KilowattHoursPerMeterInOneWattHourPerKilometer, KilowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.MegawattHourPerKilometer => (MegawattHoursPerKilometerInOneWattHourPerKilometer, MegawattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.MegawattHourPerMeter => (MegawattHoursPerMeterInOneWattHourPerKilometer, MegawattHoursPerMeterTolerance), + EnergyEfficiencyUnit.MicrowattHourPerKilometer => (MicrowattHoursPerKilometerInOneWattHourPerKilometer, MicrowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.MicrowattHourPerMeter => (MicrowattHoursPerMeterInOneWattHourPerKilometer, MicrowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.MilliwattHourPerKilometer => (MilliwattHoursPerKilometerInOneWattHourPerKilometer, MilliwattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.MilliwattHourPerMeter => (MilliwattHoursPerMeterInOneWattHourPerKilometer, MilliwattHoursPerMeterTolerance), + EnergyEfficiencyUnit.NanowattHourPerKilometer => (NanowattHoursPerKilometerInOneWattHourPerKilometer, NanowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.NanowattHourPerMeter => (NanowattHoursPerMeterInOneWattHourPerKilometer, NanowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.PicowattHourPerKilometer => (PicowattHoursPerKilometerInOneWattHourPerKilometer, PicowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.PicowattHourPerMeter => (PicowattHoursPerMeterInOneWattHourPerKilometer, PicowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.WattHourPerKilometer => (WattHoursPerKilometerInOneWattHourPerKilometer, WattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.WattHourPerMeter => (WattHoursPerMeterInOneWattHourPerKilometer, WattHoursPerMeterTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { EnergyEfficiencyUnit.FemtowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.FemtowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.GigawattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.GigawattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.KilowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.KilowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.MegawattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.MegawattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.MicrowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.MicrowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.MilliwattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.MilliwattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.NanowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.NanowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.PicowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.PicowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.WattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.WattHourPerMeter }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new EnergyEfficiency(); + Assert.Equal(0, quantity.Value); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new EnergyEfficiency(double.PositiveInfinity, EnergyEfficiencyUnit.WattHourPerKilometer)); + Assert.Throws(() => new EnergyEfficiency(double.NegativeInfinity, EnergyEfficiencyUnit.WattHourPerKilometer)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new EnergyEfficiency(double.NaN, EnergyEfficiencyUnit.WattHourPerKilometer)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new EnergyEfficiency(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new EnergyEfficiency(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (EnergyEfficiency) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void EnergyEfficiency_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(EnergyEfficiency.Zero, quantityInfo.Zero); + Assert.Equal("EnergyEfficiency", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void WattHourPerKilometerToEnergyEfficiencyUnits() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(FemtowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(FemtowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(GigawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(GigawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MegawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MegawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MicrowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MicrowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MilliwattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MilliwattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); + AssertEx.EqualTolerance(NanowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(NanowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(PicowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(PicowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerMeter, WattHoursPerMeterTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity00.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, quantity00.Unit); + + var quantity01 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.FemtowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity01.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, quantity01.Unit); + + var quantity02 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.GigawattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity02.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, quantity02.Unit); + + var quantity03 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.GigawattHourPerMeter); + AssertEx.EqualTolerance(1, quantity03.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, quantity03.Unit); + + var quantity04 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity04.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity04.Unit); + + var quantity05 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity05.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, quantity05.Unit); + + var quantity06 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MegawattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity06.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, quantity06.Unit); + + var quantity07 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MegawattHourPerMeter); + AssertEx.EqualTolerance(1, quantity07.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, quantity07.Unit); + + var quantity08 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity08.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, quantity08.Unit); + + var quantity09 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MicrowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity09.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, quantity09.Unit); + + var quantity10 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity10.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, quantity10.Unit); + + var quantity11 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MilliwattHourPerMeter); + AssertEx.EqualTolerance(1, quantity11.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, quantity11.Unit); + + var quantity12 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.NanowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity12.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, quantity12.Unit); + + var quantity13 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.NanowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity13.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, quantity13.Unit); + + var quantity14 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.PicowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity14.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, quantity14.Unit); + + var quantity15 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.PicowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity15.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, quantity15.Unit); + + var quantity16 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity16.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity16.Unit); + + var quantity17 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerMeter); + AssertEx.EqualTolerance(1, quantity17.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, quantity17.Unit); + + } + + [Fact] + public void FromWattHoursPerKilometer_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.PositiveInfinity)); + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.NegativeInfinity)); + } + + [Fact] + public void FromWattHoursPerKilometer_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.NaN)); + } + + [Fact] + public void As() + { + var watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(FemtowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.FemtowattHourPerKilometer), FemtowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(FemtowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.FemtowattHourPerMeter), FemtowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(GigawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.GigawattHourPerKilometer), GigawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(GigawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.GigawattHourPerMeter), GigawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerKilometer), KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerMeter), KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MegawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MegawattHourPerKilometer), MegawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MegawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MegawattHourPerMeter), MegawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MicrowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MicrowattHourPerKilometer), MicrowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MicrowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MicrowattHourPerMeter), MicrowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(MilliwattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MilliwattHourPerKilometer), MilliwattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(MilliwattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MilliwattHourPerMeter), MilliwattHoursPerMeterTolerance); + AssertEx.EqualTolerance(NanowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.NanowattHourPerKilometer), NanowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(NanowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.NanowattHourPerMeter), NanowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(PicowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.PicowattHourPerKilometer), PicowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(PicowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.PicowattHourPerMeter), PicowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerKilometer), WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerMeter), WattHoursPerMeterTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new EnergyEfficiency(value: 1, unit: EnergyEfficiency.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = Convert.ToDouble(AsWithSIUnitSystem()); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + + [Fact] + public void Parse() + { + try + { + var parsed = EnergyEfficiency.Parse("1 fWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 fWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 GWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 GWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 kWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 kWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 MWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 MWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 µWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 µWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 mWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 mWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 nWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 nWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 pWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 pWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 Wh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 Wh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(EnergyEfficiency.TryParse("1 fWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 fWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 GWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 GWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 kWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 µWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 µWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 nWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 nWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 pWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 pWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 Wh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("fWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("fWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("GWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("GWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("kWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("MWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("MWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("µWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("µWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("mWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("mWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("nWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("nWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("pWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("pWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("Wh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(EnergyEfficiency.TryParseUnit("fWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("fWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("GWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("GWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("kWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("µWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("µWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("nWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("nWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("pWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("pWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("Wh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(EnergyEfficiencyUnit unit) + { + var inBaseUnits = EnergyEfficiency.From(1.0, EnergyEfficiency.BaseUnit); + var converted = inBaseUnits.ToUnit(unit); + + var conversionFactor = GetConversionFactor(unit); + AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); + Assert.Equal(unit, converted.Unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_WithSameUnits_AreEqual(EnergyEfficiencyUnit unit) + { + var quantity = EnergyEfficiency.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(EnergyEfficiencyUnit unit) + { + // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. + var fromUnit = EnergyEfficiency.Units.First(u => u != EnergyEfficiency.BaseUnit); + + var quantity = EnergyEfficiency.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(EnergyEfficiencyUnit unit) + { + var quantity = default(EnergyEfficiency); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromFemtowattHoursPerKilometer(watthourperkilometer.FemtowattHoursPerKilometer).WattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromFemtowattHoursPerMeter(watthourperkilometer.FemtowattHoursPerMeter).WattHoursPerKilometer, FemtowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromGigawattHoursPerKilometer(watthourperkilometer.GigawattHoursPerKilometer).WattHoursPerKilometer, GigawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromGigawattHoursPerMeter(watthourperkilometer.GigawattHoursPerMeter).WattHoursPerKilometer, GigawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerKilometer(watthourperkilometer.KilowattHoursPerKilometer).WattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerMeter(watthourperkilometer.KilowattHoursPerMeter).WattHoursPerKilometer, KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMegawattHoursPerKilometer(watthourperkilometer.MegawattHoursPerKilometer).WattHoursPerKilometer, MegawattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMegawattHoursPerMeter(watthourperkilometer.MegawattHoursPerMeter).WattHoursPerKilometer, MegawattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMicrowattHoursPerKilometer(watthourperkilometer.MicrowattHoursPerKilometer).WattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMicrowattHoursPerMeter(watthourperkilometer.MicrowattHoursPerMeter).WattHoursPerKilometer, MicrowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMilliwattHoursPerKilometer(watthourperkilometer.MilliwattHoursPerKilometer).WattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromMilliwattHoursPerMeter(watthourperkilometer.MilliwattHoursPerMeter).WattHoursPerKilometer, MilliwattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromNanowattHoursPerKilometer(watthourperkilometer.NanowattHoursPerKilometer).WattHoursPerKilometer, NanowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromNanowattHoursPerMeter(watthourperkilometer.NanowattHoursPerMeter).WattHoursPerKilometer, NanowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromPicowattHoursPerKilometer(watthourperkilometer.PicowattHoursPerKilometer).WattHoursPerKilometer, PicowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromPicowattHoursPerMeter(watthourperkilometer.PicowattHoursPerMeter).WattHoursPerKilometer, PicowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerKilometer(watthourperkilometer.WattHoursPerKilometer).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerMeter(watthourperkilometer.WattHoursPerMeter).WattHoursPerKilometer, WattHoursPerMeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + EnergyEfficiency v = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(-1, -v.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (EnergyEfficiency.FromWattHoursPerKilometer(3)-v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (v + v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(10, (v*10).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(10, (10*v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (EnergyEfficiency.FromWattHoursPerKilometer(10)/5).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, EnergyEfficiency.FromWattHoursPerKilometer(10)/EnergyEfficiency.FromWattHoursPerKilometer(5), WattHoursPerKilometerTolerance); + } + + [Fact] + public void ComparisonOperators() + { + EnergyEfficiency oneWattHourPerKilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + EnergyEfficiency twoWattHoursPerKilometer = EnergyEfficiency.FromWattHoursPerKilometer(2); + + Assert.True(oneWattHourPerKilometer < twoWattHoursPerKilometer); + Assert.True(oneWattHourPerKilometer <= twoWattHoursPerKilometer); + Assert.True(twoWattHoursPerKilometer > oneWattHourPerKilometer); + Assert.True(twoWattHoursPerKilometer >= oneWattHourPerKilometer); + + Assert.False(oneWattHourPerKilometer > twoWattHoursPerKilometer); + Assert.False(oneWattHourPerKilometer >= twoWattHoursPerKilometer); + Assert.False(twoWattHoursPerKilometer < oneWattHourPerKilometer); + Assert.False(twoWattHoursPerKilometer <= oneWattHourPerKilometer); + } + + [Fact] + public void CompareToIsImplemented() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Equal(0, watthourperkilometer.CompareTo(watthourperkilometer)); + Assert.True(watthourperkilometer.CompareTo(EnergyEfficiency.Zero) > 0); + Assert.True(EnergyEfficiency.Zero.CompareTo(watthourperkilometer) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => watthourperkilometer.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => watthourperkilometer.CompareTo(null)); + } + + [Theory] + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.WattHourPerKilometer, true)] // Same value and unit. + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 2, EnergyEfficiencyUnit.WattHourPerKilometer, false)] // Different value. + [InlineData(2, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.FemtowattHourPerKilometer, false)] // Different value and unit. + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.FemtowattHourPerKilometer, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EnergyEfficiencyUnit unitA, double valueB, EnergyEfficiencyUnit unitB, bool expectEqual) + { + var a = new EnergyEfficiency(valueA, unitA); + var b = new EnergyEfficiency(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = EnergyEfficiency.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + + [Fact] + public void Equals_RelativeTolerance_IsImplemented() + { + var v = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.True(v.Equals(EnergyEfficiency.FromWattHoursPerKilometer(1), WattHoursPerKilometerTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(EnergyEfficiency.Zero, WattHoursPerKilometerTolerance, ComparisonType.Relative)); + Assert.True(EnergyEfficiency.FromWattHoursPerKilometer(100).Equals(EnergyEfficiency.FromWattHoursPerKilometer(120), (double)0.3m, ComparisonType.Relative)); + Assert.False(EnergyEfficiency.FromWattHoursPerKilometer(100).Equals(EnergyEfficiency.FromWattHoursPerKilometer(120), (double)0.1m, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => v.Equals(EnergyEfficiency.FromWattHoursPerKilometer(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.False(watthourperkilometer.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.False(watthourperkilometer.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(EnergyEfficiencyUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(EnergyEfficiency.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 fWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer).ToString()); + Assert.Equal("1 fWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerMeter).ToString()); + Assert.Equal("1 GWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerKilometer).ToString()); + Assert.Equal("1 GWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerMeter).ToString()); + Assert.Equal("1 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString()); + Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString()); + Assert.Equal("1 MWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerKilometer).ToString()); + Assert.Equal("1 MWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerMeter).ToString()); + Assert.Equal("1 µWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer).ToString()); + Assert.Equal("1 µWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerMeter).ToString()); + Assert.Equal("1 mWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer).ToString()); + Assert.Equal("1 mWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerMeter).ToString()); + Assert.Equal("1 nWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerKilometer).ToString()); + Assert.Equal("1 nWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerMeter).ToString()); + Assert.Equal("1 pWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerKilometer).ToString()); + Assert.Equal("1 pWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerMeter).ToString()); + Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString()); + Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = 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 fWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 fWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 GWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 GWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 MWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 MWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 µWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 µWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 mWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 mWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 nWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 nWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 pWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 pWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s1")); + Assert.Equal("0.12 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s2")); + Assert.Equal("0.123 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s3")); + Assert.Equal("0.1235 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s1", culture)); + Assert.Equal("0.12 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s2", culture)); + Assert.Equal("0.123 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s3", culture)); + Assert.Equal("0.1235 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + CultureInfo formatProvider = cultureName == null + ? null + : CultureInfo.GetCultureInfo(cultureName); + + Assert.Equal(quantity.ToString("g", formatProvider), quantity.ToString(null, formatProvider)); + } + + [Theory] + [InlineData(null)] + [InlineData("g")] + public void ToString_NullProvider_EqualsCurrentCulture(string format) + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(EnergyEfficiency))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(EnergyEfficiencyUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(EnergyEfficiency.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(EnergyEfficiency.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(new {EnergyEfficiency.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); + } + + [Theory] + [InlineData(1.0)] + [InlineData(-1.0)] + public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(value); + Assert.Equal(EnergyEfficiency.FromWattHoursPerKilometer(-value), -quantity); + } + } +} diff --git a/UnitsNet/.DS_Store b/UnitsNet/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..83158d0b147bd9e2307db67d535fe81c6379bcee GIT binary patch literal 6148 zcmeHKyH3ME5S)V)5eO+I<^2MGa0-d?0sH_DrwdpjN$-x|X7)kk$f2b`v(n!9_I7UN zDZE|)WqIr#fCYd#-4I{4OwG>CCw7$)!{T@Jc*i4pbl6U^F9(c!L(UO<9LPNJyZzhl zweNREyTgVTe$YSh!n7?5WSMc=Q0VyB_q<|EV0%HZ(v(4tWfm)@26p#WZ1?>A! z>4q(F2=q?}7aswLGlt#x?6U;1T7cLRhd@SXC8)%pmK-rk&>63p*Aj=oprd$Y-jkI} zPAJ8zGhRI%r3Gr00#e{yf$P{VtpBg+zs&#VB<-Yt6!=#Pl-cTOwd5;hZ=JlH_1a2* srvDgoJ)MiUVxqTVZmbpGkMgQL^SmVvflg=K=|ueqm@YCY@D~bv1Dt6b;{X5v literal 0 HcmV?d00001 diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs new file mode 100644 index 0000000000..b1fee0a398 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -0,0 +1,1272 @@ +//------------------------------------------------------------------------------ +// +// 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.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct EnergyEfficiency : + IArithmeticQuantity, + IComparable, + IComparable, + IConvertible, + IEquatable, + IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 1)] + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 2)] + private readonly EnergyEfficiencyUnit? _unit; + + static EnergyEfficiency() + { + BaseDimensions = BaseDimensions.Dimensionless; + BaseUnit = EnergyEfficiencyUnit.WattHourPerKilometer; + Units = Enum.GetValues(typeof(EnergyEfficiencyUnit)).Cast().ToArray(); + Zero = new EnergyEfficiency(0, BaseUnit); + Info = new QuantityInfo("EnergyEfficiency", + new UnitInfo[] + { + new UnitInfo(EnergyEfficiencyUnit.FemtowattHourPerKilometer, "FemtowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.FemtowattHourPerMeter, "FemtowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.GigawattHourPerKilometer, "GigawattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.GigawattHourPerMeter, "GigawattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerKilometer, "KilowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerMeter, "KilowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MegawattHourPerKilometer, "MegawattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MegawattHourPerMeter, "MegawattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MicrowattHourPerKilometer, "MicrowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MicrowattHourPerMeter, "MicrowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MilliwattHourPerKilometer, "MilliwattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.MilliwattHourPerMeter, "MilliwattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.NanowattHourPerKilometer, "NanowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.NanowattHourPerMeter, "NanowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.PicowattHourPerKilometer, "PicowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.PicowattHourPerMeter, "PicowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.WattHourPerKilometer, "WattHoursPerKilometer", new BaseUnits(), "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.WattHourPerMeter, "WattHoursPerMeter", new BaseUnits(), "EnergyEfficiency"), + }, + BaseUnit, Zero, BaseDimensions); + + DefaultConversionFunctions = new UnitConverter(); + RegisterDefaultConversions(DefaultConversionFunctions); + } + + /// + /// 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 EnergyEfficiency(double value, EnergyEfficiencyUnit 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 EnergyEfficiency(double value, UnitSystem unitSystem) + { + if (unitSystem is 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 + + /// + /// The containing the default generated conversion functions for instances. + /// + public static UnitConverter DefaultConversionFunctions { get; } + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of EnergyEfficiency, which is WattHourPerKilometer. All conversions go via this value. + /// + public static EnergyEfficiencyUnit BaseUnit { get; } + + /// + /// All units of measurement for the EnergyEfficiency quantity. + /// + public static EnergyEfficiencyUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit WattHourPerKilometer. + /// + public static EnergyEfficiency Zero { get; } + + /// + public static EnergyEfficiency AdditiveIdentity => Zero; + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + QuantityValue IQuantity.Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public EnergyEfficiencyUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => EnergyEfficiency.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double FemtowattHoursPerKilometer => As(EnergyEfficiencyUnit.FemtowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double FemtowattHoursPerMeter => As(EnergyEfficiencyUnit.FemtowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double GigawattHoursPerKilometer => As(EnergyEfficiencyUnit.GigawattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double GigawattHoursPerMeter => As(EnergyEfficiencyUnit.GigawattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerKilometer => As(EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MegawattHoursPerKilometer => As(EnergyEfficiencyUnit.MegawattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MegawattHoursPerMeter => As(EnergyEfficiencyUnit.MegawattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrowattHoursPerKilometer => As(EnergyEfficiencyUnit.MicrowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrowattHoursPerMeter => As(EnergyEfficiencyUnit.MicrowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double MilliwattHoursPerKilometer => As(EnergyEfficiencyUnit.MilliwattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double MilliwattHoursPerMeter => As(EnergyEfficiencyUnit.MilliwattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double NanowattHoursPerKilometer => As(EnergyEfficiencyUnit.NanowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double NanowattHoursPerMeter => As(EnergyEfficiencyUnit.NanowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double PicowattHoursPerKilometer => As(EnergyEfficiencyUnit.PicowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double PicowattHoursPerMeter => As(EnergyEfficiencyUnit.PicowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerKilometer => As(EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerMeter => As(EnergyEfficiencyUnit.WattHourPerMeter); + + #endregion + + #region Static Methods + + /// + /// Registers the default conversion functions in the given instance. + /// + /// The to register the default conversion functions in. + internal static void RegisterDefaultConversions(UnitConverter unitConverter) + { + // Register in unit converter: EnergyEfficiencyUnit -> BaseUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.FemtowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.FemtowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.GigawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.GigawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MegawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MegawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MicrowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MicrowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MilliwattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MilliwattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.NanowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.NanowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.PicowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.PicowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity); + + // Register in unit converter: BaseUnit -> EnergyEfficiencyUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.FemtowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.FemtowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.GigawattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.GigawattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MegawattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MegawattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MicrowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MicrowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MilliwattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MilliwattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.NanowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.NanowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.PicowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.PicowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerMeter)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(EnergyEfficiencyUnit 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(EnergyEfficiencyUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromFemtowattHoursPerKilometer(QuantityValue femtowatthoursperkilometer) + { + double value = (double) femtowatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.FemtowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromFemtowattHoursPerMeter(QuantityValue femtowatthourspermeter) + { + double value = (double) femtowatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.FemtowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromGigawattHoursPerKilometer(QuantityValue gigawatthoursperkilometer) + { + double value = (double) gigawatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.GigawattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromGigawattHoursPerMeter(QuantityValue gigawatthourspermeter) + { + double value = (double) gigawatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.GigawattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerKilometer(QuantityValue kilowatthoursperkilometer) + { + double value = (double) kilowatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.KilowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerMeter(QuantityValue kilowatthourspermeter) + { + double value = (double) kilowatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.KilowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMegawattHoursPerKilometer(QuantityValue megawatthoursperkilometer) + { + double value = (double) megawatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MegawattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMegawattHoursPerMeter(QuantityValue megawatthourspermeter) + { + double value = (double) megawatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MegawattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMicrowattHoursPerKilometer(QuantityValue microwatthoursperkilometer) + { + double value = (double) microwatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MicrowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMicrowattHoursPerMeter(QuantityValue microwatthourspermeter) + { + double value = (double) microwatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MicrowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMilliwattHoursPerKilometer(QuantityValue milliwatthoursperkilometer) + { + double value = (double) milliwatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MilliwattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromMilliwattHoursPerMeter(QuantityValue milliwatthourspermeter) + { + double value = (double) milliwatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.MilliwattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromNanowattHoursPerKilometer(QuantityValue nanowatthoursperkilometer) + { + double value = (double) nanowatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.NanowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromNanowattHoursPerMeter(QuantityValue nanowatthourspermeter) + { + double value = (double) nanowatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.NanowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromPicowattHoursPerKilometer(QuantityValue picowatthoursperkilometer) + { + double value = (double) picowatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.PicowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromPicowattHoursPerMeter(QuantityValue picowatthourspermeter) + { + double value = (double) picowatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.PicowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerKilometer(QuantityValue watthoursperkilometer) + { + double value = (double) watthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.WattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerMeter(QuantityValue watthourspermeter) + { + double value = (double) watthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.WattHourPerMeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// EnergyEfficiency unit value. + public static EnergyEfficiency From(QuantityValue value, EnergyEfficiencyUnit fromUnit) + { + return new EnergyEfficiency((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", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static EnergyEfficiency Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static EnergyEfficiency Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse(string? str, out EnergyEfficiency result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse(string? str, IFormatProvider? provider, out EnergyEfficiency result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static EnergyEfficiencyUnit 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", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static EnergyEfficiencyUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out EnergyEfficiencyUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider? provider, out EnergyEfficiencyUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static EnergyEfficiency operator -(EnergyEfficiency right) + { + return new EnergyEfficiency(-right.Value, right.Unit); + } + + /// Get from adding two . + public static EnergyEfficiency operator +(EnergyEfficiency left, EnergyEfficiency right) + { + return new EnergyEfficiency(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static EnergyEfficiency operator -(EnergyEfficiency left, EnergyEfficiency right) + { + return new EnergyEfficiency(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static EnergyEfficiency operator *(double left, EnergyEfficiency right) + { + return new EnergyEfficiency(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static EnergyEfficiency operator *(EnergyEfficiency left, double right) + { + return new EnergyEfficiency(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static EnergyEfficiency operator /(EnergyEfficiency left, double right) + { + return new EnergyEfficiency(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(EnergyEfficiency left, EnergyEfficiency right) + { + return left.WattHoursPerKilometer / right.WattHoursPerKilometer; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value > right.ToUnit(left.Unit).Value; + } + + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #pragma warning disable CS0809 + + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(EnergyEfficiency other, EnergyEfficiency tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public static bool operator ==(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Equals(right); + } + + /// Indicates strict inequality of two quantities, where both and are exactly equal. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(EnergyEfficiency other, EnergyEfficiency tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public static bool operator !=(EnergyEfficiency left, EnergyEfficiency right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(EnergyEfficiency other, EnergyEfficiency tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public override bool Equals(object? obj) + { + if (obj is null || !(obj is EnergyEfficiency otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(EnergyEfficiency other, EnergyEfficiency tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public bool Equals(EnergyEfficiency other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(object? obj) + { + if (obj is null) throw new ArgumentNullException(nameof(obj)); + if (!(obj is EnergyEfficiency otherQuantity)) throw new ArgumentException("Expected type EnergyEfficiency.", nameof(obj)); + + return CompareTo(otherQuantity); + } + + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(EnergyEfficiency other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another EnergyEfficiency 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 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. + [Obsolete("Use Equals(EnergyEfficiency other, EnergyEfficiency tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public bool Equals(EnergyEfficiency other, double tolerance, ComparisonType comparisonType) + { + if (tolerance < 0) + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); + + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: comparisonType); + } + + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is EnergyEfficiency otherTyped + && (tolerance is EnergyEfficiency toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'EnergyEfficiency'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(EnergyEfficiency other, EnergyEfficiency tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current EnergyEfficiency. + public override int GetHashCode() + { + return new { Info.Name, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(EnergyEfficiencyUnit unit) + { + if (Unit == unit) + return Value; + + return ToUnit(unit).Value; + } + + /// + public double As(UnitSystem unitSystem) + { + if (unitSystem is 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 EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return (double)As(typedUnit); + } + + /// + double IValueQuantity.As(Enum unit) + { + if (!(unit is EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this EnergyEfficiency to another EnergyEfficiency with the unit representation . + /// + /// The unit to convert to. + /// A EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit unit) + { + return ToUnit(unit, DefaultConversionFunctions); + } + + /// + /// Converts this to another using the given with the unit representation . + /// + /// The unit to convert to. + /// The to use for the conversion. + /// A EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit unit, UnitConverter unitConverter) + { + if (TryToUnit(unit, out var converted)) + { + // Try to convert using the auto-generated conversion methods. + return converted!.Value; + } + else if (unitConverter.TryGetConversionFunction((typeof(EnergyEfficiency), Unit, typeof(EnergyEfficiency), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (EnergyEfficiency)conversionFunction(this); + } + else if (Unit != BaseUnit) + { + // Conversion to requested unit NOT found. Try to convert to BaseUnit, and then from BaseUnit to requested unit. + var inBaseUnits = ToUnit(BaseUnit); + return inBaseUnits.ToUnit(unit); + } + else + { + // No possible conversion + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + /// + /// Attempts to convert this to another with the unit representation . + /// + /// The unit to convert to. + /// The converted in , if successful. + /// True if successful, otherwise false. + private bool TryToUnit(EnergyEfficiencyUnit unit, [NotNullWhen(true)] out EnergyEfficiency? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + EnergyEfficiency? convertedOrNull = (Unit, unit) switch + { + // EnergyEfficiencyUnit -> BaseUnit + (EnergyEfficiencyUnit.FemtowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-15d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.FemtowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-15d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.GigawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e9d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.GigawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e9d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MegawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e6d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MegawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e6d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MicrowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-6d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MicrowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-6d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MilliwattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.MilliwattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.NanowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-9d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.NanowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-9d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.PicowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.PicowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency(_value / 1e3, EnergyEfficiencyUnit.WattHourPerKilometer), + + // BaseUnit -> EnergyEfficiencyUnit + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-15d, EnergyEfficiencyUnit.FemtowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-15d, EnergyEfficiencyUnit.FemtowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer) => new EnergyEfficiency((_value) / 1e9d, EnergyEfficiencyUnit.GigawattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e9d, EnergyEfficiencyUnit.GigawattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer) => new EnergyEfficiency((_value) / 1e6d, EnergyEfficiencyUnit.MegawattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e6d, EnergyEfficiencyUnit.MegawattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-6d, EnergyEfficiencyUnit.MicrowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-6d, EnergyEfficiencyUnit.MicrowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-3d, EnergyEfficiencyUnit.MilliwattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-3d, EnergyEfficiencyUnit.MilliwattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-9d, EnergyEfficiencyUnit.NanowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-9d, EnergyEfficiencyUnit.NanowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-12d, EnergyEfficiencyUnit.PicowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-12d, EnergyEfficiencyUnit.PicowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter) => new EnergyEfficiency(_value * 1e3, EnergyEfficiencyUnit.WattHourPerMeter), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public EnergyEfficiency ToUnit(UnitSystem unitSystem) + { + if (unitSystem is 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(EnergyEfficiencyUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IValueQuantity IValueQuantity.ToUnit(Enum unit) + { + if (unit is not EnergyEfficiencyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit); + } + + /// + IValueQuantity IValueQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + #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(IFormatProvider? provider) + { + return ToString("g", provider); + } + + /// + /// + /// 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.CurrentCulture); + } + + /// + /// + /// 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? provider) + { + return QuantityFormatter.Format(this, format, provider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} 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(EnergyEfficiency)) + return this; + else if (conversionType == typeof(EnergyEfficiencyUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return EnergyEfficiency.Info; + else if (conversionType == typeof(BaseDimensions)) + return EnergyEfficiency.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} 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 9432eb50b6..568098df47 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -75,6 +75,7 @@ public partial class Quantity { "ElectricSurfaceChargeDensity", ElectricSurfaceChargeDensity.Info }, { "Energy", Energy.Info }, { "EnergyDensity", EnergyDensity.Info }, + { "EnergyEfficiency", EnergyEfficiency.Info }, { "Entropy", Entropy.Info }, { "Force", Force.Info }, { "ForceChangeRate", ForceChangeRate.Info }, @@ -211,6 +212,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "ElectricSurfaceChargeDensity" => ElectricSurfaceChargeDensity.From(value, ElectricSurfaceChargeDensity.BaseUnit), "Energy" => Energy.From(value, Energy.BaseUnit), "EnergyDensity" => EnergyDensity.From(value, EnergyDensity.BaseUnit), + "EnergyEfficiency" => EnergyEfficiency.From(value, EnergyEfficiency.BaseUnit), "Entropy" => Entropy.From(value, Entropy.BaseUnit), "Force" => Force.From(value, Force.BaseUnit), "ForceChangeRate" => ForceChangeRate.From(value, ForceChangeRate.BaseUnit), @@ -350,6 +352,7 @@ public static bool TryFrom(QuantityValue value, Enum? unit, [NotNullWhen(true)] ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit => ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit), EnergyUnit energyUnit => Energy.From(value, energyUnit), EnergyDensityUnit energyDensityUnit => EnergyDensity.From(value, energyDensityUnit), + EnergyEfficiencyUnit energyEfficiencyUnit => EnergyEfficiency.From(value, energyEfficiencyUnit), EntropyUnit entropyUnit => Entropy.From(value, entropyUnit), ForceUnit forceUnit => Force.From(value, forceUnit), ForceChangeRateUnit forceChangeRateUnit => ForceChangeRate.From(value, forceChangeRateUnit), @@ -499,6 +502,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(ElectricSurfaceChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricSurfaceChargeDensity.From, out quantity), Type _ when quantityType == typeof(Energy) => parser.TryParse(quantityString, formatProvider, Energy.From, out quantity), Type _ when quantityType == typeof(EnergyDensity) => parser.TryParse(quantityString, formatProvider, EnergyDensity.From, out quantity), + Type _ when quantityType == typeof(EnergyEfficiency) => parser.TryParse(quantityString, formatProvider, EnergyEfficiency.From, out quantity), Type _ when quantityType == typeof(Entropy) => parser.TryParse(quantityString, formatProvider, Entropy.From, out quantity), Type _ when quantityType == typeof(Force) => parser.TryParse(quantityString, formatProvider, Force.From, out quantity), Type _ when quantityType == typeof(ForceChangeRate) => parser.TryParse(quantityString, formatProvider, ForceChangeRate.From, out quantity), @@ -629,6 +633,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(ElectricSurfaceChargeDensity); yield return typeof(Energy); yield return typeof(EnergyDensity); + yield return typeof(EnergyEfficiency); yield return typeof(Entropy); yield return typeof(Force); yield return typeof(ForceChangeRate); diff --git a/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext new file mode 100644 index 0000000000..c14c1b3fc7 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext @@ -0,0 +1,18 @@ +FemtowattHoursPerKilometer=fWh/km +FemtowattHoursPerMeter=fWh/m +GigawattHoursPerKilometer=GWh/km +GigawattHoursPerMeter=GWh/m +KilowattHoursPerKilometer=kWh/km +KilowattHoursPerMeter=kWh/m +MegawattHoursPerKilometer=MWh/km +MegawattHoursPerMeter=MWh/m +MicrowattHoursPerKilometer=µWh/km +MicrowattHoursPerMeter=µWh/m +MilliwattHoursPerKilometer=mWh/km +MilliwattHoursPerMeter=mWh/m +NanowattHoursPerKilometer=nWh/km +NanowattHoursPerMeter=nWh/m +PicowattHoursPerKilometer=pWh/km +PicowattHoursPerMeter=pWh/m +WattHoursPerKilometer=Wh/km +WattHoursPerMeter=Wh/m diff --git a/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs new file mode 100644 index 0000000000..6dc17b9e06 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiencyUnit + { + FemtowattHourPerKilometer = 7, + FemtowattHourPerMeter = 9, + GigawattHourPerKilometer = 10, + GigawattHourPerMeter = 2, + KilowattHourPerKilometer = 5, + KilowattHourPerMeter = 3, + MegawattHourPerKilometer = 1, + MegawattHourPerMeter = 6, + MicrowattHourPerKilometer = 4, + MicrowattHourPerMeter = 8, + MilliwattHourPerKilometer = 12, + MilliwattHourPerMeter = 15, + NanowattHourPerKilometer = 11, + NanowattHourPerMeter = 16, + PicowattHourPerKilometer = 14, + PicowattHourPerMeter = 19, + WattHourPerKilometer = 13, + WattHourPerMeter = 20, + } + + #pragma warning restore 1591 +} From 9d940d2febec901c013615c25dfa8d221bcfd62f Mon Sep 17 00:00:00 2001 From: Chef904 Date: Thu, 29 Aug 2024 15:30:46 +0200 Subject: [PATCH 2/7] chore: Update EnergyEfficiencyTests with unit conversions --- .../CustomCode/EnergyEfficiencyTests.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs index cf0b53c170..d3ccdd2b09 100644 --- a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs +++ b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs @@ -23,6 +23,23 @@ namespace UnitsNet.Tests.CustomCode { public class EnergyEfficiencyTests : EnergyEfficiencyTestsBase { - // Override properties in base class here + protected override double FemtowattHoursPerKilometerInOneWattHourPerKilometer => 1e15; + protected override double FemtowattHoursPerMeterInOneWattHourPerKilometer => 1e12; + protected override double GigawattHoursPerKilometerInOneWattHourPerKilometer => 1e-9; + protected override double GigawattHoursPerMeterInOneWattHourPerKilometer => 1e-12; + protected override double KilowattHoursPerKilometerInOneWattHourPerKilometer => 1e-3; + protected override double KilowattHoursPerMeterInOneWattHourPerKilometer => 1e-6; + protected override double MegawattHoursPerKilometerInOneWattHourPerKilometer => 1e-6; + protected override double MegawattHoursPerMeterInOneWattHourPerKilometer => 1e-9; + protected override double MicrowattHoursPerKilometerInOneWattHourPerKilometer => 1e6; + protected override double MicrowattHoursPerMeterInOneWattHourPerKilometer => 1e3; + protected override double MilliwattHoursPerKilometerInOneWattHourPerKilometer => 1e3; + protected override double MilliwattHoursPerMeterInOneWattHourPerKilometer => 1; + protected override double NanowattHoursPerKilometerInOneWattHourPerKilometer => 1e9; + protected override double NanowattHoursPerMeterInOneWattHourPerKilometer => 1e6; + protected override double PicowattHoursPerKilometerInOneWattHourPerKilometer => 1e12; + protected override double PicowattHoursPerMeterInOneWattHourPerKilometer => 1e9; + protected override double WattHoursPerKilometerInOneWattHourPerKilometer => 1; + protected override double WattHoursPerMeterInOneWattHourPerKilometer => 1e-3; } } From 6201988a0c7f5844d1cc700d741c0df8c5545da6 Mon Sep 17 00:00:00 2001 From: Chef904 Date: Thu, 29 Aug 2024 15:45:34 +0200 Subject: [PATCH 3/7] chore: Update EnergyEfficiencyTests with unit conversions --- Common/UnitDefinitions/EnergyEfficiency.json | 6 +- .../Quantities/EnergyEfficiency.g.cs | 182 ------- .../Units/EnergyEfficiencyUnit.g.cs | 14 - ...umberToEnergyEfficiencyExtensionsTest.g.cs | 56 -- .../NumberToEnergyEfficiencyExtensions.g.cs | 112 ---- .../CustomCode/EnergyEfficiencyTests.cs | 1 + .../TestsBase/EnergyEfficiencyTestsBase.g.cs | 502 +----------------- .../Quantities/EnergyEfficiency.g.cs | 280 ---------- .../Resources/EnergyEfficiency.restext | 14 - .../Units/EnergyEfficiencyUnit.g.cs | 14 - 10 files changed, 18 insertions(+), 1163 deletions(-) diff --git a/Common/UnitDefinitions/EnergyEfficiency.json b/Common/UnitDefinitions/EnergyEfficiency.json index 0967cd7c57..617ecca5dd 100644 --- a/Common/UnitDefinitions/EnergyEfficiency.json +++ b/Common/UnitDefinitions/EnergyEfficiency.json @@ -14,7 +14,7 @@ }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": ["Kilo" ], "Localization": [ { "Culture": "en-US", @@ -26,11 +26,11 @@ "SingularName": "WattHourPerMeter", "PluralName": "WattHoursPerMeter", "BaseUnits": { - "Wh/km": "WattHourPerMeter" + "Wh/m": "WattHourPerMeter" }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", - "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": ["Kilo"], "Localization": [ { "Culture": "en-US", diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs index 5ff1658afb..86c1477029 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -79,26 +79,6 @@ public EnergyEfficiency(double value, EnergyEfficiencyUnit unit) public static EnergyEfficiency Zero { get; } = new EnergyEfficiency(0, BaseUnit); #region Conversion Properties - /// - /// Gets a value of this quantity converted into - /// - public double FemtowattHoursPerKilometer => As(EnergyEfficiencyUnit.FemtowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double FemtowattHoursPerMeter => As(EnergyEfficiencyUnit.FemtowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double GigawattHoursPerKilometer => As(EnergyEfficiencyUnit.GigawattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double GigawattHoursPerMeter => As(EnergyEfficiencyUnit.GigawattHourPerMeter); - /// /// Gets a value of this quantity converted into /// @@ -109,56 +89,6 @@ public EnergyEfficiency(double value, EnergyEfficiencyUnit unit) /// public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); - /// - /// Gets a value of this quantity converted into - /// - public double MegawattHoursPerKilometer => As(EnergyEfficiencyUnit.MegawattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MegawattHoursPerMeter => As(EnergyEfficiencyUnit.MegawattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrowattHoursPerKilometer => As(EnergyEfficiencyUnit.MicrowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrowattHoursPerMeter => As(EnergyEfficiencyUnit.MicrowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double MilliwattHoursPerKilometer => As(EnergyEfficiencyUnit.MilliwattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MilliwattHoursPerMeter => As(EnergyEfficiencyUnit.MilliwattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double NanowattHoursPerKilometer => As(EnergyEfficiencyUnit.NanowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double NanowattHoursPerMeter => As(EnergyEfficiencyUnit.NanowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double PicowattHoursPerKilometer => As(EnergyEfficiencyUnit.PicowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double PicowattHoursPerMeter => As(EnergyEfficiencyUnit.PicowattHourPerMeter); - /// /// Gets a value of this quantity converted into /// @@ -173,30 +103,6 @@ public EnergyEfficiency(double value, EnergyEfficiencyUnit unit) #region Static Factory Methods - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromFemtowattHoursPerKilometer(double femtowatthoursperkilometer) => new EnergyEfficiency(femtowatthoursperkilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromFemtowattHoursPerMeter(double femtowatthourspermeter) => new EnergyEfficiency(femtowatthourspermeter, EnergyEfficiencyUnit.FemtowattHourPerMeter); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromGigawattHoursPerKilometer(double gigawatthoursperkilometer) => new EnergyEfficiency(gigawatthoursperkilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromGigawattHoursPerMeter(double gigawatthourspermeter) => new EnergyEfficiency(gigawatthourspermeter, EnergyEfficiencyUnit.GigawattHourPerMeter); - /// /// Creates a from . /// @@ -209,66 +115,6 @@ public EnergyEfficiency(double value, EnergyEfficiencyUnit unit) /// If value is NaN or Infinity. public static EnergyEfficiency FromKilowattHoursPerMeter(double kilowatthourspermeter) => new EnergyEfficiency(kilowatthourspermeter, EnergyEfficiencyUnit.KilowattHourPerMeter); - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMegawattHoursPerKilometer(double megawatthoursperkilometer) => new EnergyEfficiency(megawatthoursperkilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMegawattHoursPerMeter(double megawatthourspermeter) => new EnergyEfficiency(megawatthourspermeter, EnergyEfficiencyUnit.MegawattHourPerMeter); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMicrowattHoursPerKilometer(double microwatthoursperkilometer) => new EnergyEfficiency(microwatthoursperkilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMicrowattHoursPerMeter(double microwatthourspermeter) => new EnergyEfficiency(microwatthourspermeter, EnergyEfficiencyUnit.MicrowattHourPerMeter); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMilliwattHoursPerKilometer(double milliwatthoursperkilometer) => new EnergyEfficiency(milliwatthoursperkilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMilliwattHoursPerMeter(double milliwatthourspermeter) => new EnergyEfficiency(milliwatthourspermeter, EnergyEfficiencyUnit.MilliwattHourPerMeter); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromNanowattHoursPerKilometer(double nanowatthoursperkilometer) => new EnergyEfficiency(nanowatthoursperkilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromNanowattHoursPerMeter(double nanowatthourspermeter) => new EnergyEfficiency(nanowatthourspermeter, EnergyEfficiencyUnit.NanowattHourPerMeter); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromPicowattHoursPerKilometer(double picowatthoursperkilometer) => new EnergyEfficiency(picowatthoursperkilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer); - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromPicowattHoursPerMeter(double picowatthourspermeter) => new EnergyEfficiency(picowatthourspermeter, EnergyEfficiencyUnit.PicowattHourPerMeter); - /// /// Creates a from . /// @@ -321,22 +167,8 @@ private double GetValueInBaseUnit() { return Unit switch { - EnergyEfficiencyUnit.FemtowattHourPerKilometer => (_value) * 1e-15d, - EnergyEfficiencyUnit.FemtowattHourPerMeter => (_value / 1e3) * 1e-15d, - EnergyEfficiencyUnit.GigawattHourPerKilometer => (_value) * 1e9d, - EnergyEfficiencyUnit.GigawattHourPerMeter => (_value / 1e3) * 1e9d, EnergyEfficiencyUnit.KilowattHourPerKilometer => (_value) * 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter => (_value / 1e3) * 1e3d, - EnergyEfficiencyUnit.MegawattHourPerKilometer => (_value) * 1e6d, - EnergyEfficiencyUnit.MegawattHourPerMeter => (_value / 1e3) * 1e6d, - EnergyEfficiencyUnit.MicrowattHourPerKilometer => (_value) * 1e-6d, - EnergyEfficiencyUnit.MicrowattHourPerMeter => (_value / 1e3) * 1e-6d, - EnergyEfficiencyUnit.MilliwattHourPerKilometer => (_value) * 1e-3d, - EnergyEfficiencyUnit.MilliwattHourPerMeter => (_value / 1e3) * 1e-3d, - EnergyEfficiencyUnit.NanowattHourPerKilometer => (_value) * 1e-9d, - EnergyEfficiencyUnit.NanowattHourPerMeter => (_value / 1e3) * 1e-9d, - EnergyEfficiencyUnit.PicowattHourPerKilometer => (_value) * 1e-12d, - EnergyEfficiencyUnit.PicowattHourPerMeter => (_value / 1e3) * 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer => _value, EnergyEfficiencyUnit.WattHourPerMeter => _value / 1e3, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") @@ -352,22 +184,8 @@ private double GetValueAs(EnergyEfficiencyUnit unit) return unit switch { - EnergyEfficiencyUnit.FemtowattHourPerKilometer => (baseUnitValue) / 1e-15d, - EnergyEfficiencyUnit.FemtowattHourPerMeter => (baseUnitValue * 1e3) / 1e-15d, - EnergyEfficiencyUnit.GigawattHourPerKilometer => (baseUnitValue) / 1e9d, - EnergyEfficiencyUnit.GigawattHourPerMeter => (baseUnitValue * 1e3) / 1e9d, EnergyEfficiencyUnit.KilowattHourPerKilometer => (baseUnitValue) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter => (baseUnitValue * 1e3) / 1e3d, - EnergyEfficiencyUnit.MegawattHourPerKilometer => (baseUnitValue) / 1e6d, - EnergyEfficiencyUnit.MegawattHourPerMeter => (baseUnitValue * 1e3) / 1e6d, - EnergyEfficiencyUnit.MicrowattHourPerKilometer => (baseUnitValue) / 1e-6d, - EnergyEfficiencyUnit.MicrowattHourPerMeter => (baseUnitValue * 1e3) / 1e-6d, - EnergyEfficiencyUnit.MilliwattHourPerKilometer => (baseUnitValue) / 1e-3d, - EnergyEfficiencyUnit.MilliwattHourPerMeter => (baseUnitValue * 1e3) / 1e-3d, - EnergyEfficiencyUnit.NanowattHourPerKilometer => (baseUnitValue) / 1e-9d, - EnergyEfficiencyUnit.NanowattHourPerMeter => (baseUnitValue * 1e3) / 1e-9d, - EnergyEfficiencyUnit.PicowattHourPerKilometer => (baseUnitValue) / 1e-12d, - EnergyEfficiencyUnit.PicowattHourPerMeter => (baseUnitValue * 1e3) / 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer => baseUnitValue, EnergyEfficiencyUnit.WattHourPerMeter => baseUnitValue * 1e3, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs index 6dc17b9e06..0fc1eafbc4 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -25,22 +25,8 @@ namespace UnitsNet.Units public enum EnergyEfficiencyUnit { - FemtowattHourPerKilometer = 7, - FemtowattHourPerMeter = 9, - GigawattHourPerKilometer = 10, - GigawattHourPerMeter = 2, KilowattHourPerKilometer = 5, KilowattHourPerMeter = 3, - MegawattHourPerKilometer = 1, - MegawattHourPerMeter = 6, - MicrowattHourPerKilometer = 4, - MicrowattHourPerMeter = 8, - MilliwattHourPerKilometer = 12, - MilliwattHourPerMeter = 15, - NanowattHourPerKilometer = 11, - NanowattHourPerMeter = 16, - PicowattHourPerKilometer = 14, - PicowattHourPerMeter = 19, WattHourPerKilometer = 13, WattHourPerMeter = 20, } diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs index 1060ea6392..3ee8b30f71 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs @@ -24,22 +24,6 @@ namespace UnitsNet.Tests { public class NumberToEnergyEfficiencyExtensionsTests { - [Fact] - public void NumberToFemtowattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromFemtowattHoursPerKilometer(2), 2.FemtowattHoursPerKilometer()); - - [Fact] - public void NumberToFemtowattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromFemtowattHoursPerMeter(2), 2.FemtowattHoursPerMeter()); - - [Fact] - public void NumberToGigawattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromGigawattHoursPerKilometer(2), 2.GigawattHoursPerKilometer()); - - [Fact] - public void NumberToGigawattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromGigawattHoursPerMeter(2), 2.GigawattHoursPerMeter()); - [Fact] public void NumberToKilowattHoursPerKilometerTest() => Assert.Equal(EnergyEfficiency.FromKilowattHoursPerKilometer(2), 2.KilowattHoursPerKilometer()); @@ -48,46 +32,6 @@ public void NumberToKilowattHoursPerKilometerTest() => public void NumberToKilowattHoursPerMeterTest() => Assert.Equal(EnergyEfficiency.FromKilowattHoursPerMeter(2), 2.KilowattHoursPerMeter()); - [Fact] - public void NumberToMegawattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromMegawattHoursPerKilometer(2), 2.MegawattHoursPerKilometer()); - - [Fact] - public void NumberToMegawattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromMegawattHoursPerMeter(2), 2.MegawattHoursPerMeter()); - - [Fact] - public void NumberToMicrowattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromMicrowattHoursPerKilometer(2), 2.MicrowattHoursPerKilometer()); - - [Fact] - public void NumberToMicrowattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromMicrowattHoursPerMeter(2), 2.MicrowattHoursPerMeter()); - - [Fact] - public void NumberToMilliwattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromMilliwattHoursPerKilometer(2), 2.MilliwattHoursPerKilometer()); - - [Fact] - public void NumberToMilliwattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromMilliwattHoursPerMeter(2), 2.MilliwattHoursPerMeter()); - - [Fact] - public void NumberToNanowattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromNanowattHoursPerKilometer(2), 2.NanowattHoursPerKilometer()); - - [Fact] - public void NumberToNanowattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromNanowattHoursPerMeter(2), 2.NanowattHoursPerMeter()); - - [Fact] - public void NumberToPicowattHoursPerKilometerTest() => - Assert.Equal(EnergyEfficiency.FromPicowattHoursPerKilometer(2), 2.PicowattHoursPerKilometer()); - - [Fact] - public void NumberToPicowattHoursPerMeterTest() => - Assert.Equal(EnergyEfficiency.FromPicowattHoursPerMeter(2), 2.PicowattHoursPerMeter()); - [Fact] public void NumberToWattHoursPerKilometerTest() => Assert.Equal(EnergyEfficiency.FromWattHoursPerKilometer(2), 2.WattHoursPerKilometer()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs index 0c4777a409..4aae2e4406 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs @@ -32,38 +32,6 @@ namespace UnitsNet.NumberExtensions.NumberToEnergyEfficiency /// public static class NumberToEnergyEfficiencyExtensions { - /// - public static EnergyEfficiency FemtowattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromFemtowattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency FemtowattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromFemtowattHoursPerMeter(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency GigawattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromGigawattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency GigawattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromGigawattHoursPerMeter(Convert.ToDouble(value)); - /// public static EnergyEfficiency KilowattHoursPerKilometer(this T value) where T : notnull @@ -80,86 +48,6 @@ public static EnergyEfficiency KilowattHoursPerMeter(this T value) #endif => EnergyEfficiency.FromKilowattHoursPerMeter(Convert.ToDouble(value)); - /// - public static EnergyEfficiency MegawattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMegawattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency MegawattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMegawattHoursPerMeter(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency MicrowattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMicrowattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency MicrowattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMicrowattHoursPerMeter(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency MilliwattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMilliwattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency MilliwattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromMilliwattHoursPerMeter(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency NanowattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromNanowattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency NanowattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromNanowattHoursPerMeter(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency PicowattHoursPerKilometer(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromPicowattHoursPerKilometer(Convert.ToDouble(value)); - - /// - public static EnergyEfficiency PicowattHoursPerMeter(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => EnergyEfficiency.FromPicowattHoursPerMeter(Convert.ToDouble(value)); - /// public static EnergyEfficiency WattHoursPerKilometer(this T value) where T : notnull diff --git a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs index d3ccdd2b09..5e78919e71 100644 --- a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs +++ b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs @@ -23,6 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class EnergyEfficiencyTests : EnergyEfficiencyTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double FemtowattHoursPerKilometerInOneWattHourPerKilometer => 1e15; protected override double FemtowattHoursPerMeterInOneWattHourPerKilometer => 1e12; protected override double GigawattHoursPerKilometerInOneWattHourPerKilometer => 1e-9; diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs index 51d2ddc637..187a2f12f9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs @@ -38,42 +38,14 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class EnergyEfficiencyTestsBase : QuantityTestsBase { - protected abstract double FemtowattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double FemtowattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double GigawattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double GigawattHoursPerMeterInOneWattHourPerKilometer { get; } protected abstract double KilowattHoursPerKilometerInOneWattHourPerKilometer { get; } protected abstract double KilowattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double MegawattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double MegawattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double MicrowattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double MicrowattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double MilliwattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double MilliwattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double NanowattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double NanowattHoursPerMeterInOneWattHourPerKilometer { get; } - protected abstract double PicowattHoursPerKilometerInOneWattHourPerKilometer { get; } - protected abstract double PicowattHoursPerMeterInOneWattHourPerKilometer { get; } protected abstract double WattHoursPerKilometerInOneWattHourPerKilometer { get; } protected abstract double WattHoursPerMeterInOneWattHourPerKilometer { get; } // ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double FemtowattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double FemtowattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double GigawattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double GigawattHoursPerMeterTolerance { get { return 1e-5; } } protected virtual double KilowattHoursPerKilometerTolerance { get { return 1e-5; } } protected virtual double KilowattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double MegawattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double MegawattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double MicrowattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double MicrowattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double MilliwattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double MilliwattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double NanowattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double NanowattHoursPerMeterTolerance { get { return 1e-5; } } - protected virtual double PicowattHoursPerKilometerTolerance { get { return 1e-5; } } - protected virtual double PicowattHoursPerMeterTolerance { get { return 1e-5; } } protected virtual double WattHoursPerKilometerTolerance { get { return 1e-5; } } protected virtual double WattHoursPerMeterTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -82,22 +54,8 @@ public abstract partial class EnergyEfficiencyTestsBase : QuantityTestsBase { return unit switch { - EnergyEfficiencyUnit.FemtowattHourPerKilometer => (FemtowattHoursPerKilometerInOneWattHourPerKilometer, FemtowattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.FemtowattHourPerMeter => (FemtowattHoursPerMeterInOneWattHourPerKilometer, FemtowattHoursPerMeterTolerance), - EnergyEfficiencyUnit.GigawattHourPerKilometer => (GigawattHoursPerKilometerInOneWattHourPerKilometer, GigawattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.GigawattHourPerMeter => (GigawattHoursPerMeterInOneWattHourPerKilometer, GigawattHoursPerMeterTolerance), EnergyEfficiencyUnit.KilowattHourPerKilometer => (KilowattHoursPerKilometerInOneWattHourPerKilometer, KilowattHoursPerKilometerTolerance), EnergyEfficiencyUnit.KilowattHourPerMeter => (KilowattHoursPerMeterInOneWattHourPerKilometer, KilowattHoursPerMeterTolerance), - EnergyEfficiencyUnit.MegawattHourPerKilometer => (MegawattHoursPerKilometerInOneWattHourPerKilometer, MegawattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.MegawattHourPerMeter => (MegawattHoursPerMeterInOneWattHourPerKilometer, MegawattHoursPerMeterTolerance), - EnergyEfficiencyUnit.MicrowattHourPerKilometer => (MicrowattHoursPerKilometerInOneWattHourPerKilometer, MicrowattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.MicrowattHourPerMeter => (MicrowattHoursPerMeterInOneWattHourPerKilometer, MicrowattHoursPerMeterTolerance), - EnergyEfficiencyUnit.MilliwattHourPerKilometer => (MilliwattHoursPerKilometerInOneWattHourPerKilometer, MilliwattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.MilliwattHourPerMeter => (MilliwattHoursPerMeterInOneWattHourPerKilometer, MilliwattHoursPerMeterTolerance), - EnergyEfficiencyUnit.NanowattHourPerKilometer => (NanowattHoursPerKilometerInOneWattHourPerKilometer, NanowattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.NanowattHourPerMeter => (NanowattHoursPerMeterInOneWattHourPerKilometer, NanowattHoursPerMeterTolerance), - EnergyEfficiencyUnit.PicowattHourPerKilometer => (PicowattHoursPerKilometerInOneWattHourPerKilometer, PicowattHoursPerKilometerTolerance), - EnergyEfficiencyUnit.PicowattHourPerMeter => (PicowattHoursPerMeterInOneWattHourPerKilometer, PicowattHoursPerMeterTolerance), EnergyEfficiencyUnit.WattHourPerKilometer => (WattHoursPerKilometerInOneWattHourPerKilometer, WattHoursPerKilometerTolerance), EnergyEfficiencyUnit.WattHourPerMeter => (WattHoursPerMeterInOneWattHourPerKilometer, WattHoursPerMeterTolerance), _ => throw new NotSupportedException() @@ -106,22 +64,8 @@ public abstract partial class EnergyEfficiencyTestsBase : QuantityTestsBase public static IEnumerable UnitTypes = new List { - new object[] { EnergyEfficiencyUnit.FemtowattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.FemtowattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.GigawattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.GigawattHourPerMeter }, new object[] { EnergyEfficiencyUnit.KilowattHourPerKilometer }, new object[] { EnergyEfficiencyUnit.KilowattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.MegawattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.MegawattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.MicrowattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.MicrowattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.MilliwattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.MilliwattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.NanowattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.NanowattHourPerMeter }, - new object[] { EnergyEfficiencyUnit.PicowattHourPerKilometer }, - new object[] { EnergyEfficiencyUnit.PicowattHourPerMeter }, new object[] { EnergyEfficiencyUnit.WattHourPerKilometer }, new object[] { EnergyEfficiencyUnit.WattHourPerMeter }, }; @@ -186,22 +130,8 @@ public void EnergyEfficiency_QuantityInfo_ReturnsQuantityInfoDescribingQuantity( public void WattHourPerKilometerToEnergyEfficiencyUnits() { EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); - AssertEx.EqualTolerance(FemtowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(FemtowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(GigawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(GigawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MegawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MegawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MicrowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MicrowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MilliwattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MilliwattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); - AssertEx.EqualTolerance(NanowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(NanowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(PicowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(PicowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerKilometer, WattHoursPerKilometerTolerance); AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerMeter, WattHoursPerMeterTolerance); } @@ -209,77 +139,21 @@ public void WattHourPerKilometerToEnergyEfficiencyUnits() [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity00.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, quantity00.Unit); + var quantity00 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity00.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity00.Unit); - var quantity01 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.FemtowattHourPerMeter); - AssertEx.EqualTolerance(1, quantity01.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, quantity01.Unit); + var quantity01 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity01.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, quantity01.Unit); - var quantity02 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.GigawattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity02.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, quantity02.Unit); + var quantity02 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity02.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity02.Unit); - var quantity03 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.GigawattHourPerMeter); - AssertEx.EqualTolerance(1, quantity03.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, quantity03.Unit); - - var quantity04 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity04.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity04.Unit); - - var quantity05 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerMeter); - AssertEx.EqualTolerance(1, quantity05.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, quantity05.Unit); - - var quantity06 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MegawattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity06.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, quantity06.Unit); - - var quantity07 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MegawattHourPerMeter); - AssertEx.EqualTolerance(1, quantity07.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, quantity07.Unit); - - var quantity08 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity08.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, quantity08.Unit); - - var quantity09 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MicrowattHourPerMeter); - AssertEx.EqualTolerance(1, quantity09.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, quantity09.Unit); - - var quantity10 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity10.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, quantity10.Unit); - - var quantity11 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.MilliwattHourPerMeter); - AssertEx.EqualTolerance(1, quantity11.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, quantity11.Unit); - - var quantity12 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.NanowattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity12.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, quantity12.Unit); - - var quantity13 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.NanowattHourPerMeter); - AssertEx.EqualTolerance(1, quantity13.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, quantity13.Unit); - - var quantity14 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.PicowattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity14.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, quantity14.Unit); - - var quantity15 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.PicowattHourPerMeter); - AssertEx.EqualTolerance(1, quantity15.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, quantity15.Unit); - - var quantity16 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerKilometer); - AssertEx.EqualTolerance(1, quantity16.WattHoursPerKilometer, WattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity16.Unit); - - var quantity17 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerMeter); - AssertEx.EqualTolerance(1, quantity17.WattHoursPerMeter, WattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, quantity17.Unit); + var quantity03 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerMeter); + AssertEx.EqualTolerance(1, quantity03.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, quantity03.Unit); } @@ -300,22 +174,8 @@ public void FromWattHoursPerKilometer_WithNanValue_ThrowsArgumentException() public void As() { var watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); - AssertEx.EqualTolerance(FemtowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.FemtowattHourPerKilometer), FemtowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(FemtowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.FemtowattHourPerMeter), FemtowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(GigawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.GigawattHourPerKilometer), GigawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(GigawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.GigawattHourPerMeter), GigawattHoursPerMeterTolerance); AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerKilometer), KilowattHoursPerKilometerTolerance); AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerMeter), KilowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MegawattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MegawattHourPerKilometer), MegawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MegawattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MegawattHourPerMeter), MegawattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MicrowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MicrowattHourPerKilometer), MicrowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MicrowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MicrowattHourPerMeter), MicrowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(MilliwattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MilliwattHourPerKilometer), MilliwattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(MilliwattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.MilliwattHourPerMeter), MilliwattHoursPerMeterTolerance); - AssertEx.EqualTolerance(NanowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.NanowattHourPerKilometer), NanowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(NanowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.NanowattHourPerMeter), NanowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(PicowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.PicowattHourPerKilometer), PicowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(PicowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.PicowattHourPerMeter), PicowattHoursPerMeterTolerance); AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerKilometer), WattHoursPerKilometerTolerance); AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerMeter), WattHoursPerMeterTolerance); } @@ -340,34 +200,6 @@ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void Parse() { - try - { - var parsed = EnergyEfficiency.Parse("1 fWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 fWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 GWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 GWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try { var parsed = EnergyEfficiency.Parse("1 kWh/km", CultureInfo.GetCultureInfo("en-US")); @@ -382,76 +214,6 @@ public void Parse() Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try - { - var parsed = EnergyEfficiency.Parse("1 MWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerKilometer, MegawattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 MWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegawattHoursPerMeter, MegawattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 µWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 µWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 mWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 mWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MilliwattHoursPerMeter, MilliwattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 nWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 nWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 pWh/km", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = EnergyEfficiency.Parse("1 pWh/m", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try { var parsed = EnergyEfficiency.Parse("1 Wh/km", CultureInfo.GetCultureInfo("en-US")); @@ -471,30 +233,6 @@ public void Parse() [Fact] public void TryParse() { - { - Assert.True(EnergyEfficiency.TryParse("1 fWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 fWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.FemtowattHoursPerMeter, FemtowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 GWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerKilometer, GigawattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 GWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigawattHoursPerMeter, GigawattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsed.Unit); - } - { Assert.True(EnergyEfficiency.TryParse("1 kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); @@ -507,42 +245,6 @@ public void TryParse() Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); } - { - Assert.True(EnergyEfficiency.TryParse("1 µWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 µWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrowattHoursPerMeter, MicrowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 nWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattHoursPerKilometer, NanowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 nWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.NanowattHoursPerMeter, NanowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 pWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattHoursPerKilometer, PicowattHoursPerKilometerTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsed.Unit); - } - - { - Assert.True(EnergyEfficiency.TryParse("1 pWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.PicowattHoursPerMeter, PicowattHoursPerMeterTolerance); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsed.Unit); - } - { Assert.True(EnergyEfficiency.TryParse("1 Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.WattHoursPerKilometer, WattHoursPerKilometerTolerance); @@ -560,30 +262,6 @@ public void TryParse() [Fact] public void ParseUnit() { - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("fWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("fWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("GWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("GWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try { var parsedUnit = EnergyEfficiency.ParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US")); @@ -596,66 +274,6 @@ public void ParseUnit() Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("MWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("MWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MegawattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("µWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("µWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("mWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("mWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.MilliwattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("nWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("nWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("pWh/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyEfficiency.ParseUnit("pWh/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - try { var parsedUnit = EnergyEfficiency.ParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US")); @@ -673,26 +291,6 @@ public void ParseUnit() [Fact] public void TryParseUnit() { - { - Assert.True(EnergyEfficiency.TryParseUnit("fWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerKilometer, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("fWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.FemtowattHourPerMeter, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("GWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerKilometer, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("GWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.GigawattHourPerMeter, parsedUnit); - } - { Assert.True(EnergyEfficiency.TryParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsedUnit); @@ -703,36 +301,6 @@ public void TryParseUnit() Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); } - { - Assert.True(EnergyEfficiency.TryParseUnit("µWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerKilometer, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("µWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.MicrowattHourPerMeter, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("nWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerKilometer, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("nWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.NanowattHourPerMeter, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("pWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerKilometer, parsedUnit); - } - - { - Assert.True(EnergyEfficiency.TryParseUnit("pWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyEfficiencyUnit.PicowattHourPerMeter, parsedUnit); - } - { Assert.True(EnergyEfficiency.TryParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsedUnit); @@ -791,22 +359,8 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ener public void ConversionRoundTrip() { EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromFemtowattHoursPerKilometer(watthourperkilometer.FemtowattHoursPerKilometer).WattHoursPerKilometer, FemtowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromFemtowattHoursPerMeter(watthourperkilometer.FemtowattHoursPerMeter).WattHoursPerKilometer, FemtowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromGigawattHoursPerKilometer(watthourperkilometer.GigawattHoursPerKilometer).WattHoursPerKilometer, GigawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromGigawattHoursPerMeter(watthourperkilometer.GigawattHoursPerMeter).WattHoursPerKilometer, GigawattHoursPerMeterTolerance); AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerKilometer(watthourperkilometer.KilowattHoursPerKilometer).WattHoursPerKilometer, KilowattHoursPerKilometerTolerance); AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerMeter(watthourperkilometer.KilowattHoursPerMeter).WattHoursPerKilometer, KilowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMegawattHoursPerKilometer(watthourperkilometer.MegawattHoursPerKilometer).WattHoursPerKilometer, MegawattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMegawattHoursPerMeter(watthourperkilometer.MegawattHoursPerMeter).WattHoursPerKilometer, MegawattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMicrowattHoursPerKilometer(watthourperkilometer.MicrowattHoursPerKilometer).WattHoursPerKilometer, MicrowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMicrowattHoursPerMeter(watthourperkilometer.MicrowattHoursPerMeter).WattHoursPerKilometer, MicrowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMilliwattHoursPerKilometer(watthourperkilometer.MilliwattHoursPerKilometer).WattHoursPerKilometer, MilliwattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromMilliwattHoursPerMeter(watthourperkilometer.MilliwattHoursPerMeter).WattHoursPerKilometer, MilliwattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromNanowattHoursPerKilometer(watthourperkilometer.NanowattHoursPerKilometer).WattHoursPerKilometer, NanowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromNanowattHoursPerMeter(watthourperkilometer.NanowattHoursPerMeter).WattHoursPerKilometer, NanowattHoursPerMeterTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromPicowattHoursPerKilometer(watthourperkilometer.PicowattHoursPerKilometer).WattHoursPerKilometer, PicowattHoursPerKilometerTolerance); - AssertEx.EqualTolerance(1, EnergyEfficiency.FromPicowattHoursPerMeter(watthourperkilometer.PicowattHoursPerMeter).WattHoursPerKilometer, PicowattHoursPerMeterTolerance); AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerKilometer(watthourperkilometer.WattHoursPerKilometer).WattHoursPerKilometer, WattHoursPerKilometerTolerance); AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerMeter(watthourperkilometer.WattHoursPerMeter).WattHoursPerKilometer, WattHoursPerMeterTolerance); } @@ -867,8 +421,8 @@ public void CompareToThrowsOnNull() [Theory] [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.WattHourPerKilometer, true)] // Same value and unit. [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 2, EnergyEfficiencyUnit.WattHourPerKilometer, false)] // Different value. - [InlineData(2, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.FemtowattHourPerKilometer, false)] // Different value and unit. - [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.FemtowattHourPerKilometer, false)] // Different unit. + [InlineData(2, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.KilowattHourPerKilometer, false)] // Different value and unit. + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.KilowattHourPerKilometer, false)] // Different unit. public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EnergyEfficiencyUnit unitA, double valueB, EnergyEfficiencyUnit unitB, bool expectEqual) { var a = new EnergyEfficiency(valueA, unitA); @@ -958,22 +512,8 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { - Assert.Equal("1 fWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer).ToString()); - Assert.Equal("1 fWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerMeter).ToString()); - Assert.Equal("1 GWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerKilometer).ToString()); - Assert.Equal("1 GWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerMeter).ToString()); Assert.Equal("1 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString()); Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString()); - Assert.Equal("1 MWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerKilometer).ToString()); - Assert.Equal("1 MWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerMeter).ToString()); - Assert.Equal("1 µWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer).ToString()); - Assert.Equal("1 µWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerMeter).ToString()); - Assert.Equal("1 mWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer).ToString()); - Assert.Equal("1 mWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerMeter).ToString()); - Assert.Equal("1 nWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerKilometer).ToString()); - Assert.Equal("1 nWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerMeter).ToString()); - Assert.Equal("1 pWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerKilometer).ToString()); - Assert.Equal("1 pWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerMeter).ToString()); Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString()); Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).ToString()); } @@ -989,22 +529,8 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 fWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 fWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.FemtowattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 GWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 GWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.GigawattHourPerMeter).ToString(swedishCulture)); Assert.Equal("1 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString(swedishCulture)); Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 MWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 MWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MegawattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 µWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 µWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MicrowattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 mWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 mWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.MilliwattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 nWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 nWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.NanowattHourPerMeter).ToString(swedishCulture)); - Assert.Equal("1 pWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerKilometer).ToString(swedishCulture)); - Assert.Equal("1 pWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.PicowattHourPerMeter).ToString(swedishCulture)); Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString(swedishCulture)); Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).ToString(swedishCulture)); } diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs index b1fee0a398..9677b00899 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -67,22 +67,8 @@ static EnergyEfficiency() Info = new QuantityInfo("EnergyEfficiency", new UnitInfo[] { - new UnitInfo(EnergyEfficiencyUnit.FemtowattHourPerKilometer, "FemtowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.FemtowattHourPerMeter, "FemtowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.GigawattHourPerKilometer, "GigawattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.GigawattHourPerMeter, "GigawattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerKilometer, "KilowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerMeter, "KilowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MegawattHourPerKilometer, "MegawattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MegawattHourPerMeter, "MegawattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MicrowattHourPerKilometer, "MicrowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MicrowattHourPerMeter, "MicrowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MilliwattHourPerKilometer, "MilliwattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.MilliwattHourPerMeter, "MilliwattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.NanowattHourPerKilometer, "NanowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.NanowattHourPerMeter, "NanowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.PicowattHourPerKilometer, "PicowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), - new UnitInfo(EnergyEfficiencyUnit.PicowattHourPerMeter, "PicowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), new UnitInfo(EnergyEfficiencyUnit.WattHourPerKilometer, "WattHoursPerKilometer", new BaseUnits(), "EnergyEfficiency"), new UnitInfo(EnergyEfficiencyUnit.WattHourPerMeter, "WattHoursPerMeter", new BaseUnits(), "EnergyEfficiency"), }, @@ -188,26 +174,6 @@ public EnergyEfficiency(double value, UnitSystem unitSystem) #region Conversion Properties - /// - /// Gets a value of this quantity converted into - /// - public double FemtowattHoursPerKilometer => As(EnergyEfficiencyUnit.FemtowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double FemtowattHoursPerMeter => As(EnergyEfficiencyUnit.FemtowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double GigawattHoursPerKilometer => As(EnergyEfficiencyUnit.GigawattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double GigawattHoursPerMeter => As(EnergyEfficiencyUnit.GigawattHourPerMeter); - /// /// Gets a value of this quantity converted into /// @@ -218,56 +184,6 @@ public EnergyEfficiency(double value, UnitSystem unitSystem) /// public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); - /// - /// Gets a value of this quantity converted into - /// - public double MegawattHoursPerKilometer => As(EnergyEfficiencyUnit.MegawattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MegawattHoursPerMeter => As(EnergyEfficiencyUnit.MegawattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrowattHoursPerKilometer => As(EnergyEfficiencyUnit.MicrowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrowattHoursPerMeter => As(EnergyEfficiencyUnit.MicrowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double MilliwattHoursPerKilometer => As(EnergyEfficiencyUnit.MilliwattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double MilliwattHoursPerMeter => As(EnergyEfficiencyUnit.MilliwattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double NanowattHoursPerKilometer => As(EnergyEfficiencyUnit.NanowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double NanowattHoursPerMeter => As(EnergyEfficiencyUnit.NanowattHourPerMeter); - - /// - /// Gets a value of this quantity converted into - /// - public double PicowattHoursPerKilometer => As(EnergyEfficiencyUnit.PicowattHourPerKilometer); - - /// - /// Gets a value of this quantity converted into - /// - public double PicowattHoursPerMeter => As(EnergyEfficiencyUnit.PicowattHourPerMeter); - /// /// Gets a value of this quantity converted into /// @@ -289,44 +205,16 @@ public EnergyEfficiency(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: EnergyEfficiencyUnit -> BaseUnit - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.FemtowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.FemtowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.GigawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.GigawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MegawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MegawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MicrowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MicrowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MilliwattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.MilliwattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.NanowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.NanowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.PicowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.PicowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity); // Register in unit converter: BaseUnit -> EnergyEfficiencyUnit - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.FemtowattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.FemtowattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.GigawattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.GigawattHourPerMeter)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerKilometer)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MegawattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MegawattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MicrowattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MicrowattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MilliwattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.MilliwattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.NanowattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.NanowattHourPerMeter)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.PicowattHourPerKilometer)); - unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.PicowattHourPerMeter)); unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerMeter)); } @@ -355,46 +243,6 @@ public static string GetAbbreviation(EnergyEfficiencyUnit unit, IFormatProvider? #region Static Factory Methods - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromFemtowattHoursPerKilometer(QuantityValue femtowatthoursperkilometer) - { - double value = (double) femtowatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.FemtowattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromFemtowattHoursPerMeter(QuantityValue femtowatthourspermeter) - { - double value = (double) femtowatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.FemtowattHourPerMeter); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromGigawattHoursPerKilometer(QuantityValue gigawatthoursperkilometer) - { - double value = (double) gigawatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.GigawattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromGigawattHoursPerMeter(QuantityValue gigawatthourspermeter) - { - double value = (double) gigawatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.GigawattHourPerMeter); - } - /// /// Creates a from . /// @@ -415,106 +263,6 @@ public static EnergyEfficiency FromKilowattHoursPerMeter(QuantityValue kilowatth return new EnergyEfficiency(value, EnergyEfficiencyUnit.KilowattHourPerMeter); } - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMegawattHoursPerKilometer(QuantityValue megawatthoursperkilometer) - { - double value = (double) megawatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MegawattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMegawattHoursPerMeter(QuantityValue megawatthourspermeter) - { - double value = (double) megawatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MegawattHourPerMeter); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMicrowattHoursPerKilometer(QuantityValue microwatthoursperkilometer) - { - double value = (double) microwatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MicrowattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMicrowattHoursPerMeter(QuantityValue microwatthourspermeter) - { - double value = (double) microwatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MicrowattHourPerMeter); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMilliwattHoursPerKilometer(QuantityValue milliwatthoursperkilometer) - { - double value = (double) milliwatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MilliwattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromMilliwattHoursPerMeter(QuantityValue milliwatthourspermeter) - { - double value = (double) milliwatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.MilliwattHourPerMeter); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromNanowattHoursPerKilometer(QuantityValue nanowatthoursperkilometer) - { - double value = (double) nanowatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.NanowattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromNanowattHoursPerMeter(QuantityValue nanowatthourspermeter) - { - double value = (double) nanowatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.NanowattHourPerMeter); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromPicowattHoursPerKilometer(QuantityValue picowatthoursperkilometer) - { - double value = (double) picowatthoursperkilometer; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.PicowattHourPerKilometer); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static EnergyEfficiency FromPicowattHoursPerMeter(QuantityValue picowatthourspermeter) - { - double value = (double) picowatthourspermeter; - return new EnergyEfficiency(value, EnergyEfficiencyUnit.PicowattHourPerMeter); - } - /// /// Creates a from . /// @@ -1028,41 +776,13 @@ private bool TryToUnit(EnergyEfficiencyUnit unit, [NotNullWhen(true)] out Energy EnergyEfficiency? convertedOrNull = (Unit, unit) switch { // EnergyEfficiencyUnit -> BaseUnit - (EnergyEfficiencyUnit.FemtowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-15d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.FemtowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-15d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.GigawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e9d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.GigawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e9d, EnergyEfficiencyUnit.WattHourPerKilometer), (EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), (EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MegawattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e6d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MegawattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e6d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MicrowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-6d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MicrowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-6d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MilliwattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-3d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.MilliwattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-3d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.NanowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-9d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.NanowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-9d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.PicowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.PicowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e-12d, EnergyEfficiencyUnit.WattHourPerKilometer), (EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency(_value / 1e3, EnergyEfficiencyUnit.WattHourPerKilometer), // BaseUnit -> EnergyEfficiencyUnit - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-15d, EnergyEfficiencyUnit.FemtowattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.FemtowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-15d, EnergyEfficiencyUnit.FemtowattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerKilometer) => new EnergyEfficiency((_value) / 1e9d, EnergyEfficiencyUnit.GigawattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.GigawattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e9d, EnergyEfficiencyUnit.GigawattHourPerMeter), (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerKilometer), (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerKilometer) => new EnergyEfficiency((_value) / 1e6d, EnergyEfficiencyUnit.MegawattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MegawattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e6d, EnergyEfficiencyUnit.MegawattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-6d, EnergyEfficiencyUnit.MicrowattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MicrowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-6d, EnergyEfficiencyUnit.MicrowattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-3d, EnergyEfficiencyUnit.MilliwattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.MilliwattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-3d, EnergyEfficiencyUnit.MilliwattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-9d, EnergyEfficiencyUnit.NanowattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.NanowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-9d, EnergyEfficiencyUnit.NanowattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e-12d, EnergyEfficiencyUnit.PicowattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.PicowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e-12d, EnergyEfficiencyUnit.PicowattHourPerMeter), (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter) => new EnergyEfficiency(_value * 1e3, EnergyEfficiencyUnit.WattHourPerMeter), _ => null diff --git a/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext index c14c1b3fc7..a4a86243a4 100644 --- a/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext +++ b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext @@ -1,18 +1,4 @@ -FemtowattHoursPerKilometer=fWh/km -FemtowattHoursPerMeter=fWh/m -GigawattHoursPerKilometer=GWh/km -GigawattHoursPerMeter=GWh/m KilowattHoursPerKilometer=kWh/km KilowattHoursPerMeter=kWh/m -MegawattHoursPerKilometer=MWh/km -MegawattHoursPerMeter=MWh/m -MicrowattHoursPerKilometer=µWh/km -MicrowattHoursPerMeter=µWh/m -MilliwattHoursPerKilometer=mWh/km -MilliwattHoursPerMeter=mWh/m -NanowattHoursPerKilometer=nWh/km -NanowattHoursPerMeter=nWh/m -PicowattHoursPerKilometer=pWh/km -PicowattHoursPerMeter=pWh/m WattHoursPerKilometer=Wh/km WattHoursPerMeter=Wh/m diff --git a/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs index 6dc17b9e06..0fc1eafbc4 100644 --- a/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -25,22 +25,8 @@ namespace UnitsNet.Units public enum EnergyEfficiencyUnit { - FemtowattHourPerKilometer = 7, - FemtowattHourPerMeter = 9, - GigawattHourPerKilometer = 10, - GigawattHourPerMeter = 2, KilowattHourPerKilometer = 5, KilowattHourPerMeter = 3, - MegawattHourPerKilometer = 1, - MegawattHourPerMeter = 6, - MicrowattHourPerKilometer = 4, - MicrowattHourPerMeter = 8, - MilliwattHourPerKilometer = 12, - MilliwattHourPerMeter = 15, - NanowattHourPerKilometer = 11, - NanowattHourPerMeter = 16, - PicowattHourPerKilometer = 14, - PicowattHourPerMeter = 19, WattHourPerKilometer = 13, WattHourPerMeter = 20, } From 41a03316553420c0ce447e232a5baa7872568b60 Mon Sep 17 00:00:00 2001 From: Chef904 Date: Thu, 29 Aug 2024 16:04:44 +0200 Subject: [PATCH 4/7] fix: Correct unit conversion functions for EnergyEfficiency --- Common/UnitDefinitions/EnergyEfficiency.json | 4 ++-- .../GeneratedCode/Quantities/EnergyEfficiency.g.cs | 8 ++++---- UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Common/UnitDefinitions/EnergyEfficiency.json b/Common/UnitDefinitions/EnergyEfficiency.json index 617ecca5dd..0e2f3f8664 100644 --- a/Common/UnitDefinitions/EnergyEfficiency.json +++ b/Common/UnitDefinitions/EnergyEfficiency.json @@ -28,8 +28,8 @@ "BaseUnits": { "Wh/m": "WattHourPerMeter" }, - "FromUnitToBaseFunc": "{x} / 1e3", - "FromBaseToUnitFunc": "{x} * 1e3", + "FromUnitToBaseFunc": "{x} * 1e3", + "FromBaseToUnitFunc": "{x} / 1e3", "Prefixes": ["Kilo"], "Localization": [ { diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs index 86c1477029..2756af7483 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -168,9 +168,9 @@ private double GetValueInBaseUnit() return Unit switch { EnergyEfficiencyUnit.KilowattHourPerKilometer => (_value) * 1e3d, - EnergyEfficiencyUnit.KilowattHourPerMeter => (_value / 1e3) * 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (_value * 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer => _value, - EnergyEfficiencyUnit.WattHourPerMeter => _value / 1e3, + EnergyEfficiencyUnit.WattHourPerMeter => _value * 1e3, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -185,9 +185,9 @@ private double GetValueAs(EnergyEfficiencyUnit unit) return unit switch { EnergyEfficiencyUnit.KilowattHourPerKilometer => (baseUnitValue) / 1e3d, - EnergyEfficiencyUnit.KilowattHourPerMeter => (baseUnitValue * 1e3) / 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (baseUnitValue / 1e3) / 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer => baseUnitValue, - EnergyEfficiencyUnit.WattHourPerMeter => baseUnitValue * 1e3, + EnergyEfficiencyUnit.WattHourPerMeter => baseUnitValue / 1e3, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs index 9677b00899..9200a5d7e9 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -777,13 +777,13 @@ private bool TryToUnit(EnergyEfficiencyUnit unit, [NotNullWhen(true)] out Energy { // EnergyEfficiencyUnit -> BaseUnit (EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value / 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency(_value / 1e3, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value * 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency(_value * 1e3, EnergyEfficiencyUnit.WattHourPerKilometer), // BaseUnit -> EnergyEfficiencyUnit (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerKilometer), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter) => new EnergyEfficiency((_value * 1e3) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter), - (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter) => new EnergyEfficiency(_value * 1e3, EnergyEfficiencyUnit.WattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter) => new EnergyEfficiency((_value / 1e3) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter) => new EnergyEfficiency(_value / 1e3, EnergyEfficiencyUnit.WattHourPerMeter), _ => null }; From 8d90e0f542a435bb5372226ffb5c3e8c3ad39a48 Mon Sep 17 00:00:00 2001 From: Chef904 Date: Thu, 29 Aug 2024 16:21:30 +0200 Subject: [PATCH 5/7] chore: Update EnergyEfficiencyTests with unit conversions --- .../CustomCode/EnergyEfficiencyTests.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs index 5e78919e71..d04045833c 100644 --- a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs +++ b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs @@ -23,23 +23,9 @@ namespace UnitsNet.Tests.CustomCode { public class EnergyEfficiencyTests : EnergyEfficiencyTestsBase { - protected override bool SupportsSIUnitSystem => true; - protected override double FemtowattHoursPerKilometerInOneWattHourPerKilometer => 1e15; - protected override double FemtowattHoursPerMeterInOneWattHourPerKilometer => 1e12; - protected override double GigawattHoursPerKilometerInOneWattHourPerKilometer => 1e-9; - protected override double GigawattHoursPerMeterInOneWattHourPerKilometer => 1e-12; + protected override bool SupportsSIUnitSystem => false; protected override double KilowattHoursPerKilometerInOneWattHourPerKilometer => 1e-3; protected override double KilowattHoursPerMeterInOneWattHourPerKilometer => 1e-6; - protected override double MegawattHoursPerKilometerInOneWattHourPerKilometer => 1e-6; - protected override double MegawattHoursPerMeterInOneWattHourPerKilometer => 1e-9; - protected override double MicrowattHoursPerKilometerInOneWattHourPerKilometer => 1e6; - protected override double MicrowattHoursPerMeterInOneWattHourPerKilometer => 1e3; - protected override double MilliwattHoursPerKilometerInOneWattHourPerKilometer => 1e3; - protected override double MilliwattHoursPerMeterInOneWattHourPerKilometer => 1; - protected override double NanowattHoursPerKilometerInOneWattHourPerKilometer => 1e9; - protected override double NanowattHoursPerMeterInOneWattHourPerKilometer => 1e6; - protected override double PicowattHoursPerKilometerInOneWattHourPerKilometer => 1e12; - protected override double PicowattHoursPerMeterInOneWattHourPerKilometer => 1e9; protected override double WattHoursPerKilometerInOneWattHourPerKilometer => 1; protected override double WattHoursPerMeterInOneWattHourPerKilometer => 1e-3; } From 6601b61d6f3e477b32b423a29b3afe0207702923 Mon Sep 17 00:00:00 2001 From: Chef904 Date: Wed, 11 Sep 2024 11:50:21 +0200 Subject: [PATCH 6/7] Remove .DS_Store from everywhere --- .DS_Store | Bin 6148 -> 0 bytes Common/.DS_Store | Bin 6148 -> 0 bytes UnitsNet/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 Common/.DS_Store delete mode 100644 UnitsNet/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index b99db7d0ef16290d7bf4aeb85ae500e1ca33ac17..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c^3>-s*BGIIz++W}iRw1-Bh#o;GkV39V=&$0t_%y~3A)*Tf1r3ZNdv<-E zUELJt7=SHb*O$Noz?|-gHxEF{(We4$6h!l z#;1cJMgZcB=`gNimLN7y5PRX6$PCSrN=&NNh+#=*zExc>921ici<@~)-E1|XSlrHh zi*i^`RFncz;820n+%CNTU(>&t{|`ypNdYPFrxdW+>UOo{D^+iuyqx#iM!%!2`1J0?au=EmFcMHFRS^EIFM!Z9)E%m0wXR|QTzhxC;NedYbk=I8KWx(;#Nc= zfiadr0Xn;NacWL16JO6S!x?I{r@=UV3Su3=^DTIaqcm%^-esX!T3IavweppJug8AY z&qisdKfIt{CtAnBtlkgKqQSUV-#FAs){m0G&;&%`04|s3Q4;ELM~{*)HLXXLcc;^8rLnbraNK){9~1pzb(Z)94b~jb=oOVYTMW~iIKYx= zh&is${xFGkatF`ZgtLj5Spimn6<8Jp-2GLlEz5#=ovZ*WurLMaeo!!C&v9a&v9E<=%Kc8sr# zyO5q`E?EIq;JX5p`vG-&|BwF8|BVwDtN<(UKNXOruHWroZ|-gVu}gYu73>;DAiv!5 lX9z0hDTXgS#hWk#v@5EBJ;%9av;h1^z{tP_E3i-nJ^*%`T37%8 diff --git a/UnitsNet/.DS_Store b/UnitsNet/.DS_Store deleted file mode 100644 index 83158d0b147bd9e2307db67d535fe81c6379bcee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyH3ME5S)V)5eO+I<^2MGa0-d?0sH_DrwdpjN$-x|X7)kk$f2b`v(n!9_I7UN zDZE|)WqIr#fCYd#-4I{4OwG>CCw7$)!{T@Jc*i4pbl6U^F9(c!L(UO<9LPNJyZzhl zweNREyTgVTe$YSh!n7?5WSMc=Q0VyB_q<|EV0%HZ(v(4tWfm)@26p#WZ1?>A! z>4q(F2=q?}7aswLGlt#x?6U;1T7cLRhd@SXC8)%pmK-rk&>63p*Aj=oprd$Y-jkI} zPAJ8zGhRI%r3Gr00#e{yf$P{VtpBg+zs&#VB<-Yt6!=#Pl-cTOwd5;hZ=JlH_1a2* srvDgoJ)MiUVxqTVZmbpGkMgQL^SmVvflg=K=|ueqm@YCY@D~bv1Dt6b;{X5v From e06fc223f8df3de687964a1463b742ed0745b0ca Mon Sep 17 00:00:00 2001 From: Chef904 Date: Wed, 11 Sep 2024 11:51:20 +0200 Subject: [PATCH 7/7] Remove .DS_Store from everywhere --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2e6ebec7d0..729a9f42b0 100644 --- a/.gitignore +++ b/.gitignore @@ -259,3 +259,6 @@ Artifacts # Build server tooling /secure-file /.tools/ + +# Mac files +**/.DS_Store \ No newline at end of file