Skip to content

Add US Therm, EU Therm and UK Therm #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions UnitsNet.Tests/CustomCode/EnergyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace UnitsNet.Tests.CustomCode
public class EnergyTests : EnergyTestsBase
{
// TODO Override properties in base class here
protected override double ThermsImperialInOneJoule => 9.478171203551087813109937767482e-15;

protected override double JoulesInOneJoule => 1;

protected override double KilojoulesInOneJoule => 1E-3;
Expand All @@ -34,10 +36,18 @@ public class EnergyTests : EnergyTestsBase

protected override double CaloriesInOneJoule => 0.239005736;

protected override double DecathermsEcInOneJoule => 9.47816988e-10;

protected override double DecathermsImperialInOneJoule => 9.478171203551087813109937767482e-15;

protected override double DecathermsUsInOneJoule => 9.4804342797334860315281322406817e-10;

protected override double ElectronVoltsInOneJoule => 6.241509343260179e18;

protected override double ErgsInOneJoule => 10000000;

protected override double ThermsEcInOneJoule => 9.4781712031331720001278504447561e-9;

protected override double FootPoundsInOneJoule => 0.737562149;

protected override double GigawattHoursInOneJoule => 2.77777778e-13;
Expand All @@ -48,6 +58,8 @@ public class EnergyTests : EnergyTestsBase

protected override double MegawattHoursInOneJoule => 2.77777778e-10;

protected override double ThermsUsInOneJoule => 9.4804342797334860315281322406817e-9;

protected override double WattHoursInOneJoule => 0.000277777778;
}
}
36 changes: 36 additions & 0 deletions UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public abstract partial class EnergyTestsBase
{
protected abstract double BritishThermalUnitsInOneJoule { get; }
protected abstract double CaloriesInOneJoule { get; }
protected abstract double DecathermsEcInOneJoule { get; }
protected abstract double DecathermsImperialInOneJoule { get; }
protected abstract double DecathermsUsInOneJoule { get; }
protected abstract double ElectronVoltsInOneJoule { get; }
protected abstract double ErgsInOneJoule { get; }
protected abstract double FootPoundsInOneJoule { get; }
Expand All @@ -64,11 +67,17 @@ public abstract partial class EnergyTestsBase
protected abstract double KilowattHoursInOneJoule { get; }
protected abstract double MegajoulesInOneJoule { get; }
protected abstract double MegawattHoursInOneJoule { get; }
protected abstract double ThermsEcInOneJoule { get; }
protected abstract double ThermsImperialInOneJoule { get; }
protected abstract double ThermsUsInOneJoule { get; }
protected abstract double WattHoursInOneJoule { get; }

// ReSharper disable VirtualMemberNeverOverriden.Global
protected virtual double BritishThermalUnitsTolerance { get { return 1e-5; } }
protected virtual double CaloriesTolerance { get { return 1e-5; } }
protected virtual double DecathermsEcTolerance { get { return 1e-5; } }
protected virtual double DecathermsImperialTolerance { get { return 1e-5; } }
protected virtual double DecathermsUsTolerance { get { return 1e-5; } }
protected virtual double ElectronVoltsTolerance { get { return 1e-5; } }
protected virtual double ErgsTolerance { get { return 1e-5; } }
protected virtual double FootPoundsTolerance { get { return 1e-5; } }
Expand All @@ -79,6 +88,9 @@ public abstract partial class EnergyTestsBase
protected virtual double KilowattHoursTolerance { 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; } }
protected virtual double ThermsImperialTolerance { get { return 1e-5; } }
protected virtual double ThermsUsTolerance { get { return 1e-5; } }
protected virtual double WattHoursTolerance { get { return 1e-5; } }
// ReSharper restore VirtualMemberNeverOverriden.Global

Expand All @@ -88,6 +100,9 @@ public void JouleToEnergyUnits()
Energy joule = Energy.FromJoules(1);
AssertEx.EqualTolerance(BritishThermalUnitsInOneJoule, joule.BritishThermalUnits, BritishThermalUnitsTolerance);
AssertEx.EqualTolerance(CaloriesInOneJoule, joule.Calories, CaloriesTolerance);
AssertEx.EqualTolerance(DecathermsEcInOneJoule, joule.DecathermsEc, DecathermsEcTolerance);
AssertEx.EqualTolerance(DecathermsImperialInOneJoule, joule.DecathermsImperial, DecathermsImperialTolerance);
AssertEx.EqualTolerance(DecathermsUsInOneJoule, joule.DecathermsUs, DecathermsUsTolerance);
AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.ElectronVolts, ElectronVoltsTolerance);
AssertEx.EqualTolerance(ErgsInOneJoule, joule.Ergs, ErgsTolerance);
AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.FootPounds, FootPoundsTolerance);
Expand All @@ -98,6 +113,9 @@ public void JouleToEnergyUnits()
AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.KilowattHours, KilowattHoursTolerance);
AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.Megajoules, MegajoulesTolerance);
AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.MegawattHours, MegawattHoursTolerance);
AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.ThermsEc, ThermsEcTolerance);
AssertEx.EqualTolerance(ThermsImperialInOneJoule, joule.ThermsImperial, ThermsImperialTolerance);
AssertEx.EqualTolerance(ThermsUsInOneJoule, joule.ThermsUs, ThermsUsTolerance);
AssertEx.EqualTolerance(WattHoursInOneJoule, joule.WattHours, WattHoursTolerance);
}

Expand All @@ -106,6 +124,9 @@ public void FromValueAndUnit()
{
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.BritishThermalUnit).BritishThermalUnits, BritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Calorie).Calories, CaloriesTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermEc).DecathermsEc, DecathermsEcTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermImperial).DecathermsImperial, DecathermsImperialTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermUs).DecathermsUs, DecathermsUsTolerance);
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);
Expand All @@ -116,6 +137,9 @@ public void FromValueAndUnit()
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilowattHour).KilowattHours, KilowattHoursTolerance);
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);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermImperial).ThermsImperial, ThermsImperialTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermUs).ThermsUs, ThermsUsTolerance);
AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.WattHour).WattHours, WattHoursTolerance);
}

Expand All @@ -125,6 +149,9 @@ public void As()
var joule = Energy.FromJoules(1);
AssertEx.EqualTolerance(BritishThermalUnitsInOneJoule, joule.As(EnergyUnit.BritishThermalUnit), BritishThermalUnitsTolerance);
AssertEx.EqualTolerance(CaloriesInOneJoule, joule.As(EnergyUnit.Calorie), CaloriesTolerance);
AssertEx.EqualTolerance(DecathermsEcInOneJoule, joule.As(EnergyUnit.DecathermEc), DecathermsEcTolerance);
AssertEx.EqualTolerance(DecathermsImperialInOneJoule, joule.As(EnergyUnit.DecathermImperial), DecathermsImperialTolerance);
AssertEx.EqualTolerance(DecathermsUsInOneJoule, joule.As(EnergyUnit.DecathermUs), DecathermsUsTolerance);
AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.As(EnergyUnit.ElectronVolt), ElectronVoltsTolerance);
AssertEx.EqualTolerance(ErgsInOneJoule, joule.As(EnergyUnit.Erg), ErgsTolerance);
AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.As(EnergyUnit.FootPound), FootPoundsTolerance);
Expand All @@ -135,6 +162,9 @@ public void As()
AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.As(EnergyUnit.KilowattHour), KilowattHoursTolerance);
AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.As(EnergyUnit.Megajoule), MegajoulesTolerance);
AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.As(EnergyUnit.MegawattHour), MegawattHoursTolerance);
AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.As(EnergyUnit.ThermEc), ThermsEcTolerance);
AssertEx.EqualTolerance(ThermsImperialInOneJoule, joule.As(EnergyUnit.ThermImperial), ThermsImperialTolerance);
AssertEx.EqualTolerance(ThermsUsInOneJoule, joule.As(EnergyUnit.ThermUs), ThermsUsTolerance);
AssertEx.EqualTolerance(WattHoursInOneJoule, joule.As(EnergyUnit.WattHour), WattHoursTolerance);
}

Expand All @@ -144,6 +174,9 @@ public void ConversionRoundTrip()
Energy joule = Energy.FromJoules(1);
AssertEx.EqualTolerance(1, Energy.FromBritishThermalUnits(joule.BritishThermalUnits).Joules, BritishThermalUnitsTolerance);
AssertEx.EqualTolerance(1, Energy.FromCalories(joule.Calories).Joules, CaloriesTolerance);
AssertEx.EqualTolerance(1, Energy.FromDecathermsEc(joule.DecathermsEc).Joules, DecathermsEcTolerance);
AssertEx.EqualTolerance(1, Energy.FromDecathermsImperial(joule.DecathermsImperial).Joules, DecathermsImperialTolerance);
AssertEx.EqualTolerance(1, Energy.FromDecathermsUs(joule.DecathermsUs).Joules, DecathermsUsTolerance);
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);
Expand All @@ -154,6 +187,9 @@ public void ConversionRoundTrip()
AssertEx.EqualTolerance(1, Energy.FromKilowattHours(joule.KilowattHours).Joules, KilowattHoursTolerance);
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);
AssertEx.EqualTolerance(1, Energy.FromThermsImperial(joule.ThermsImperial).Joules, ThermsImperialTolerance);
AssertEx.EqualTolerance(1, Energy.FromThermsUs(joule.ThermsUs).Joules, ThermsUsTolerance);
AssertEx.EqualTolerance(1, Energy.FromWattHours(joule.WattHours).Joules, WattHoursTolerance);
}

Expand Down
6 changes: 6 additions & 0 deletions UnitsNet/GeneratedCode/Enums/EnergyUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public enum EnergyUnit
Undefined = 0,
BritishThermalUnit,
Calorie,
DecathermEc,
DecathermImperial,
DecathermUs,
ElectronVolt,
Erg,
FootPound,
Expand All @@ -54,6 +57,9 @@ public enum EnergyUnit
KilowattHour,
Megajoule,
MegawattHour,
ThermEc,
ThermImperial,
ThermUs,
WattHour,
}
}
Loading