Skip to content

Commit

Permalink
Added quantity Volume (0.3.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav committed Jul 19, 2022
1 parent a3d8add commit 1a629d6
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: dart test --platform=vm --coverage=coverage

- name: Format coverage
run: dart pub global run coverage:format_coverage --packages=.packages --in=coverage/test/ --out=stdout --report-on=lib/ --check-ignore
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --in=coverage/test/ --out=stdout --report-on=lib/ --check-ignore

- name: Pub publish (dry-run)
run: dart pub publish --dry-run
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ before_script:
script:
- dart analyze --fatal-infos --fatal-warnings
- dart test --platform=vm --coverage=coverage
- dart pub global run coverage:format_coverage --packages=.packages --in=coverage/test/ --out=coverage/lcov.info --report-on=lib/ --lcov --check-ignore
- dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --in=coverage/test/ --out=coverage/lcov.info --report-on=lib/ --lcov --check-ignore
- cat coverage/lcov.info | coveralls
- dart pub publish --dry-run
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.5

- Added quantities
- `Volume`

## 0.3.4

- Added quantities
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# converter - Convert between different units of measurement

[![Version](https://img.shields.io/pub/v/converter)](https://pub.dev/packages/converter)
[![Build Status](https://travis-ci.com/dkin-om/converter-dart.svg?branch=master)](https://travis-ci.com/dkin-om/converter-dart)
[![Build Status](https://travis-ci.com/dkin-om/converter-dart.svg?branch=master)](https://app.travis-ci.com/github/dkin-om/converter-dart)
[![Coverage Status](https://coveralls.io/repos/github/dkin-om/converter-dart/badge.svg)](https://coveralls.io/github/dkin-om/converter-dart)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/dkin-om/converter-dart/blob/master/LICENSE)

Expand Down Expand Up @@ -195,6 +195,24 @@ final bool t3LTEt2 = t3 <= t2;
- `mi/h` - mile per hour
- `kn` - knot

### `Volume`
- `m3` | `kl` - cubic metre *or* kilolitre (**SI**)
- `dm3` | `l` - cubic decimetre *or* litre
- `cm3` | `ml` - cubic centimetre *or* millilitre
- `mm3` | `µl` - cubic millimetre *or* microlitre
- `dam3` | `Ml` - cubic decametre *or* megalitre
- `hm3` | `Gl` - cubic hectometre *or* gigalitre
- `km3` | `Tl` - cubic kilometre *or* teralitre
- `in3` - cubic inch
- `ft3` - cubic foot
- `mi3` - cubic mile
- `gal` - gallon
- `qt` - quart
- `pt` - pint
- `fl-oz` - fluid ounce
- `tbsp` - tablespoon
- `tsp` - teaspoon

## Syntax

See [documentation](https://pub.dev/documentation/converter) for more
Expand Down
1 change: 1 addition & 0 deletions lib/converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export 'src/quantities/frequency.dart' show Frequency;
export 'src/quantities/quantity.dart' show Quantity;
export 'src/quantities/solid_angle.dart' show SolidAngle;
export 'src/quantities/speed.dart' show Speed;
export 'src/quantities/volume.dart' show Volume;
161 changes: 161 additions & 0 deletions lib/src/quantities/volume.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import 'package:invertible/invertible.dart';

import 'base/base_quantity.dart';
import 'base/length.dart';
import 'quantity.dart';
import 'unit.dart';

/// Represents quantity Volume
class Volume extends Quantity<Volume> {
/// Constructs Volume with the value and the unit
Volume(num value, String unitSymbol)
: super(value, unitSymbol, _V._dimension);

/// Constructs Volume with the value in SI unit
const Volume.si(num siValue) : super.si(siValue, _V._dimension);
}

class _V extends Dimension<Volume> {
factory _V() => _dimension;

const _V._internal()
: super(
const <BaseDimension<dynamic>, num>{L.dimension: 3},
siUnitSymbol: 'm3',
allUnits: const <String, Unit>{
'm3': Unit('cubic metre', toSI: <InvertibleRealFunction>[]),
'kl': Unit('kilolitre', toSI: <InvertibleRealFunction>[]),
'dm3': Unit(
'cubic decimetre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'dm',
},
),
'l': Unit(
'litre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'dm',
},
),
'cm3': Unit(
'cubic centimetre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'cm',
},
),
'ml': Unit(
'millilitre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'cm',
},
),
'mm3': Unit(
'cubic millimetre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'mm',
},
),
'µl': Unit(
'microlitre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'mm',
},
),
'dam3': Unit(
'cubic decametre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'dam',
},
),
'Ml': Unit(
'megalitre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'dam',
},
),
'hm3': Unit(
'cubic hectometre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'hm',
},
),
'Gl': Unit(
'gigalitre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'hm',
},
),
'km3': Unit(
'cubic kilometre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'km',
},
),
'Tl': Unit(
'teralitre',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'km',
},
),
'in3': Unit(
'cubic inch',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'in',
},
),
'ft3': Unit(
'cubic foot',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'ft',
},
),
'mi3': Unit(
'cubic mile',
baseUnitSymbols: <BaseDimension<dynamic>, String>{
L.dimension: 'mi',
},
),
'gal': Unit(
'gallon',
toSI: <InvertibleRealFunction>[
Multiplication(0.00454609),
],
),
'qt': Unit(
'quart',
toSI: <InvertibleRealFunction>[
Multiplication(0.0011365225),
],
),
'pt': Unit(
'pint',
toSI: <InvertibleRealFunction>[
Multiplication(5.6826125e-4),
],
),
'fl-oz': Unit(
'fluid ounce',
toSI: <InvertibleRealFunction>[
Multiplication(2.84130625e-5),
],
),
'tbsp': Unit(
'tablespoon',
toSI: <InvertibleRealFunction>[
Multiplication(1.5e-5),
],
),
'tsp': Unit(
'teaspoon',
toSI: <InvertibleRealFunction>[
Multiplication(5e-6),
],
),
},
);

@override
Volume si(num siValue) => Volume.si(siValue);

static const _V _dimension = _V._internal();
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: converter
version: 0.3.4
version: 0.3.5
description: A Dart library for converting between different units of measurement for various quantities
repository: https://github.com/dkin-om/converter-dart.git
issue_tracker: https://github.com/dkin-om/converter-dart/issues
Expand Down
2 changes: 2 additions & 0 deletions test/converter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'quantities/frequency_testcase.dart';
import 'quantities/quantity_testcase.dart';
import 'quantities/solid_angle_testcase.dart';
import 'quantities/speed_testcase.dart';
import 'quantities/volume_testcase.dart';

void main() {
testAdditions();
Expand Down Expand Up @@ -104,6 +105,7 @@ void testConverters() {
testConverter(frequencyConverter);
testConverter(solidAngleConverter);
testConverter(speedConverter);
testConverter(volumeConverter);
}

void testConverter(Map<String, dynamic> converter) {
Expand Down
93 changes: 93 additions & 0 deletions test/quantities/volume_testcase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'package:converter/converter.dart';

final Map<String, dynamic> volumeConverter = <String, dynamic>{
'testCases': <Map<String, dynamic>>[
<String, dynamic>{
'quantity': Volume.si(139),
'siValue': 139,
'valueIn': <String, num>{
'm3': 139,
'kl': 139,
'dm3': 1.39e5,
'l': 1.39e5,
'cm3': 1.39e8,
'ml': 1.39e8,
'mm3': 1.39e11,
'µl': 1.39e11,
'dam3': 0.139,
'Ml': 0.139,
'hm3': 1.39e-4,
'Gl': 1.39e-4,
'km3': 1.39e-7,
'Tl': 1.39e-7,
'in3': 8.4823e6,
'ft3': 4908.74,
'mi3': 3.33479e-8,
'gal': 30575.7,
'qt': 122303,
'pt': 244606,
'fl-oz': 4.892116e6,
'tbsp': 9.266666e6,
'tsp': 2.78e7,
},
},
<String, dynamic>{
'quantity': Volume(149, 'µl'),
'siValue': 1.49e-7,
'valueIn': <String, num>{
'm3': 1.49e-7,
'kl': 1.49e-7,
'dm3': 1.49e-4,
'l': 1.49e-4,
'cm3': 0.149,
'ml': 0.149,
'mm3': 149,
'µl': 149,
'dam3': 1.49e-10,
'Ml': 1.49e-10,
'hm3': 1.49e-13,
'Gl': 1.49e-13,
'km3': 1.49e-16,
'Tl': 1.49e-16,
'in3': 0.009092537,
'ft3': 5.261885e-6,
'mi3': 3.5747e-17,
'gal': 3.277541e-5,
'qt': 1.311016e-4,
'pt': 2.622032e-4,
'fl-oz': 0.005244067,
'tbsp': 0.009933333,
'tsp': 0.0298,
},
},
<String, dynamic>{
'quantity': Volume(151, 'Ml'),
'siValue': 1.51e5,
'valueIn': <String, num>{
'm3': 1.51e5,
'kl': 1.51e5,
'dm3': 1.51e8,
'l': 1.51e8,
'cm3': 1.51e11,
'ml': 1.51e11,
'mm3': 1.51e14,
'µl': 1.51e14,
'dam3': 151,
'Ml': 151,
'hm3': 0.151,
'Gl': 0.151,
'km3': 1.51e-4,
'Tl': 1.51e-4,
'in3': 9.214585e9,
'ft3': 5.332514e6,
'mi3': 3.622682e-5,
'gal': 3.321535e7,
'qt': 1.328614e8,
'pt': 2.657228e8,
'fl-oz': 5.314457e9,
'tbsp': 1.006666e10,
'tsp': 3.02e10,
},
},
],
};

0 comments on commit 1a629d6

Please sign in to comment.