diff --git a/lib/src/note/frequency.dart b/lib/src/note/frequency.dart index a8857b87..8b922a58 100644 --- a/lib/src/note/frequency.dart +++ b/lib/src/note/frequency.dart @@ -7,7 +7,7 @@ class Frequency implements Comparable { 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'; diff --git a/test/src/note/frequency_test.dart b/test/src/note/frequency_test.dart index 7e91386f..b3284fb3 100644 --- a/test/src/note/frequency_test.dart +++ b/test/src/note/frequency_test.dart @@ -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())); + }); + }); + group('.isHumanAudible', () { test('should return whether the frequency is audible by humans', () { expect(const Frequency(0).isHumanAudible, isFalse);