Skip to content

Commit

Permalink
Add illuminance units (#38)
Browse files Browse the repository at this point in the history
* Add illuminance units

* Fix description

* Format + adapted code style

---------

Co-authored-by: Dennis Geldhof <[email protected]>
Co-authored-by: Damiano Ferrari <[email protected]>
  • Loading branch information
3 people authored Aug 18, 2023
1 parent dfffa5f commit 7ea883b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/models/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum PROPERTY {
energy,
force,
fuelConsumption,
illuminance,
length,
mass,
molarmass,
Expand Down
38 changes: 38 additions & 0 deletions lib/properties/illuminance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:units_converter/models/conversion_node.dart';
import 'package:units_converter/models/double_property.dart';
import 'package:units_converter/models/property.dart';
import 'package:units_converter/models/unit.dart';

enum ILLUMINANCE {
lux,
footCandle,
}

class Illuminance extends DoubleProperty<ILLUMINANCE> {
///Class for light conversions, e.g. if you want to convert 1 lux in to foot-candle:
///```dart
///var illuminance = Illuminance(removeTrailingZeros: false);
///illuminance.convert(Unit(ILLUMINANCE.lux, value: 1));
///print(illuminance.footCandle);
/// ```
Illuminance(
{super.significantFigures,
super.removeTrailingZeros,
super.useScientificNotation,
name})
: super(
name: name ?? PROPERTY.illuminance,
mapSymbols: {
ILLUMINANCE.lux: 'lx',
ILLUMINANCE.footCandle: 'fc',
},
conversionTree: ConversionNode(name: ILLUMINANCE.lux, leafNodes: [
ConversionNode(
coefficientProduct: 10.763910416709722,
name: ILLUMINANCE.footCandle,
),
]));

Unit get lux => getUnit(ILLUMINANCE.lux);
Unit get footCandle => getUnit(ILLUMINANCE.footCandle);
}
1 change: 1 addition & 0 deletions lib/units_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export 'package:units_converter/properties/digital_data.dart';
export 'package:units_converter/properties/shoe_size.dart';
export 'package:units_converter/properties/numeral_systems.dart';
export 'package:units_converter/properties/density.dart';
export 'package:units_converter/properties/illuminance.dart';
3 changes: 3 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';
import 'package:units_converter/models/property.dart';
import 'package:units_converter/properties/amount_of_substance.dart';
import 'package:units_converter/properties/illuminance.dart';
import 'package:units_converter/properties/length.dart';
import 'package:units_converter/properties/area.dart';
import 'package:units_converter/properties/molar_mass.dart';
Expand Down Expand Up @@ -41,6 +42,8 @@ Property? getPropertyFromEnum(dynamic propertyEnum) {
return Force();
case FUEL_CONSUMPTION:
return FuelConsumption();
case ILLUMINANCE:
return Illuminance();
case LENGTH:
return Length();
case MASS:
Expand Down
8 changes: 8 additions & 0 deletions test/conversion_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ void main() {
runConversionTest(expectedResult, FuelConsumption());
});

group('Illuminance', () {
const Map<ILLUMINANCE, double> expectedResult = {
ILLUMINANCE.lux: 1,
ILLUMINANCE.footCandle: 0.09290304,
};
runConversionTest(expectedResult, Illuminance());
});

group('Length', () {
const Map<LENGTH, double> expectedResult = {
LENGTH.meters: 1,
Expand Down
2 changes: 2 additions & 0 deletions test/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void main() {
expect(1.convertFromTo(DIGITAL_DATA.byte, DIGITAL_DATA.nibble), 2);
expect(1.convertFromTo(ENERGY.kilocalories, ENERGY.calories), 1e3);
expect(1.convertFromTo(FORCE.dyne, FORCE.newton), 1e-5);
expect(
1.convertFromTo(ILLUMINANCE.lux, ILLUMINANCE.footCandle), 0.09290304);
expect(
1.convertFromTo(FUEL_CONSUMPTION.kilometersPerLiter,
FUEL_CONSUMPTION.litersPer100km),
Expand Down
8 changes: 8 additions & 0 deletions test/getters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ void main() {
property.getUnit(FUEL_CONSUMPTION.milesPerImperialGallon));
});

group('Illuminance test', () {
var property = Illuminance();
property.convert(ILLUMINANCE.lux, 1);
runGetterTest(property.lux, property.getUnit(ILLUMINANCE.lux));
runGetterTest(
property.footCandle, property.getUnit(ILLUMINANCE.footCandle));
});

group('Length test', () {
var property = Length();
property.convert(LENGTH.meters, 1);
Expand Down

0 comments on commit 7ea883b

Please sign in to comment.