Skip to content

Commit

Permalink
feat(frequency): assert positive hertz value (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed May 13, 2023
1 parent 9ae0b91 commit 44f501e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/note/frequency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Frequency implements Comparable<Frequency> {
final double hertz;

/// Creates a new [Frequency] instance from [hertz].
const Frequency(this.hertz);
const Frequency(this.hertz) : assert(hertz >= 0, 'Hertz must be positive');

/// The symbol for the Hertz unit.
static const hertzUnitSymbol = 'Hz';
Expand Down
6 changes: 6 additions & 0 deletions test/src/note/frequency_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import 'package:test/test.dart';

void main() {
group('Frequency', () {
group('constructor', () {
test('should throw an assertion error when arguments are incorrect', () {
expect(() => Frequency(-0.1), throwsA(isA<AssertionError>()));
});
});

group('.isHumanAudible', () {
test('should return whether the frequency is audible by humans', () {
expect(const Frequency(0).isHumanAudible, isFalse);
Expand Down

0 comments on commit 44f501e

Please sign in to comment.