energizr 1.0.0 energizr: ^1.0.0 copied to clipboard
Energizr -- Energy for The Visionary Software Solutions Measurement & me_sure_meant API
import 'package:energizr/energizr.dart';
void main() {
energyDemo();
}
void energyDemo() {
final calories = 250.kiloCalories();
var added = calories + 25.kiloCalories();
/// + supported
assert(added.magnitude.toNum() == 275);
assert(added.unit == Calorie.kilocalorie);
/// Objects are immutable: calculations yield new objects.
assert(calories.magnitude.toNum() == 250);
assert(calories.unit == Calorie.kilocalorie);
/// - supported
var subtracted = calories - 100.kiloCalories();
assert(subtracted.magnitude.toNum() == 150);
assert(subtracted.unit == Calorie.kilocalorie);
/// Unit conversion between units of same type (e.g. [Energy])
var asKJ = calories.toUnit(Joule.kilojoule);
assert(asKJ.magnitude.toNum() == 1046);
assert(asKJ.unit == Joule.kilojoule);
/// Common base type enables math between mixed units with auto-conversion
var mixedMath = asKJ + calories;
assert(mixedMath.magnitude.toNum() == 2092);
assert(mixedMath.unit == Joule.kilojoule);
/// Conversion yields equivalent result when converted back
var backToCal = mixedMath.toUnit(Calorie.kilocalorie);
assert(backToCal.magnitude.toNum() == 500);
assert(backToCal.unit == Calorie.kilocalorie);
}