From afba47ba335b5357158e7da8254f2e8573811d56 Mon Sep 17 00:00:00 2001 From: lhengl <93251339+lhengl@users.noreply.github.com> Date: Sun, 2 Apr 2023 00:47:06 +1100 Subject: [PATCH] Added kilojoules (#36) * Added kilojoules * Added getter test --------- Co-authored-by: Damiano Ferrari --- lib/properties/energy.dart | 7 +++++++ test/conversion_test.dart | 1 + test/getters_test.dart | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/properties/energy.dart b/lib/properties/energy.dart index c54e01e..b3ce2a0 100644 --- a/lib/properties/energy.dart +++ b/lib/properties/energy.dart @@ -6,6 +6,7 @@ import 'package:units_converter/models/unit.dart'; //Available ENERGY units enum ENERGY { joules, + kilojoules, calories, kilocalories, kilowattHours, @@ -29,6 +30,7 @@ class Energy extends DoubleProperty { name: name ?? PROPERTY.energy, mapSymbols: { ENERGY.joules: 'J', + ENERGY.kilojoules: 'kJ', ENERGY.calories: 'cal', ENERGY.kilocalories: 'kcal', ENERGY.kilowattHours: 'kwh', @@ -36,6 +38,10 @@ class Energy extends DoubleProperty { ENERGY.energyFootPound: 'ft⋅lbf', }, conversionTree: ConversionNode(name: ENERGY.joules, leafNodes: [ + ConversionNode( + coefficientProduct: 1000.0, + name: ENERGY.kilojoules, + ), ConversionNode( coefficientProduct: 4.1867999409, name: ENERGY.calories, @@ -61,6 +67,7 @@ class Energy extends DoubleProperty { ])); Unit get joules => getUnit(ENERGY.joules); + Unit get kilojoules => getUnit(ENERGY.kilojoules); Unit get calories => getUnit(ENERGY.calories); Unit get kilocalories => getUnit(ENERGY.kilocalories); Unit get kilowattHours => getUnit(ENERGY.kilowattHours); diff --git a/test/conversion_test.dart b/test/conversion_test.dart index e18eb02..e6f59f9 100644 --- a/test/conversion_test.dart +++ b/test/conversion_test.dart @@ -143,6 +143,7 @@ void main() { group('Energy', () { const Map expectedResult = { ENERGY.joules: 1, + ENERGY.kilojoules: 1e-3, ENERGY.calories: 0.2388459, ENERGY.kilocalories: 0.0002388459, ENERGY.kilowattHours: 2.7777777778e-7, diff --git a/test/getters_test.dart b/test/getters_test.dart index 97bb539..4f42e10 100644 --- a/test/getters_test.dart +++ b/test/getters_test.dart @@ -134,6 +134,7 @@ void main() { var property = Energy(); property.convert(ENERGY.joules, 1); runGetterTest(property.joules, property.getUnit(ENERGY.joules)); + runGetterTest(property.kilojoules, property.getUnit(ENERGY.kilojoules)); runGetterTest(property.calories, property.getUnit(ENERGY.calories)); runGetterTest(property.kilocalories, property.getUnit(ENERGY.kilocalories)); runGetterTest(