Esempio n. 1
0
        public void SplitByStep_UnequalDivision()
        {
            var tempoMap = TempoMap.Default;

            var partsNumber     = 10;
            var step            = 1000L;
            var inputObjects    = CreateInputObjects(step * (partsNumber - 1) + step / 2).ToArray();
            var expectedObjects = inputObjects.SelectMany(o => Split(o, Enumerable.Range(1, partsNumber - 1).Select(i => o.Time + step * i)));
            var actualObjects   = Splitter.SplitByStep(inputObjects, (MidiTimeSpan)step, tempoMap).ToArray();

            Assert.AreEqual(inputObjects.Length * partsNumber,
                            actualObjects.Length,
                            "Parts count is invalid.");
            Assert.IsTrue(Enumerable.Range(0, inputObjects.Length)
                          .SelectMany(i => actualObjects.Skip(partsNumber * i)
                                      .Take(partsNumber - 1))
                          .All(o => o.Length == step),
                          "Length of some objects (except the last one) doesn't equal to the step.");
            Assert.IsTrue(Enumerable.Range(0, inputObjects.Length)
                          .All(i => actualObjects.Skip(partsNumber * i)
                               .Take(partsNumber)
                               .Last()
                               .Length < step),
                          "Last object's length is not less than the step.");
            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 2
0
        private SplitData SplitByGrid_ClonesExpected(IEnumerable <TObject> inputObjects, ITimeSpan gridStart, IEnumerable <ITimeSpan> gridSteps, TempoMap tempoMap)
        {
            var expectedObjects = inputObjects.Select(o => o == null ? default(TObject) : ObjectMethods.Clone(o)).ToArray();
            var actualObjects   = Splitter.SplitByGrid(inputObjects, new SteppedGrid(gridStart, gridSteps), tempoMap).ToArray();

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);

            return(new SplitData(inputObjects, expectedObjects, actualObjects));
        }
Esempio n. 3
0
        public void SplitAtDistance_FullLengthRatio(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(1000);
            var ratio           = 1.0;
            var expectedObjects = inputObjects.Select(o => ObjectMethods.Clone(o));
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, ratio, TimeSpanType.Midi, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 4
0
        public void SplitByStep_EmptyCollection()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = Enumerable.Empty <TObject>();
            var step            = (MidiTimeSpan)100;
            var expectedObjects = Enumerable.Empty <TObject>();
            var actualObjects   = Splitter.SplitByStep(inputObjects, step, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 5
0
        public void SplitAtDistance_ByRatio_Nulls(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = new[] { default(TObject), default(TObject) };
            var ratio           = 0.5;
            var expectedObjects = new[] { default(TObject), default(TObject) };
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, ratio, TimeSpanType.Midi, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 6
0
        public void SplitAtDistance_ByRatio_EmptyCollection(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = Enumerable.Empty <TObject>();
            var ratio           = 0.5;
            var expectedObjects = Enumerable.Empty <TObject>();
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, ratio, TimeSpanType.Midi, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 7
0
        public void SplitAtDistance_BigDistance(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(1000);
            var distance        = (MidiTimeSpan)1000;
            var expectedObjects = inputObjects.Select(o => ObjectMethods.Clone(o));
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, distance, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 8
0
        public void SplitAtDistance_Nulls(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = new[] { default(TObject), default(TObject) };
            var distance        = (MidiTimeSpan)100;
            var expectedObjects = new[] { default(TObject), default(TObject) };
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, distance, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 9
0
        public void SplitAtDistance_EmptyCollection(LengthedObjectTarget from)
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = Enumerable.Empty <TObject>();
            var distance        = (MidiTimeSpan)100;
            var expectedObjects = Enumerable.Empty <TObject>();
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, distance, from, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 10
0
        public void SplitByPartsNumber_ZeroLength()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(0);
            var partsNumber     = 10;
            var expectedObjects = inputObjects.SelectMany(o => Enumerable.Range(0, partsNumber).Select(i => ObjectMethods.Clone(o)));
            var actualObjects   = Splitter.SplitByPartsNumber(inputObjects, partsNumber, TimeSpanType.Midi, tempoMap).ToArray();

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 11
0
        public void SplitByPartsNumber_OnePart()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(100);
            var partsNumber     = 1;
            var expectedObjects = inputObjects.Select(o => ObjectMethods.Clone(o));
            var actualObjects   = Splitter.SplitByPartsNumber(inputObjects, partsNumber, TimeSpanType.Midi, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 12
0
        public void SplitByPartsNumber_Nulls()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = new[] { default(TObject), default(TObject) };
            var partsNumber     = 100;
            var expectedObjects = new[] { default(TObject), default(TObject) };
            var actualObjects   = Splitter.SplitByPartsNumber(inputObjects, partsNumber, TimeSpanType.Midi, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 13
0
        public void SplitByPartsNumber_EmptyCollection()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = Enumerable.Empty <TObject>();
            var partsNumber     = 100;
            var expectedObjects = Enumerable.Empty <TObject>();
            var actualObjects   = Splitter.SplitByPartsNumber(inputObjects, partsNumber, TimeSpanType.Midi, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 14
0
        public void SplitAtDistance_ByRatio_End()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(1000);
            var ratio           = 0.1;
            var expectedObjects = inputObjects.SelectMany(o => Split(o, new[] { o.Time + o.Length - 100 }));
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, ratio, TimeSpanType.Midi, LengthedObjectTarget.End, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 15
0
        public void SplitAtDistance_End()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = CreateInputObjects(1000);
            var distance        = (MidiTimeSpan)10;
            var expectedObjects = inputObjects.SelectMany(o => Split(o, new[] { o.Time + o.Length - distance }));
            var actualObjects   = Splitter.SplitAtDistance(inputObjects, distance, LengthedObjectTarget.End, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 16
0
        public void SplitByStep_StepEqualObjectsLength()
        {
            var tempoMap = TempoMap.Default;

            var step            = 1000L;
            var inputObjects    = CreateInputObjects(step);
            var expectedObjects = inputObjects.Select(o => ObjectMethods.Clone(o));
            var actualObjects   = Splitter.SplitByStep(inputObjects, (MidiTimeSpan)step, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 17
0
        public void SplitByStep_Nulls()
        {
            var tempoMap = TempoMap.Default;

            var inputObjects    = new[] { default(TObject), default(TObject) };
            var step            = (MidiTimeSpan)100;
            var expectedObjects = new[] { default(TObject), default(TObject) };
            var actualObjects   = Splitter.SplitByStep(inputObjects, step, tempoMap);

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 18
0
        private SplitData SplitByPartsNumber(long objectsLength, int partsNumber, TimeSpanType lengthType, TempoMap tempoMap)
        {
            var inputObjects    = CreateInputObjects(objectsLength).ToArray();
            var expectedObjects = GetExpectedObjectsByPartsNumber(inputObjects, partsNumber).ToArray();
            var actualObjects   = Splitter.SplitByPartsNumber(inputObjects, partsNumber, lengthType, tempoMap).ToArray();

            Assert.AreEqual(inputObjects.Length * partsNumber,
                            actualObjects.Length,
                            "Parts count is invalid.");
            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);

            return(new SplitData(inputObjects, expectedObjects, actualObjects));
        }
Esempio n. 19
0
        public void SplitByStep_EqualDivision()
        {
            var tempoMap = TempoMap.Default;

            var partsNumber     = 10;
            var step            = 1000L;
            var inputObjects    = CreateInputObjects(step * partsNumber).ToArray();
            var expectedObjects = inputObjects.SelectMany(o => Split(o, Enumerable.Range(1, partsNumber - 1).Select(i => o.Time + step * i)));
            var actualObjects   = Splitter.SplitByStep(inputObjects, (MidiTimeSpan)step, tempoMap).ToArray();

            Assert.AreEqual(inputObjects.Length * partsNumber,
                            actualObjects.Length,
                            "Parts count is invalid.");
            Assert.IsTrue(actualObjects.All(o => o.Length == step),
                          "Length of some objects doesn't equal to the step.");
            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 20
0
        private void SplitByGrid_MultipleSteps(IEnumerable <TObject> inputObjects,
                                               ITimeSpan gridStart,
                                               IEnumerable <ITimeSpan> gridSteps,
                                               Dictionary <TObject, IEnumerable <TimeAndLength> > expectedParts,
                                               TempoMap tempoMap)
        {
            var expectedObjects = expectedParts
                                  .SelectMany(p => p.Value.Select(tl => CloneAndChangeTimeAndLength(
                                                                      p.Key,
                                                                      TimeConverter.ConvertFrom(tl.Time, tempoMap),
                                                                      LengthConverter.ConvertFrom(tl.Length, tl.Time, tempoMap))))
                                  .ToArray();

            var actualObjects = Splitter.SplitByGrid(inputObjects, new SteppedGrid(gridStart, gridSteps), tempoMap).ToArray();

            ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects);
        }
Esempio n. 21
0
        private void Merge(IEnumerable <Note> inputNotes,
                           IEnumerable <Note> expectedNotes,
                           TempoMap tempoMap,
                           VelocityMergingPolicy velocityMergingPolicy    = VelocityMergingPolicy.First,
                           VelocityMergingPolicy offVelocityMergingPolicy = VelocityMergingPolicy.Last,
                           ITimeSpan tolerance = null)
        {
            var settings = new NotesMergingSettings
            {
                VelocityMergingPolicy    = velocityMergingPolicy,
                OffVelocityMergingPolicy = offVelocityMergingPolicy,
                Tolerance = tolerance ?? new MidiTimeSpan()
            };

            var actualNotes = new NotesMerger().Merge(inputNotes, tempoMap, settings);

            ObjectMethods.AssertCollectionsAreEqual(expectedNotes.OrderBy(n => n.Time),
                                                    actualNotes.OrderBy(n => n.Time),
                                                    "Merging detached notes failed.");

            //

            var trackChunk = inputNotes.ToTrackChunk();

            trackChunk.MergeNotes(tempoMap, settings);

            ObjectMethods.AssertCollectionsAreEqual(expectedNotes.OrderBy(n => n.Time),
                                                    trackChunk.GetNotes(),
                                                    "Merging notes inside a track chunk failed.");

            //

            var midiFile = inputNotes.ToFile();

            midiFile.MergeNotes(settings);

            ObjectMethods.AssertCollectionsAreEqual(expectedNotes.OrderBy(n => n.Time),
                                                    midiFile.GetNotes(),
                                                    "Merging notes inside a file failed.");
        }