Repository navigation
Reject undefined enum values in the Pitch, PitchClass and Section factories [patch] - #535
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
…tories [patch] Pitch.Create and PitchClass.Create added the enum's integer value straight into the note number, so (NoteLetter)1 gave C# and (Accidental)7 turned C4 into G4. Section.Create stored any SectionType, and an undefined one printed as a number that Section.Parse refuses, breaking the round trip. Each factory now throws ArgumentOutOfRangeException naming the parameter, using the Enum.IsDefined check ChordSymbolWriter already applies to chord enums. Fixes #533 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW4QsgMfJRhwEBdboKd
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #533
What was wrong
Pitch.Create(NoteLetter, Accidental, int)andPitchClass.Create(NoteLetter, Accidental)added the enums' integer values straight into the note number.Pitch.Create((NoteLetter)1, Accidental.Natural, 4)gave C#4, andPitch.Create(NoteLetter.C, (Accidental)7, 4)gave G4.Section.Createstored anySectionType.(SectionType)42printed as[42], whichSection.Parserefuses, so theParse(x.ToString()) == xround trip broke.Change
Notation.EnsureDefined(letter, accidental)throwsArgumentOutOfRangeExceptionwithParamNameset toletteroraccidental. Both pitch factories call it.Section.CreatethrowsArgumentOutOfRangeException(ParamName=type) for an undefinedSectionType.Enum.IsDefinedcheck thatChordSymbolWriter.HasSupportedValuesalready applies to chord enums.Tests
PitchTests: an undefined letter, and undefined accidentals 7, 3 and -3PitchClassTests: an undefined letter and an undefined accidentalSectionRoundTripTests.CreateRejectsAnUndefinedSectionTypeSectionRoundTripTests.RoundTripsEveryDefinedSectionTypeguards the round trip for every defined value, as the acceptance criteria askAll seven rejection cases fail on
main(I reverted the fix to confirm) and pass with it. The round-trip guard passes on both.Semantics.Testpasses in full: 1970 passed, 14 skipped, 0 failed.Semantics.Musicbuilds clean on every target framework (net8/9/10, netstandard2.0/2.1).Generated by Claude Code