Skip to content

Commit

Permalink
Added kilojoules (#36)
Browse files Browse the repository at this point in the history
* Added kilojoules

* Added getter test

---------

Co-authored-by: Damiano Ferrari <[email protected]>
  • Loading branch information
lhengl and ferraridamiano authored Apr 1, 2023
1 parent 234224a commit afba47b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/properties/energy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:units_converter/models/unit.dart';
//Available ENERGY units
enum ENERGY {
joules,
kilojoules,
calories,
kilocalories,
kilowattHours,
Expand All @@ -29,13 +30,18 @@ class Energy extends DoubleProperty<ENERGY> {
name: name ?? PROPERTY.energy,
mapSymbols: {
ENERGY.joules: 'J',
ENERGY.kilojoules: 'kJ',
ENERGY.calories: 'cal',
ENERGY.kilocalories: 'kcal',
ENERGY.kilowattHours: 'kwh',
ENERGY.electronvolts: 'eV',
ENERGY.energyFootPound: 'ft⋅lbf',
},
conversionTree: ConversionNode(name: ENERGY.joules, leafNodes: [
ConversionNode(
coefficientProduct: 1000.0,
name: ENERGY.kilojoules,
),
ConversionNode(
coefficientProduct: 4.1867999409,
name: ENERGY.calories,
Expand All @@ -61,6 +67,7 @@ class Energy extends DoubleProperty<ENERGY> {
]));

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);
Expand Down
1 change: 1 addition & 0 deletions test/conversion_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void main() {
group('Energy', () {
const Map<ENERGY, double> expectedResult = {
ENERGY.joules: 1,
ENERGY.kilojoules: 1e-3,
ENERGY.calories: 0.2388459,
ENERGY.kilocalories: 0.0002388459,
ENERGY.kilowattHours: 2.7777777778e-7,
Expand Down
1 change: 1 addition & 0 deletions test/getters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit afba47b

Please sign in to comment.