Exemplo n.º 1
0
        private void RemoveChords_DetectionSettings_EventsCollection_WithoutPredicate(
            ContainerType containerType,
            ChordDetectionSettings settings,
            ICollection <MidiEvent> midiEvents,
            ICollection <MidiEvent> expectedMidiEvents)
        {
            var eventsCollection = new EventsCollection();

            eventsCollection.AddRange(midiEvents);

            var chordsCount = eventsCollection.GetChords(settings).Count;

            switch (containerType)
            {
            case ContainerType.EventsCollection:
            {
                Assert.AreEqual(
                    chordsCount,
                    eventsCollection.RemoveChords(settings),
                    "Invalid count of removed chords.");

                var expectedEventsCollection = new EventsCollection();
                expectedEventsCollection.AddRange(expectedMidiEvents);

                MidiAsserts.AreEqual(expectedEventsCollection, eventsCollection, true, "Events are invalid.");
                Assert.IsTrue(
                    eventsCollection.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))),
                    "There are new events references.");
            }
            break;

            case ContainerType.TrackChunk:
            {
                var trackChunk = new TrackChunk(eventsCollection);

                Assert.AreEqual(
                    chordsCount,
                    trackChunk.RemoveChords(settings),
                    "Invalid count of removed chords.");

                var expectedTrackChunk = new TrackChunk(expectedMidiEvents);
                MidiAsserts.AreEqual(expectedTrackChunk, trackChunk, true, "Events are invalid.");
                Assert.IsTrue(
                    trackChunk.Events.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))),
                    "There are new events references.");
            }
            break;

            case ContainerType.TrackChunks:
            case ContainerType.File:
            {
                RemoveChords_DetectionSettings_TrackChunks_WithoutPredicate(
                    containerType == ContainerType.File,
                    settings,
                    new[] { midiEvents },
                    new[] { expectedMidiEvents });
            }
            break;
            }
        }
        private void GetChords_DetectionSettings_EventsCollection(
            ContainerType containerType,
            ChordDetectionSettings settings,
            ICollection <MidiEvent> midiEvents,
            ICollection <Chord> expectedChords)
        {
            switch (containerType)
            {
            case ContainerType.EventsCollection:
            {
                var eventsCollection = new EventsCollection();
                eventsCollection.AddRange(midiEvents);

                var chords = eventsCollection.GetChords(settings);
                MidiAsserts.AreEqual(expectedChords, chords, "Chords are invalid.");

                var timedObjets = eventsCollection.GetObjects(ObjectType.Chord, new ObjectDetectionSettings {
                        ChordDetectionSettings = settings
                    });
                MidiAsserts.AreEqual(expectedChords, timedObjets, "Chords are invalid from GetObjects.");
            }
            break;

            case ContainerType.TrackChunk:
            {
                var trackChunk = new TrackChunk(midiEvents);

                var chords = trackChunk.GetChords(settings);
                MidiAsserts.AreEqual(expectedChords, chords, "Chords are invalid.");

                var timedObjets = trackChunk.GetObjects(ObjectType.Chord, new ObjectDetectionSettings {
                        ChordDetectionSettings = settings
                    });
                MidiAsserts.AreEqual(expectedChords, timedObjets, "Chords are invalid from GetObjects.");
            }
            break;

            case ContainerType.TrackChunks:
            case ContainerType.File:
            {
                GetChords_DetectionSettings_TrackChunks(
                    containerType == ContainerType.File,
                    settings,
                    new[] { midiEvents },
                    expectedChords);
            }
            break;
            }
        }