Skip to content

Commit

Permalink
feat: add greater or equal, less or equal operators
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed May 9, 2024
1 parent 1f1d4e2 commit a824bf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ extension type Coin(int value) {
/// Returns true if [value] is greater than [other] value.
bool operator >(Coin other) => value > other.value;

/// Returns true if [value] is greater than or equal [other] value.
bool operator >=(Coin other) => value > other.value || value == other.value;

/// Returns true if [value] is smaller than [other] value.
bool operator <(Coin other) => value < other.value;

/// Returns true if [value] is smaller than or equal [other] value.
bool operator <=(Coin other) => value < other.value || value == other.value;
}

/// A blockchain slot number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void main() {

test('comparison', () {
expect(Coin(3) > Coin(2), isTrue);
expect(Coin(100) < Coin(50), isFalse);
expect(Coin(3) >= Coin(3), isTrue);
expect(Coin(100) < Coin(100), isFalse);
expect(Coin(100) <= Coin(100), isTrue);
});
});
}

0 comments on commit a824bf2

Please sign in to comment.