From b34b165068bcfa7843f5bfd7f4baa3447566841b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Ma=C3=B1osa?= Date: Sun, 14 May 2023 00:14:59 +0200 Subject: [PATCH] feat(frequency): assert positive `hertz` value --- lib/src/note/frequency.dart | 2 +- test/src/note/frequency_test.dart | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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);