Add comprehensive tests for toSpelledPitch(Pitch) and toPitch(SpelledPitch).

This commit is contained in:
2026-01-10 10:43:06 -06:00
parent 7ff6dde168
commit 18bc7d25ac
2 changed files with 61 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
pco_chords pco_chords
src/notation src/pco_chordspkg/notation
.*.sw? .*.sw?

View File

@@ -387,3 +387,63 @@ when isMainModule:
assert "#5" == $toScaleDegree( assert "#5" == $toScaleDegree(
Key(tonic: parseSpelledPitch("Eb"), mode: Ionian), Key(tonic: parseSpelledPitch("Eb"), mode: Ionian),
parseSpelledPitch("B")) parseSpelledPitch("B"))
assert toSpelledPitch(Pitch.F + 2) ==
SpelledPitch(note: Note.G, alteration: naNatural)
let pitchCases = [
(Pitch.Af, SpelledPitch(note: Note.A, alteration: naFlat)),
(Pitch.A, SpelledPitch(note: Note.A, alteration: naNatural)),
(Pitch.Bf, SpelledPitch(note: Note.B, alteration: naFlat)),
(Pitch.B, SpelledPitch(note: Note.B, alteration: naNatural)),
(Pitch.C, SpelledPitch(note: Note.C, alteration: naNatural)),
(Pitch.Df, SpelledPitch(note: Note.D, alteration: naFlat)),
(Pitch.D, SpelledPitch(note: Note.D, alteration: naNatural)),
(Pitch.Ef, SpelledPitch(note: Note.E, alteration: naFlat)),
(Pitch.E, SpelledPitch(note: Note.E, alteration: naNatural)),
(Pitch.F, SpelledPitch(note: Note.F, alteration: naNatural)),
(Pitch.Gf, SpelledPitch(note: Note.G, alteration: naFlat)),
(Pitch.G, SpelledPitch(note: Note.G, alteration: naNatural)),
]
for (pitch, expected) in pitchCases:
assert toSpelledPitch(pitch) == expected
let spelledPitchCases = [
("Ab", Pitch.Af),
("G#", Pitch.Af),
("A", Pitch.A),
("G##", Pitch.A),
("Bbb", Pitch.A),
("Bb", Pitch.Bf),
("A#", Pitch.Bf),
("Cbb", Pitch.Bf),
("B", Pitch.B),
("Cb", Pitch.B),
("A##", Pitch.B),
("C", Pitch.C),
("B#", Pitch.C),
("Dbb", Pitch.C),
("Db", Pitch.Df),
("C#", Pitch.Df),
("B##", Pitch.Df),
("D", Pitch.D),
("C##", Pitch.D),
("Ebb", Pitch.D),
("Eb", Pitch.Ef),
("D#", Pitch.Ef),
("Fbb", Pitch.Ef),
("E", Pitch.E),
("Fb", Pitch.E),
("D##", Pitch.E),
("F", Pitch.F),
("E#", Pitch.F),
("Gbb", Pitch.F),
("Gb", Pitch.Gf),
("F#", Pitch.Gf),
("E##", Pitch.Gf),
("G", Pitch.G),
("F##", Pitch.G),
("Abb", Pitch.G),
]
for (spelled, expected) in spelledPitchCases:
assert parseSpelledPitch(spelled).toPitch == expected