Skip to content

Commit

Permalink
Add a few new units and new prefixes for existing units. (#291)
Browse files Browse the repository at this point in the history
* Add Therm unit
* Add new prefixes and a few abbreviations for russian culture.
* Add test and some prefixes abbreviations for pound. Misplaced code removed
* Add improved name scheme
* Add 'TonPerHour' unit and tests
* Update for ThermsEC
* Add 'BTU/hr' unit of measure.
* Add 'cf/hr' Unit of measure.
  • Loading branch information
DInozemtsev authored and Andreas Gullberg Larsen committed Oct 3, 2017
1 parent 554d548 commit 83aeaca
Show file tree
Hide file tree
Showing 37 changed files with 1,682 additions and 4 deletions.
6 changes: 6 additions & 0 deletions UnitsNet.Tests/CustomCode/EnergyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public class EnergyTests : EnergyTestsBase

protected override double JoulesInOneJoule => 1;

protected override double KilobritishThermalUnitsInOneJoule => 9.4781339449889105832843629746176e-7;

protected override double KilojoulesInOneJoule => 1E-3;

protected override double MegabritishThermalUnitsInOneJoule => 9.4781339449889105832843629746176e-10;

protected override double MegajoulesInOneJoule => 1E-6;

protected override double BritishThermalUnitsInOneJoule => 0.00094781712;
Expand All @@ -50,6 +54,8 @@ public class EnergyTests : EnergyTestsBase

protected override double FootPoundsInOneJoule => 0.737562149;

protected override double GigabritishThermalUnitsInOneJoule => 9.4781339449889105832843629746176e-13;

protected override double GigawattHoursInOneJoule => 2.77777778e-13;

protected override double KilocaloriesInOneJoule => 0.00023900573614;
Expand Down
2 changes: 2 additions & 0 deletions UnitsNet.Tests/CustomCode/FlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class FlowTests : FlowTestsBase

protected override double CubicDecimetersPerMinuteInOneCubicMeterPerSecond => 60000.00000;

protected override double CubicFeetPerHourInOneCubicMeterPerSecond => 1.2713300937959091422759633856933e+5;

protected override double CubicFeetPerSecondInOneCubicMeterPerSecond => 35.314666213;

protected override double MillionUsGallonsPerDayInOneCubicMeterPerSecond => 22.824465227;
Expand Down
4 changes: 4 additions & 0 deletions UnitsNet.Tests/CustomCode/MassFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class MassFlowTests : MassFlowTestsBase

protected override double KilogramsPerSecondInOneGramPerSecond => 1E-3;

protected override double MegapoundsPerHourInOneGramPerSecond => 7.93664e-6;

protected override double DecigramsPerSecondInOneGramPerSecond => 1E1;

protected override double CentigramsPerSecondInOneGramPerSecond => 1E2;
Expand All @@ -46,6 +48,8 @@ public class MassFlowTests : MassFlowTestsBase

protected override double NanogramsPerSecondInOneGramPerSecond => 1E9;

protected override double ShortTonsPerHourInOneGramPerSecond => 3.96832e-3;

protected override double TonnesPerDayInOneGramPerSecond => 60.0*60*24/1E6;

protected override double PoundsPerHourInOneGramPerSecond => 7.93664;
Expand Down
4 changes: 4 additions & 0 deletions UnitsNet.Tests/CustomCode/MassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ public class MassTests : MassTestsBase

protected override double KilogramsInOneKilogram => 1;

protected override double KilopoundsInOneKilogram => 2.2046226218487757e-3;

protected override double KilotonnesInOneKilogram => 1E-6;

protected override double LongTonsInOneKilogram => 0.000984207;

protected override double MegapoundsInOneKilogram => 2.2046226218487757e-6;

protected override double MegatonnesInOneKilogram => 1E-6;

protected override double MicrogramsInOneKilogram => 1E9;
Expand Down
3 changes: 3 additions & 0 deletions UnitsNet.Tests/CustomCode/PowerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class PowerTests : PowerTestsBase

protected override double WattsInOneWatt => 1;

protected override double KilobritishThermalUnitsPerHourInOneWatt => 3.412141633e-3;

protected override double KilowattsInOneWatt => 1e-3;

protected override double MegawattsInOneWatt => 1e-6;
Expand All @@ -49,6 +51,7 @@ public class PowerTests : PowerTestsBase
protected override double PetawattsInOneWatt => 1e-15;

protected override double BoilerHorsepowerInOneWatt => 1.0191082802547770700636942675159e-4;
protected override double BritishThermalUnitsPerHourInOneWatt => 3.412141633;

protected override double ElectricalHorsepowerInOneWatt => 0.00134048257372654155495978552279;

Expand Down
10 changes: 10 additions & 0 deletions UnitsNet.Tests/CustomCode/VolumeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ public class VolumeTests : VolumeTestsBase
protected override double CubicYardsInOneCubicMeter => 1.30795062;

protected override double DecilitersInOneCubicMeter => 1E4;
protected override double HectocubicFeetInOneCubicMeter => 3.531472e-1;
protected override double HectocubicMetersInOneCubicMeter => 0.01;

protected override double HectolitersInOneCubicMeter => 1E1;

protected override double ImperialGallonsInOneCubicMeter => 219.96924;

protected override double ImperialOuncesInOneCubicMeter => 35195.07972;

protected override double KilocubicFeetInOneCubicMeter => 3.531472e-2;
protected override double KilocubicMetersInOneCubicMeter => 0.001;
protected override double KiloimperialGallonsInOneCubicMeter => 2.1996924e-1;
protected override double KilousGallonsInOneCubicMeter => 2.6417217e-1;

protected override double LitersInOneCubicMeter => 1E3;
protected override double MegacubicFeetInOneCubicMeter => 3.531472e-5;
protected override double MegaimperialGallonsInOneCubicMeter => 2.1996924e-4;
protected override double MegausGallonsInOneCubicMeter => 2.6417217e-4;

protected override double MicrolitersInOneCubicMeter => 1E9;

Expand Down
18 changes: 18 additions & 0 deletions UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ public abstract partial class EnergyTestsBase
protected abstract double ElectronVoltsInOneJoule { get; }
protected abstract double ErgsInOneJoule { get; }
protected abstract double FootPoundsInOneJoule { get; }
protected abstract double GigabritishThermalUnitsInOneJoule { get; }
protected abstract double GigawattHoursInOneJoule { get; }
protected abstract double JoulesInOneJoule { get; }
protected abstract double KilobritishThermalUnitsInOneJoule { get; }
protected abstract double KilocaloriesInOneJoule { get; }
protected abstract double KilojoulesInOneJoule { get; }
protected abstract double KilowattHoursInOneJoule { get; }
protected abstract double MegabritishThermalUnitsInOneJoule { get; }
protected abstract double MegajoulesInOneJoule { get; }
protected abstract double MegawattHoursInOneJoule { get; }
protected abstract double ThermsEcInOneJoule { get; }
Expand All @@ -81,11 +84,14 @@ public abstract partial class EnergyTestsBase
protected virtual double ElectronVoltsTolerance { get { return 1e-5; } }
protected virtual double ErgsTolerance { get { return 1e-5; } }
protected virtual double FootPoundsTolerance { get { return 1e-5; } }
protected virtual double GigabritishThermalUnitsTolerance { get { return 1e-5; } }
protected virtual double GigawattHoursTolerance { get { return 1e-5; } }
protected virtual double JoulesTolerance { get { return 1e-5; } }
protected virtual double KilobritishThermalUnitsTolerance { get { return 1e-5; } }
protected virtual double KilocaloriesTolerance { get { return 1e-5; } }
protected virtual double KilojoulesTolerance { get { return 1e-5; } }
protected virtual double KilowattHoursTolerance { get { return 1e-5; } }
protected virtual double MegabritishThermalUnitsTolerance { get { return 1e-5; } }
protected virtual double MegajoulesTolerance { get { return 1e-5; } }
protected virtual double MegawattHoursTolerance { get { return 1e-5; } }
protected virtual double ThermsEcTolerance { get { return 1e-5; } }
Expand All @@ -106,11 +112,14 @@ public void JouleToEnergyUnits()
AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.ElectronVolts, ElectronVoltsTolerance);
AssertEx.EqualTolerance(ErgsInOneJoule, joule.Ergs, ErgsTolerance);
AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.FootPounds, FootPoundsTolerance);
AssertEx.EqualTolerance(GigabritishThermalUnitsInOneJoule, joule.GigabritishThermalUnits, GigabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(GigawattHoursInOneJoule, joule.GigawattHours, GigawattHoursTolerance);
AssertEx.EqualTolerance(JoulesInOneJoule, joule.Joules, JoulesTolerance);
AssertEx.EqualTolerance(KilobritishThermalUnitsInOneJoule, joule.KilobritishThermalUnits, KilobritishThermalUnitsTolerance);
AssertEx.EqualTolerance(KilocaloriesInOneJoule, joule.Kilocalories, KilocaloriesTolerance);
AssertEx.EqualTolerance(KilojoulesInOneJoule, joule.Kilojoules, KilojoulesTolerance);
AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.KilowattHours, KilowattHoursTolerance);
AssertEx.EqualTolerance(MegabritishThermalUnitsInOneJoule, joule.MegabritishThermalUnits, MegabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.Megajoules, MegajoulesTolerance);
AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.MegawattHours, MegawattHoursTolerance);
AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.ThermsEc, ThermsEcTolerance);
Expand All @@ -130,11 +139,14 @@ public void FromValueAndUnit()
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ElectronVolt).ElectronVolts, ElectronVoltsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Erg).Ergs, ErgsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.FootPound).FootPounds, FootPoundsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigabritishThermalUnit).GigabritishThermalUnits, GigabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigawattHour).GigawattHours, GigawattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Joule).Joules, JoulesTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilobritishThermalUnit).KilobritishThermalUnits, KilobritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilocalorie).Kilocalories, KilocaloriesTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilojoule).Kilojoules, KilojoulesTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilowattHour).KilowattHours, KilowattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegabritishThermalUnit).MegabritishThermalUnits, MegabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Megajoule).Megajoules, MegajoulesTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegawattHour).MegawattHours, MegawattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermEc).ThermsEc, ThermsEcTolerance);
Expand All @@ -155,11 +167,14 @@ public void As()
AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.As(EnergyUnit.ElectronVolt), ElectronVoltsTolerance);
AssertEx.EqualTolerance(ErgsInOneJoule, joule.As(EnergyUnit.Erg), ErgsTolerance);
AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.As(EnergyUnit.FootPound), FootPoundsTolerance);
AssertEx.EqualTolerance(GigabritishThermalUnitsInOneJoule, joule.As(EnergyUnit.GigabritishThermalUnit), GigabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(GigawattHoursInOneJoule, joule.As(EnergyUnit.GigawattHour), GigawattHoursTolerance);
AssertEx.EqualTolerance(JoulesInOneJoule, joule.As(EnergyUnit.Joule), JoulesTolerance);
AssertEx.EqualTolerance(KilobritishThermalUnitsInOneJoule, joule.As(EnergyUnit.KilobritishThermalUnit), KilobritishThermalUnitsTolerance);
AssertEx.EqualTolerance(KilocaloriesInOneJoule, joule.As(EnergyUnit.Kilocalorie), KilocaloriesTolerance);
AssertEx.EqualTolerance(KilojoulesInOneJoule, joule.As(EnergyUnit.Kilojoule), KilojoulesTolerance);
AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.As(EnergyUnit.KilowattHour), KilowattHoursTolerance);
AssertEx.EqualTolerance(MegabritishThermalUnitsInOneJoule, joule.As(EnergyUnit.MegabritishThermalUnit), MegabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.As(EnergyUnit.Megajoule), MegajoulesTolerance);
AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.As(EnergyUnit.MegawattHour), MegawattHoursTolerance);
AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.As(EnergyUnit.ThermEc), ThermsEcTolerance);
Expand All @@ -180,11 +195,14 @@ public void ConversionRoundTrip()
AssertEx.EqualTolerance(1, Energy.FromElectronVolts(joule.ElectronVolts).Joules, ElectronVoltsTolerance);
AssertEx.EqualTolerance(1, Energy.FromErgs(joule.Ergs).Joules, ErgsTolerance);
AssertEx.EqualTolerance(1, Energy.FromFootPounds(joule.FootPounds).Joules, FootPoundsTolerance);
AssertEx.EqualTolerance(1, Energy.FromGigabritishThermalUnits(joule.GigabritishThermalUnits).Joules, GigabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.FromGigawattHours(joule.GigawattHours).Joules, GigawattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.FromJoules(joule.Joules).Joules, JoulesTolerance);
AssertEx.EqualTolerance(1, Energy.FromKilobritishThermalUnits(joule.KilobritishThermalUnits).Joules, KilobritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.FromKilocalories(joule.Kilocalories).Joules, KilocaloriesTolerance);
AssertEx.EqualTolerance(1, Energy.FromKilojoules(joule.Kilojoules).Joules, KilojoulesTolerance);
AssertEx.EqualTolerance(1, Energy.FromKilowattHours(joule.KilowattHours).Joules, KilowattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.FromMegabritishThermalUnits(joule.MegabritishThermalUnits).Joules, MegabritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.FromMegajoules(joule.Megajoules).Joules, MegajoulesTolerance);
AssertEx.EqualTolerance(1, Energy.FromMegawattHours(joule.MegawattHours).Joules, MegawattHoursTolerance);
AssertEx.EqualTolerance(1, Energy.FromThermsEc(joule.ThermsEc).Joules, ThermsEcTolerance);
Expand Down
6 changes: 6 additions & 0 deletions UnitsNet.Tests/GeneratedCode/FlowTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract partial class FlowTestsBase
{
protected abstract double CentilitersPerMinuteInOneCubicMeterPerSecond { get; }
protected abstract double CubicDecimetersPerMinuteInOneCubicMeterPerSecond { get; }
protected abstract double CubicFeetPerHourInOneCubicMeterPerSecond { get; }
protected abstract double CubicFeetPerSecondInOneCubicMeterPerSecond { get; }
protected abstract double CubicMetersPerHourInOneCubicMeterPerSecond { get; }
protected abstract double CubicMetersPerSecondInOneCubicMeterPerSecond { get; }
Expand All @@ -72,6 +73,7 @@ public abstract partial class FlowTestsBase
// ReSharper disable VirtualMemberNeverOverriden.Global
protected virtual double CentilitersPerMinuteTolerance { get { return 1e-5; } }
protected virtual double CubicDecimetersPerMinuteTolerance { get { return 1e-5; } }
protected virtual double CubicFeetPerHourTolerance { get { return 1e-5; } }
protected virtual double CubicFeetPerSecondTolerance { get { return 1e-5; } }
protected virtual double CubicMetersPerHourTolerance { get { return 1e-5; } }
protected virtual double CubicMetersPerSecondTolerance { get { return 1e-5; } }
Expand All @@ -94,6 +96,7 @@ public void CubicMeterPerSecondToFlowUnits()
Flow cubicmeterpersecond = Flow.FromCubicMetersPerSecond(1);
AssertEx.EqualTolerance(CentilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CentilitersPerMinute, CentilitersPerMinuteTolerance);
AssertEx.EqualTolerance(CubicDecimetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance);
AssertEx.EqualTolerance(CubicFeetPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.CubicFeetPerHour, CubicFeetPerHourTolerance);
AssertEx.EqualTolerance(CubicFeetPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.CubicFeetPerSecond, CubicFeetPerSecondTolerance);
AssertEx.EqualTolerance(CubicMetersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.CubicMetersPerHour, CubicMetersPerHourTolerance);
AssertEx.EqualTolerance(CubicMetersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.CubicMetersPerSecond, CubicMetersPerSecondTolerance);
Expand All @@ -115,6 +118,7 @@ public void FromValueAndUnit()
{
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CentilitersPerMinute).CentilitersPerMinute, CentilitersPerMinuteTolerance);
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CubicDecimeterPerMinute).CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance);
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CubicFootPerHour).CubicFeetPerHour, CubicFeetPerHourTolerance);
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CubicFootPerSecond).CubicFeetPerSecond, CubicFeetPerSecondTolerance);
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CubicMeterPerHour).CubicMetersPerHour, CubicMetersPerHourTolerance);
AssertEx.EqualTolerance(1, Flow.From(1, FlowUnit.CubicMeterPerSecond).CubicMetersPerSecond, CubicMetersPerSecondTolerance);
Expand All @@ -137,6 +141,7 @@ public void As()
var cubicmeterpersecond = Flow.FromCubicMetersPerSecond(1);
AssertEx.EqualTolerance(CentilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CentilitersPerMinute), CentilitersPerMinuteTolerance);
AssertEx.EqualTolerance(CubicDecimetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CubicDecimeterPerMinute), CubicDecimetersPerMinuteTolerance);
AssertEx.EqualTolerance(CubicFeetPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CubicFootPerHour), CubicFeetPerHourTolerance);
AssertEx.EqualTolerance(CubicFeetPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CubicFootPerSecond), CubicFeetPerSecondTolerance);
AssertEx.EqualTolerance(CubicMetersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CubicMeterPerHour), CubicMetersPerHourTolerance);
AssertEx.EqualTolerance(CubicMetersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(FlowUnit.CubicMeterPerSecond), CubicMetersPerSecondTolerance);
Expand All @@ -159,6 +164,7 @@ public void ConversionRoundTrip()
Flow cubicmeterpersecond = Flow.FromCubicMetersPerSecond(1);
AssertEx.EqualTolerance(1, Flow.FromCentilitersPerMinute(cubicmeterpersecond.CentilitersPerMinute).CubicMetersPerSecond, CentilitersPerMinuteTolerance);
AssertEx.EqualTolerance(1, Flow.FromCubicDecimetersPerMinute(cubicmeterpersecond.CubicDecimetersPerMinute).CubicMetersPerSecond, CubicDecimetersPerMinuteTolerance);
AssertEx.EqualTolerance(1, Flow.FromCubicFeetPerHour(cubicmeterpersecond.CubicFeetPerHour).CubicMetersPerSecond, CubicFeetPerHourTolerance);
AssertEx.EqualTolerance(1, Flow.FromCubicFeetPerSecond(cubicmeterpersecond.CubicFeetPerSecond).CubicMetersPerSecond, CubicFeetPerSecondTolerance);
AssertEx.EqualTolerance(1, Flow.FromCubicMetersPerHour(cubicmeterpersecond.CubicMetersPerHour).CubicMetersPerSecond, CubicMetersPerHourTolerance);
AssertEx.EqualTolerance(1, Flow.FromCubicMetersPerSecond(cubicmeterpersecond.CubicMetersPerSecond).CubicMetersPerSecond, CubicMetersPerSecondTolerance);
Expand Down
Loading

0 comments on commit 83aeaca

Please sign in to comment.