From 51735c4c16247325bb89170ae8fccfe42f29cfd2 Mon Sep 17 00:00:00 2001 From: Nathan Merritt Date: Wed, 6 Apr 2022 13:32:00 -0600 Subject: [PATCH] add test for conversion to joules --- .../resources/v2_1_4/VOCAB_QUDT-UNITS-ALL-v2.1.ttl | 6 +++--- qudt/units/energy.py | 4 ++++ test/units/energy_unit_test.py | 11 +++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qudt/ontology/resources/v2_1_4/VOCAB_QUDT-UNITS-ALL-v2.1.ttl b/qudt/ontology/resources/v2_1_4/VOCAB_QUDT-UNITS-ALL-v2.1.ttl index 4c455da..05ac1a8 100644 --- a/qudt/ontology/resources/v2_1_4/VOCAB_QUDT-UNITS-ALL-v2.1.ttl +++ b/qudt/ontology/resources/v2_1_4/VOCAB_QUDT-UNITS-ALL-v2.1.ttl @@ -20662,7 +20662,7 @@ unit:failures-in-time rdfs:label "failures in time" ; skos:prefLabel "failures in time" ; . - unit:NM3-NAT-GAS: + unit:NM3-NAT-GAS a qudt:Unit ; dcterms:description "Normal Cubic Meter - One M3 of natural gas at 0c and 1.01325 bar (=37MJ)"; qudt:conversionMultiplier 3.7E7; @@ -20672,7 +20672,7 @@ unit:failures-in-time rdfs:isDefinedBy ; rdfs:label "Normal Cubic Metre" ; . -unit:SCM-NAT-GAS: +unit:SCM-NAT-GAS a qudt:Unit ; dcterms:description "Standard Cubic Metre - One M3 of natural gas at 15C and 1.01325 bar"; qudt:conversionMultiplier 3.9109E7; @@ -20682,7 +20682,7 @@ unit:SCM-NAT-GAS: rdfs:isDefinedBy ; rdfs:label "Standard Cubic Metre" ; . -unit:SFT3-NAT-GAS: +unit:SFT3-NAT-GAS a qudt:Unit ; dcterms:description "Standard Cubic Foot - One Ft3 of natural gas at 60f and 1.01325 bar"; qudt:conversionMultiplier 1.085E6; diff --git a/qudt/units/energy.py b/qudt/units/energy.py index 763c81e..360a0c7 100644 --- a/qudt/units/energy.py +++ b/qudt/units/energy.py @@ -22,3 +22,7 @@ class EnergyUnit(object): JOULE: Unit = UnitFactory.get_qudt('J') BTU: Unit = UnitFactory.get_qudt('BTU_IT') KWH: Unit = UnitFactory.get_qudt('KiloW-HR') + + NM3_GAS: Unit = UnitFactory.get_qudt('NM3-NAT-GAS') + SCM_GAS: Unit = UnitFactory.get_qudt('SCM-NAT-GAS') + SFT3_GAS: Unit = UnitFactory.get_qudt('SFT3-NAT-GAS') diff --git a/test/units/energy_unit_test.py b/test/units/energy_unit_test.py index d7d7f12..11c9975 100644 --- a/test/units/energy_unit_test.py +++ b/test/units/energy_unit_test.py @@ -35,5 +35,16 @@ def test_kwh_to_btu(self) -> None: self.assertAlmostEqual(btu.value, 170607.08, 2) +class NormalNaturalGasTest(unittest.TestCase): + def test_gas_to_joules(self) -> None: + for gas in [EnergyUnit.NM3_GAS, EnergyUnit.SCM_GAS, EnergyUnit.SFT3_GAS]: + one_standard = Quantity(1, gas) + assert one_standard.unit is not None + + joules = one_standard.convert_to(EnergyUnit.JOULE) + assert joules.value > 0 + self.assertEqual(joules.unit, EnergyUnit.JOULE) + + if __name__ == '__main__': unittest.main()