ucum 0.4.0 copy "ucum: ^0.4.0" to clipboard
ucum: ^0.4.0 copied to clipboard

Dart Library Mimicking the Unified Code for Units of Measure Library Functionality

example/example.dart

import 'package:test/test.dart';
import 'package:ucum/ucum.dart';

void main() {
  group("grey's tests", () {
    late UcumService ucumService;

    setUpAll(() {
      ucumService = getUcumService();
    });

    test('make units', () {
      final ValidatedQuantity quantity1 =
          ValidatedQuantity.fromString('4 hours');
      expect(quantity1.value.asUcumDecimal(), '4');
      expect(quantity1.unit, 'hours');
      final ValidatedQuantity quantity2 =
          ValidatedQuantity.fromString('16.5559988 mph');
      expect(ucumService.validate(quantity2.unit), isNull);
    });

    test('Equal', () {
      final ValidatedQuantity quantity3 = ValidatedQuantity.fromString('4 m');
      final ValidatedQuantity quantity4 =
          ValidatedQuantity.fromString('400 cm');
      expect(ucumService.isEqual(quantity3, quantity4), true);
      final ValidatedQuantity quantity5 =
          ValidatedQuantity.fromString('2.54 cm');
      final ValidatedQuantity quantity6 =
          ValidatedQuantity.fromString('1 inch');
      expect(ucumService.isEqual(quantity5, quantity6), true);
      expect(ucumService.isEqual(quantity6, quantity5), true);
    });
  });
}

UcumService getUcumService() => UcumService();
0
likes
140
pub points
47%
popularity

Publisher

verified publisherfhirfli.dev

Dart Library Mimicking the Unified Code for Units of Measure Library Functionality

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

xml

More

Packages that depend on ucum