Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frequency): assert positive hertz value #118

Merged
merged 1 commit into from
May 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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