Skip to content

Commit

Permalink
test(closest_pitch): 🧪 add test cases for toString rounding (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>
  • Loading branch information
albertms10 committed May 12, 2024
1 parent 1d0a073 commit 5fcc757
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ Or parse a `ClosestPitch` from a string:

```dart
ClosestPitch.parse('A4'); // A4
ClosestPitch.parse('A4+12.4'); // A4+12.4
ClosestPitch.parse('A4+12.6'); // A4+13
ClosestPitch.parse('Eâ™­3-28'); // Eâ™­3-28
```

Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void main() {
Note.g.flat.inOctave(5) - const Cent(8.236); // Gâ™­5-8

ClosestPitch.parse('A4'); // A4
ClosestPitch.parse('A4+12.4'); // A4+12.4
ClosestPitch.parse('A4+12.6'); // A4+13
ClosestPitch.parse('Eâ™­3-28'); // Eâ™­3-28

// In a nutshell
Expand Down
2 changes: 1 addition & 1 deletion lib/src/note/closest_pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ClosestPitch {
/// const Frequency(440).closestPitch().toString() == 'A4'
/// const Frequency(228.9).closestPitch().toString() == 'A♯3-31'
/// (Note.g.inOctave(2) + const Cent(2)).toString() == 'G2+2'
/// (Note.e.flat.inOctave(3) - const Cent(14)).toString() == 'Eâ™­3-14'
/// (Note.e.flat.inOctave(3) - const Cent(14.6)).toString() == 'Eâ™­3-15'
/// ```
@override
String toString() {
Expand Down
6 changes: 6 additions & 0 deletions test/src/note/closest_pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ void main() {

group('.toString()', () {
test('returns the string representation of this ClosestPitch', () {
expect(ClosestPitch(Note.a.inOctave(-3)).toString(), 'A-3');
expect(
ClosestPitch(Note.f.sharp.inOctave(6), cents: const Cent(0.4))
.toString(),
'F♯6',
);
expect(
ClosestPitch(Note.a.inOctave(4), cents: const Cent(3.456)).toString(),
'A4+3',
Expand Down

0 comments on commit 5fcc757

Please sign in to comment.