예제 #1
0
        public void When_note_choices_have_different_voice_note_choices_they_are_not_equal()
        {
            // arrange
            var voiceNoteChoicesA = new HashSet <VoiceNoteChoice>
            {
                new(Voice.Bass, NoteMotion.Oblique, 2),
                new(Voice.Harmony, NoteMotion.Descending, 13),
                new(Voice.Melody, NoteMotion.Ascending, 124)
            };

            var voiceNoteChoicesB = new HashSet <VoiceNoteChoice>
            {
                new(Voice.Bass, NoteMotion.Oblique, 1),
                new(Voice.Harmony, NoteMotion.Descending, 12),
                new(Voice.Melody, NoteMotion.Ascending, 123)
            };

            var noteChoiceA = new NoteChoice(voiceNoteChoicesA);
            var noteChoiceB = new NoteChoice(voiceNoteChoicesB);

            // act
            var areEqual            = noteChoiceA.Equals(noteChoiceB);
            var areEqualOperator    = noteChoiceA == noteChoiceB;
            var areNotEqualOperator = noteChoiceA != noteChoiceB;
            var areHashCodesEqual   = noteChoiceA.GetHashCode() == noteChoiceB.GetHashCode();

            // assert
            areEqual.Should().BeFalse();
            areEqualOperator.Should().BeFalse();
            areNotEqualOperator.Should().BeTrue();
            areHashCodesEqual.Should().BeFalse();
        }
예제 #2
0
        public void When_other_NoteChoice_is_null_they_are_not_equal()
        {
            // arrange
            var noteChoice = new NoteChoice(new HashSet <VoiceNoteChoice>());

            // act
            var areEqual       = noteChoice.Equals(null);
            var areObjectEqual = noteChoice.Equals((object)null);

            // assert
            areEqual.Should().BeFalse();
            areObjectEqual.Should().BeFalse();
        }
예제 #3
0
        public void When_other_NoteChoice_is_not_a_NoteChoice_they_are_not_equal()
        {
            // arrange
            var voiceNoteChoices = new HashSet <VoiceNoteChoice>();

            var noteChoice  = new NoteChoice(voiceNoteChoices);
            var noteChoiceB = new { SomeField = 1 };

            // act
            var areEqual = noteChoice.Equals(noteChoiceB);

            // assert
            areEqual.Should().BeFalse();
        }
예제 #4
0
        public void When_other_NoteChoice_is_same_reference_they_are_equal()
        {
            // arrange
            var noteChoice  = new NoteChoice(new HashSet <VoiceNoteChoice>());
            var noteChoiceB = noteChoice;

            // act
            var areEqual       = noteChoice.Equals(noteChoiceB);
            var areObjectEqual = noteChoice.Equals((object)noteChoiceB);

            // assert
            areEqual.Should().BeTrue();
            areObjectEqual.Should().BeTrue();
        }
예제 #5
0
 /// <summary>
 /// Creates a new NotePair with the given values.
 /// </summary>
 /// <param name="cantusFirmusNote">The cantus firmus note to use</param>
 /// <param name="counterPointNote">The counterpoint note to use</param>
 /// <param name="arrivedFromCompositionContext">The arrived from composition context to use</param>
 /// <param name="arrivedFromNoteChoice">The arrived from note choice to use</param>
 /// <returns></returns>
 public NotePair CreateNotePair(
     int cantusFirmusNote,
     int counterPointNote,
     CompositionContext arrivedFromCompositionContext,
     NoteChoice arrivedFromNoteChoice
     )
 {
     return(new NotePair(
                cantusFirmusNote,
                counterPointNote,
                arrivedFromCompositionContext,
                arrivedFromNoteChoice,
                ScaleDegreeEvaluator
                ));
 }
예제 #6
0
 /// <summary>
 /// Add notes to the composition.
 /// </summary>
 /// <param name="cantusFirmusNote">The cantus firmus note to add</param>
 /// <param name="counterPointNote">The counterpoint note to add</param>
 /// <param name="arrivedFromCompositionContext">The composition context from which the notes were generated</param>
 /// <param name="arrivedFromNoteChoice">The note choice which led to these notes being generated</param>
 public void AddNotes(
     int cantusFirmusNote,
     int counterPointNote,
     CompositionContext arrivedFromCompositionContext,
     NoteChoice arrivedFromNoteChoice
     )
 {
     _notePairs.Add(
         _factory.CreateNotePair(
             cantusFirmusNote,
             counterPointNote,
             arrivedFromCompositionContext,
             arrivedFromNoteChoice
             )
         );
 }
예제 #7
0
        public void GetVoiceNoteChoice_returns_expected_VoiceNoteChoice()
        {
            // arrange
            var voiceNoteChoices = new HashSet <VoiceNoteChoice>
            {
                new(Voice.Bass, NoteMotion.Oblique, 1),
                new(Voice.Harmony, NoteMotion.Descending, 12),
                new(Voice.Melody, NoteMotion.Ascending, 123)
            };

            var noteChoice = new NoteChoice(voiceNoteChoices);

            // act
            var voiceNoteChoice = noteChoice.GetVoiceNoteChoice(Voice.Melody);

            // assert
            voiceNoteChoice.Should().Be(new VoiceNoteChoice(Voice.Melody, NoteMotion.Ascending, 123));
        }
예제 #8
0
        public void When_other_VoiceNoteChoices_are_null_they_are_not_equal()
        {
            // arrange
            var voiceNoteChoices = new HashSet <VoiceNoteChoice>
            {
                new(Voice.Bass, NoteMotion.Oblique, 2),
                new(Voice.Harmony, NoteMotion.Descending, 13),
                new(Voice.Melody, NoteMotion.Ascending, 124)
            };

            var noteChoice  = new NoteChoice(voiceNoteChoices);
            var noteChoiceB = new NoteChoice(null);

            // act
            var areEqual = noteChoice.Equals(noteChoiceB);

            // assert
            areEqual.Should().BeFalse();
        }
예제 #9
0
        /// <summary>
        /// Minimizes the roll space for the given CompositionContext and detrimental NoteChoice to help prevent choosing
        /// that detrimental note again.
        /// </summary>
        /// <param name="context">The CompositionContext which led to the NoteChoice being chosen</param>
        /// <param name="noteChoice">The detrimental NoteChoice</param>
        public void MinimizeDetrimentalNoteChoiceWeight(CompositionContext context, NoteChoice noteChoice)
        {
            var specificContext = _compositionContexts.GetSpecificContext(context);
            var noteChoiceWeightsNoteChoices = StrategyDictionary[specificContext];

            var foundNoteChoiceWeightNoteChoice =
                noteChoiceWeightsNoteChoices.FirstOrDefault(
                    noteWeightNoteChoice => noteWeightNoteChoice.NoteChoice.Equals(noteChoice)
                    );

            var index = noteChoiceWeightsNoteChoices.IndexOf(foundNoteChoiceWeightNoteChoice);

            switch (index)
            {
            case -1:
                return;

            case 0:
                var firstNoteChoiceWeightNoteChoice  = noteChoiceWeightsNoteChoices[0];
                var secondNoteChoiceWeightNoteChoice = noteChoiceWeightsNoteChoices[1];

                firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight        = AdjustedNoteChoiceWeightValue;
                firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling = AdjustedNoteChoiceWeightValue;

                secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                    firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight + 1;
                secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                    secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                    secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                break;

            default:
                if (index == noteChoiceWeightsNoteChoices.Count - 1)
                {
                    var lastNoteChoiceWeightNoteChoice =
                        noteChoiceWeightsNoteChoices[noteChoiceWeightsNoteChoices.Count - 1];
                    var secondToLastNoteChoiceWeightNoteChoice =
                        noteChoiceWeightsNoteChoices[noteChoiceWeightsNoteChoices.Count - 2];

                    lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight      = AdjustedNoteChoiceWeightValue;
                    lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                        _noteChoiceWeightGenerator.GetNoteChoiceWeightCeiling(noteChoiceWeightsNoteChoices.Count) -
                        lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight;

                    secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling =
                        lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor - 1;
                    secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                        secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                        secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                }
                else
                {
                    var noteChoiceWeightNoteChoice     = noteChoiceWeightsNoteChoices[index];
                    var nextNoteChoiceWeightNoteChoice = noteChoiceWeightsNoteChoices[index + 1];

                    noteChoiceWeightNoteChoice.NoteChoiceWeight.Weight        = AdjustedNoteChoiceWeightValue;
                    noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling =
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor +
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.Weight;

                    nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling + 1;
                    nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                        nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                        nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                }

                break;
            }
        }
 /// <summary>
 /// NoteChoiceWeightNoteChoice constructor.
 /// </summary>
 /// <param name="noteChoiceWeight">The NoteChoiceWeight object to initialize this NoteChoiceWeightNoteChoice with</param>
 /// <param name="noteChoice">The NoteChoice object to initialize this NoteChoiceWeightNoteChoice with</param>
 public NoteChoiceWeightNoteChoice(NoteChoiceWeight noteChoiceWeight, NoteChoice noteChoice)
 {
     NoteChoiceWeight = noteChoiceWeight;
     NoteChoice       = noteChoice;
 }