Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/fraction_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ name: fractions_ci

on:
pull_request:
paths-ignore:
- "**.md"
push:
branches:
- master
- main
- develop

jobs:
verify_fraction_package:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.0.5
- Updated Dart SDK constraints to `^3.7.2`
- Dependencies update
- Minor documentation fixes

## 5.0.4
- Updated Dart SDK constraints to `^3.6.0`
- Dependencies update
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Alberto Miola
Copyright (c) 2025 Alberto Miola

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 12 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linter:
- avoid_field_initializers_in_const_classes
- avoid_final_parameters
- avoid_function_literals_in_foreach_calls
- avoid_futureor_void
- avoid_implementing_value_types
- avoid_init_to_null
- avoid_js_rounded_ints
Expand Down Expand Up @@ -70,6 +71,7 @@ linter:
- directives_ordering
- discarded_futures
- do_not_use_environment
- document_ignores
- empty_catches
- empty_constructor_bodies
- empty_statements
Expand All @@ -82,6 +84,7 @@ linter:
- implicit_call_tearoffs
- implicit_reopen
- invalid_case_patterns
- invalid_runtime_check_with_js_interop_types
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_annotations
Expand All @@ -102,11 +105,14 @@ linter:
- no_logic_in_create_state
- no_runtimeType_toString
- no_self_assignments
- no_wildcard_variable_uses
- non_constant_identifier_names
- noop_primitive_operations
- null_check_on_nullable_type_parameter
- null_closures
- omit_local_variable_types
- omit_obvious_local_variable_types
- omit_obvious_property_types
- one_member_abstracts
- only_throw_errors
- overridden_fields
Expand Down Expand Up @@ -161,13 +167,16 @@ linter:
- sort_child_properties_last
- sort_pub_dependencies
- sort_unnamed_constructors_first
- strict_top_level_inference
- test_types_in_equals
- throw_in_finally
- tighten_type_of_initializing_formals
- type_annotate_public_apis
- type_init_formals
- type_literal_in_constant_pattern
- unawaited_futures
- unintended_html_in_doc_comment
- unnecessary_async
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_breaks
Expand All @@ -192,9 +201,11 @@ linter:
- unnecessary_string_interpolations
- unnecessary_this
- unnecessary_to_list_in_spreads
- unnecessary_underscores
- unreachable_from_main
- unrelated_type_equality_checks
- unsafe_html
- unsafe_variance
- use_build_context_synchronously
- use_colored_box
- use_decorated_box
Expand All @@ -214,5 +225,6 @@ linter:
- use_super_parameters
- use_test_throws_matchers
- use_to_and_as_if_applicable
- use_truncating_division
- valid_regexps
- void_checks
4 changes: 4 additions & 0 deletions example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.9
- Updated Dart SDK constraints to `^3.7.2`
- Updated dependencies and pubspec file

## 1.0.8
- Updated Dart SDK constraints to `^3.1.0`
- Updated dependencies and pubspec file
Expand Down
4 changes: 3 additions & 1 deletion example/lib/src/analyzer.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:fraction/fraction.dart';

/// {@template RationalAnalyzer}
/// This base class is used to analyze an [input] string.
///
/// The [analyze] method tries to convert [input] into a [Fraction] or
/// [MixedFraction] object and prints various properties to the console.
/// {@endtemplate}
abstract base class RationalAnalyzer {
/// The fraction or mixed fraction input.
final String input;

/// Creates a [RationalAnalyzer] object.
/// {@macro RationalAnalyzer}
const RationalAnalyzer(this.input);

/// Tries to convert [input] into a [Fraction] or [MixedFraction] object and
Expand Down
25 changes: 14 additions & 11 deletions example/lib/src/fraction_analyzer.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:fraction/fraction.dart';
import 'package:fraction_example/src/analyzer.dart';

/// {@template FractionAnalyzer}
/// Tries to convert a [String] into a [Fraction].
/// {@endtemplate}
final class FractionAnalyzer extends RationalAnalyzer {
/// Creates a [FractionAnalyzer] object.
/// {@macro FractionAnalyzer}
const FractionAnalyzer({required String input}) : super(input);

@override
Expand All @@ -13,16 +15,17 @@ final class FractionAnalyzer extends RationalAnalyzer {
final fraction = Fraction.fromString(input);

// Used to incrementally build the results
final buffer = StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Fraction = $fraction')
..writeln('Decimal: ${fraction.toDouble()}')
..writeln('Mixed: ${fraction.toMixedFraction()}\n')
..writeln('Inverse: ${fraction.inverse()}')
..writeln('Negate: ${fraction.negate()}')
..writeln('Reduced: ${fraction.reduce()}\n')
..writeln('Is proper? ${fraction.isProper}')
..writeln('Is improper? ${fraction.isImproper}');
final buffer =
StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Fraction = $fraction')
..writeln('Decimal: ${fraction.toDouble()}')
..writeln('Mixed: ${fraction.toMixedFraction()}\n')
..writeln('Inverse: ${fraction.inverse()}')
..writeln('Negate: ${fraction.negate()}')
..writeln('Reduced: ${fraction.reduce()}\n')
..writeln('Is proper? ${fraction.isProper}')
..writeln('Is improper? ${fraction.isImproper}');

return buffer.toString();
} on Exception {
Expand Down
19 changes: 11 additions & 8 deletions example/lib/src/mixed_fraction_analyzer.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:fraction/fraction.dart';
import 'package:fraction_example/src/analyzer.dart';

/// {@template FractionAnalyzer}
/// Tries to convert a [String] into a [MixedFraction].
/// {@endtemplate}
final class MixedFractionAnalyzer extends RationalAnalyzer {
/// Creates a [MixedFractionAnalyzer] object.
/// {@macro FractionAnalyzer}
const MixedFractionAnalyzer({required String input}) : super(input);

@override
Expand All @@ -13,13 +15,14 @@ final class MixedFractionAnalyzer extends RationalAnalyzer {
final mixedFraction = MixedFraction.fromString(input);

// Used to incrementally build the results
final buffer = StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Mixed fraction = $mixedFraction')
..writeln('Decimal: ${mixedFraction.toDouble()}')
..writeln('Fraction: ${mixedFraction.toFraction()}\n')
..writeln('Negate: ${mixedFraction.negate()}')
..writeln('Reduced: ${mixedFraction.reduce()}');
final buffer =
StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Mixed fraction = $mixedFraction')
..writeln('Decimal: ${mixedFraction.toDouble()}')
..writeln('Fraction: ${mixedFraction.toFraction()}\n')
..writeln('Negate: ${mixedFraction.negate()}')
..writeln('Reduced: ${mixedFraction.reduce()}');

return buffer.toString();
} on Exception {
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: fraction_example
description: A Dart CLI application that uses the API of the 'fraction' package.
version: 1.0.8
version: 1.0.9
repository: https://github.com/albertodev01/fraction/tree/master/example
homepage: https://pub.dev/packages/fraction
publish_to: none

environment:
sdk: ^3.1.0
sdk: ^3.7.2

dependencies:
fraction:
path: ../

dev_dependencies:
test: ^1.24.6
test: ^1.25.15
34 changes: 14 additions & 20 deletions example/test/fraction_analyzer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@ import 'package:test/test.dart';
void main() {
group("Testing the 'FractionAnalyzer' class", () {
test('Making sure that valid fractions can be analyzed', () {
const analyzer = FractionAnalyzer(
input: '8/12',
);
const analyzer = FractionAnalyzer(input: '8/12');

// Building the expected result
final fraction = Fraction(8, 12);
final buffer = StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Fraction = $fraction')
..writeln('Decimal: ${fraction.toDouble()}')
..writeln('Mixed: ${fraction.toMixedFraction()}\n')
..writeln('Inverse: ${fraction.inverse()}')
..writeln('Negate: ${fraction.negate()}')
..writeln('Reduced: ${fraction.reduce()}\n')
..writeln('Is proper? ${fraction.isProper}')
..writeln('Is improper? ${fraction.isImproper}');
final buffer =
StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Fraction = $fraction')
..writeln('Decimal: ${fraction.toDouble()}')
..writeln('Mixed: ${fraction.toMixedFraction()}\n')
..writeln('Inverse: ${fraction.inverse()}')
..writeln('Negate: ${fraction.negate()}')
..writeln('Reduced: ${fraction.reduce()}\n')
..writeln('Is proper? ${fraction.isProper}')
..writeln('Is improper? ${fraction.isImproper}');

expect(
analyzer.analyze(),
equals(buffer.toString()),
);
expect(analyzer.analyze(), equals(buffer.toString()));
});

test('Making sure that invalid fractions report an error', () {
const analyzer = FractionAnalyzer(
input: '',
);
const analyzer = FractionAnalyzer(input: '');

expect(
analyzer.analyze(),
Expand Down
28 changes: 11 additions & 17 deletions example/test/mixed_fraction_analyzer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,28 @@ import 'package:test/test.dart';
void main() {
group("Testing the 'MixedFractionAnalyzer' class", () {
test('Making sure that valid fractions can be analyzed', () {
const analyzer = MixedFractionAnalyzer(
input: '6 7/3',
);
const analyzer = MixedFractionAnalyzer(input: '6 7/3');

// Building the expected result
final mixedFraction = MixedFraction(
whole: 6,
numerator: 7,
denominator: 3,
);
final buffer = StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Mixed fraction = $mixedFraction')
..writeln('Decimal: ${mixedFraction.toDouble()}')
..writeln('Fraction: ${mixedFraction.toFraction()}\n')
..writeln('Negate: ${mixedFraction.negate()}')
..writeln('Reduced: ${mixedFraction.reduce()}');
final buffer =
StringBuffer()
..writeln('\n > ==================== < \n')
..writeln('Mixed fraction = $mixedFraction')
..writeln('Decimal: ${mixedFraction.toDouble()}')
..writeln('Fraction: ${mixedFraction.toFraction()}\n')
..writeln('Negate: ${mixedFraction.negate()}')
..writeln('Reduced: ${mixedFraction.reduce()}');

expect(
analyzer.analyze(),
equals(buffer.toString()),
);
expect(analyzer.analyze(), equals(buffer.toString()));
});

test('Making sure that invalid fractions report an error', () {
const analyzer = MixedFractionAnalyzer(
input: '',
);
const analyzer = MixedFractionAnalyzer(input: '');

expect(
analyzer.analyze(),
Expand Down
13 changes: 8 additions & 5 deletions lib/src/types/egyptian_converter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fraction/fraction.dart';

/// {@template EgyptianFractionConverter}
/// This class converts a [Fraction] or a [MixedFraction] type into its egyptian
/// fraction representation. Only positive number are allowed.
///
Expand All @@ -19,6 +20,7 @@ import 'package:fraction/fraction.dart';
///
/// In various cases, the value of the denominator can be so big that an
/// overflow error happens.
/// {@endtemplate}
class EgyptianFractionConverter {
/// This variable caches the result of the `compute()` method.
static final _cache = <Fraction, List<Fraction>>{};
Expand All @@ -27,16 +29,17 @@ class EgyptianFractionConverter {
final Fraction fraction;

/// Creates an [EgyptianFractionConverter] instance from a [Fraction] object.
const EgyptianFractionConverter({
required this.fraction,
});
///
/// {@macro EgyptianFractionConverter}
const EgyptianFractionConverter({required this.fraction});

/// Creates an [EgyptianFractionConverter] instance from a [MixedFraction]
/// object.
///
/// {@macro EgyptianFractionConverter}
factory EgyptianFractionConverter.fromMixedFraction({
required MixedFraction mixedFraction,
}) =>
EgyptianFractionConverter(fraction: mixedFraction.toFraction());
}) => EgyptianFractionConverter(fraction: mixedFraction.toFraction());

/// Returns a series of [Fraction]s that represent the egyptian fraction of
/// the [fraction] object.
Expand Down
Loading