diff --git a/ph_units/unit_types/energy.py b/ph_units/unit_types/energy.py index f96664e..4e62666 100644 --- a/ph_units/unit_types/energy.py +++ b/ph_units/unit_types/energy.py @@ -8,14 +8,16 @@ class WattHour(Base_UnitType): """Wh""" __symbol__ = "WH" - __aliases__ = [] + __aliases__ = ["WATT-HOUR", "WATT-HOURS", "WHR"] __factors__ = { - "WH": "{}*1", - "KWH": "{}*0.001", "BTU": "{}*3.41214", "KBTU": "{}*0.00341214", - "MJ": "{}*0.0036", + "WH": "{}*1", + "KWH": "{}*0.001", + "J": "{}*3600", "KJ": "{}*3.6", + "MJ": "{}*0.0036", + "GJ": "{}*0.0000036", } @@ -23,14 +25,16 @@ class KiloWattHour(Base_UnitType): """KWH""" __symbol__ = "KWH" - __aliases__ = ["KWH/YR", "KWH/A", "KWH/M", "KWH/MONTH"] + __aliases__ = ["KWHR", "KWH/YR", "KWH/A", "KWH/M", "KWH/MONTH"] __factors__ = { - "WH": "{}*1000", - "KWH": "{}*1", "BTU": "{}*3412.14", "KBTU": "{}*3.41214", - "MJ": "{}*3.6", + "WH": "{}*1000", + "KWH": "{}*1", + "J": "{}*3600000", "KJ": "{}*3600", + "MJ": "{}*3.6", + "GJ": "{}*0.0036", } @@ -40,12 +44,14 @@ class BTU(Base_UnitType): __symbol__ = "BTU" __aliases__ = [] __factors__ = { - "WH": "{}*0.293071", - "KWH": "{}*0.000293071", "BTU": "{}*1", "KBTU": "{}*0.001", - "MJ": "{}*0.00105506", + "WH": "{}*0.293071", + "KWH": "{}*0.000293071", + "J": "{}*1055.06", "KJ": "{}*1.05506", + "MJ": "{}*0.00105506", + "GJ": "{}*0.00000105506", } @@ -55,27 +61,31 @@ class KiloBTU(Base_UnitType): __symbol__ = "KBTU" __aliases__ = [] __factors__ = { - "WH": "{}*293.071", - "KWH": "{}*0.293071", "BTU": "{}*1000", "KBTU": "{}*1", - "MJ": "{}*1.05506", + "WH": "{}*293.071", + "KWH": "{}*0.293071", + "J": "{}*1055060", "KJ": "{}*1055.06", + "MJ": "{}*1.05506", + "GJ": "{}*0.00105506", } -class MegaJoule(Base_UnitType): - """MJ""" +class Joule(Base_UnitType): + """J""" - __symbol__ = "MJ" - __aliases__ = [] + __symbol__ = "J" + __aliases__ = ["JOULE"] __factors__ = { - "WH": "{}*277.778", - "KWH": "{}*0.277778", - "BTU": "{}*947.817", - "KBTU": "{}*0.947817", - "MJ": "{}*1", - "KJ": "{}*1000", + "BTU": "{}*0.000947817", + "KBTU": "{}*0.000000947817", + "WH": "{}*0.000277778", + "KWH": "{}*0.00000027778 ", + "J": "{}*1", + "KJ": "{}*0.001", + "MJ": "{}*0.000001", + "GJ": "{}*0.000000001", } @@ -83,14 +93,50 @@ class KiloJoule(Base_UnitType): """KJ""" __symbol__ = "KJ" - __aliases__ = [] + __aliases__ = ["KILOJOULE"] __factors__ = { - "WH": "{}*0.277778", - "KWH": "{}*0.000277778", "BTU": "{}*0.947817", "KBTU": "{}*0.000947817", - "MJ": "{}*0.001", + "WH": "{}*0.277778", + "KWH": "{}*0.000277778", + "J": "{}*1000", "KJ": "{}*1", + "MJ": "{}*0.001", + "GJ": "{}*0.000001", + } + + +class MegaJoule(Base_UnitType): + """MJ""" + + __symbol__ = "MJ" + __aliases__ = ["MEGAJOULE"] + __factors__ = { + "BTU": "{}*947.817", + "KBTU": "{}*0.947817", + "WH": "{}*277.778", + "KWH": "{}*0.277778", + "J": "{}*1000000", + "KJ": "{}*1000", + "MJ": "{}*1", + "GJ": "{}*0.001", + } + + +class GigaJoule(Base_UnitType): + """GJ""" + + __symbol__ = "GJ" + __aliases__ = ["GIGAJOULE"] + __factors__ = { + "BTU": "{}*947817.120313", + "KBTU": "{}*947.817120313", + "WH": "{}*277777.778", + "KWH": "{}*277.778", + "J": "{}*1000000000", + "KJ": "{}*1000000", + "MJ": "{}*1000", + "GJ": "{}*1", } diff --git a/tests/test_energy.py b/tests/test_energy.py index ab710cd..64c70f7 100644 --- a/tests/test_energy.py +++ b/tests/test_energy.py @@ -57,57 +57,91 @@ def test_Btu_foot_squared(): def test_wh(): - assert convert(1, "WH", "WH") == 1 assert convert(1, "WH", "BTU") == pytest.approx(3.41214) - assert convert(1, "WH", "KWH") == 0.001 assert convert(1, "WH", "KBTU") == pytest.approx(0.003412141633) - assert convert(1, "WH", "MJ") == pytest.approx(0.0036) + assert convert(1, "WH", "WH") == 1 + assert convert(1, "WH", "KWH") == 0.001 + assert convert(1, "WH", "J") == 3600 assert convert(1, "WH", "KJ") == pytest.approx(3.6) + assert convert(1, "WH", "MJ") == pytest.approx(0.0036) + assert convert(1, "WH", "GJ") == pytest.approx(0.0000036) def test_KWH(): - assert convert(1, "KWH", "WH") == 1000 assert convert(1, "KWH", "BTU") == pytest.approx(3412.141633) - assert convert(1, "KWH", "KWH") == 1 assert convert(1, "KWH", "KBTU") == pytest.approx(3.412141633) - assert convert(1, "KWH", "MJ") == pytest.approx(3.6) + assert convert(1, "KWH", "WH") == 1000 + assert convert(1, "KWH", "KWH") == 1 + assert convert(1, "KWH", "J") == pytest.approx(3600000) assert convert(1, "KWH", "KJ") == pytest.approx(3600) + assert convert(1, "KWH", "MJ") == pytest.approx(3.6) + assert convert(1, "KWH", "GJ") == pytest.approx(0.0036) def test_BTU(): - assert convert(1, "BTU", "WH") == pytest.approx(0.293071) assert convert(1, "BTU", "BTU") == 1 - assert convert(1, "BTU", "KWH") == pytest.approx(0.000293071) assert convert(1, "BTU", "KBTU") == pytest.approx(0.001) - assert convert(1, "BTU", "MJ") == pytest.approx(0.00105506) + assert convert(1, "BTU", "WH") == pytest.approx(0.293071) + assert convert(1, "BTU", "KWH") == pytest.approx(0.000293071) + assert convert(1, "BTU", "J") == pytest.approx(1055.06) assert convert(1, "BTU", "KJ") == pytest.approx(1.05506) + assert convert(1, "BTU", "MJ") == pytest.approx(0.00105506) + assert convert(1, "BTU", "GJ") == pytest.approx(0.00000105506) def test_KBTU(): - assert convert(1, "KBTU", "WH") == pytest.approx(293.071) assert convert(1, "KBTU", "BTU") == 1000 - assert convert(1, "KBTU", "KWH") == pytest.approx(0.293071) assert convert(1, "KBTU", "KBTU") == 1 - assert convert(1, "KBTU", "MJ") == pytest.approx(1.05506) + assert convert(1, "KBTU", "WH") == pytest.approx(293.071) + assert convert(1, "KBTU", "KWH") == pytest.approx(0.293071) + assert convert(1, "KBTU", "J") == pytest.approx(1055060) assert convert(1, "KBTU", "KJ") == pytest.approx(1055.06) + assert convert(1, "KBTU", "MJ") == pytest.approx(1.05506) + assert convert(1, "KBTU", "GJ") == pytest.approx(0.00105506) -def test_MegaJoule(): - assert convert(1, "MJ", "WH") == pytest.approx(277.778) - assert convert(1, "MJ", "BTU") == pytest.approx(947.817) - assert convert(1, "MJ", "KWH") == pytest.approx(0.277778) - assert convert(1, "MJ", "KBTU") == pytest.approx(0.947817) - assert convert(1, "MJ", "MJ") == 1 - assert convert(1, "MJ", "KJ") == pytest.approx(1000) +def test_Joule(): + assert convert(1, "J", "BTU") == pytest.approx(0.000947817) + assert convert(1, "J", "KBTU") == pytest.approx(0.000000947817) + assert convert(1, "J", "WH") == pytest.approx(0.000277778) + assert convert(1, "J", "KWH") == pytest.approx(0.00000027778) + assert convert(1, "J", "J") == 1 + assert convert(1, "J", "KJ") == pytest.approx(0.001) + assert convert(1, "J", "MJ") == pytest.approx(0.000001) + assert convert(1, "J", "GJ") == pytest.approx(0.000000001) def test_KiloJoule(): - assert convert(1, "KJ", "WH") == pytest.approx(0.277778) assert convert(1, "KJ", "BTU") == pytest.approx(0.947817) - assert convert(1, "KJ", "KWH") == pytest.approx(0.000277778) assert convert(1, "KJ", "KBTU") == pytest.approx(0.000947817) + assert convert(1, "KJ", "WH") == pytest.approx(0.277778) + assert convert(1, "KJ", "KWH") == pytest.approx(0.000277778) + assert convert(1, "KJ", "J") == 1000 assert convert(1, "KJ", "MJ") == pytest.approx(0.001) assert convert(1, "KJ", "KJ") == 1 + assert convert(1, "KJ", "GJ") == pytest.approx(0.000001) + + +def test_MegaJoule(): + assert convert(1, "MJ", "BTU") == pytest.approx(947.817) + assert convert(1, "MJ", "KBTU") == pytest.approx(0.947817) + assert convert(1, "MJ", "WH") == pytest.approx(277.778) + assert convert(1, "MJ", "KWH") == pytest.approx(0.277778) + assert convert(1, "MJ", "J") == pytest.approx(1000000) + assert convert(1, "MJ", "KJ") == pytest.approx(1000) + assert convert(1, "MJ", "MJ") == 1 + assert convert(1, "MJ", "GJ") == pytest.approx(0.001) + + +def test_GigaJoule(): + assert convert(1, "GJ", "BTU") == pytest.approx(947817) + assert convert(1, "GJ", "KBTU") == pytest.approx(947.817) + assert convert(1, "GJ", "WH") == pytest.approx(277778) + assert convert(1, "GJ", "KWH") == pytest.approx(277.778) + assert convert(1, "GJ", "J") == pytest.approx(1000000000) + assert convert(1, "GJ", "KJ") == pytest.approx(1000000) + assert convert(1, "GJ", "MJ") == pytest.approx(1000) + assert convert(1, "GJ", "GJ") == 1 def test_MegaJoule_per_m3_DegreeKelvin():