2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-10-28 10:34:41 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2021-08-30 13:12:30 +08:00
|
|
|
|
using osu.Game.Beatmaps.Legacy;
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.NonVisual
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class ControlPointInfoTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAdd()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
cpi.Add(0, new TimingControlPoint());
|
|
|
|
|
cpi.Add(1000, new TimingControlPoint { BeatLength = 500 });
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddRedundantTiming()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
cpi.Add(0, new TimingControlPoint()); // is *not* redundant, special exception for first timing point.
|
2020-04-08 16:42:35 +08:00
|
|
|
|
cpi.Add(1000, new TimingControlPoint()); // is also not redundant, due to change of offset
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
2020-04-08 16:42:35 +08:00
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
|
|
|
|
|
|
2020-05-05 09:31:11 +08:00
|
|
|
|
cpi.Add(1000, new TimingControlPoint()); // is redundant
|
2020-04-08 16:42:35 +08:00
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
|
2023-02-28 18:27:46 +08:00
|
|
|
|
|
|
|
|
|
cpi.Add(1200, new TimingControlPoint { OmitFirstBarLine = true }); // is not redundant
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(3));
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(3));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(3));
|
|
|
|
|
|
|
|
|
|
cpi.Add(1500, new TimingControlPoint { OmitFirstBarLine = true }); // is not redundant
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(4));
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(4));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(4));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddRedundantDifficulty()
|
|
|
|
|
{
|
2021-08-31 15:31:48 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
cpi.Add(0, new DifficultyControlPoint()); // is redundant
|
|
|
|
|
cpi.Add(1000, new DifficultyControlPoint()); // is redundant
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(0));
|
2019-12-13 17:13:24 +08:00
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(0));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(0));
|
|
|
|
|
|
2021-08-31 22:59:36 +08:00
|
|
|
|
cpi.Add(1000, new DifficultyControlPoint { SliderVelocity = 2 }); // is not redundant
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddRedundantSample()
|
|
|
|
|
{
|
2021-08-25 17:00:57 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
2019-12-13 17:12:44 +08:00
|
|
|
|
cpi.Add(0, new SampleControlPoint()); // is *not* redundant, special exception for first sample point
|
2019-10-28 10:34:41 +08:00
|
|
|
|
cpi.Add(1000, new SampleControlPoint()); // is redundant
|
|
|
|
|
|
2019-12-13 17:12:44 +08:00
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
2019-12-13 17:13:24 +08:00
|
|
|
|
Assert.That(cpi.SamplePoints.Count, Is.EqualTo(1));
|
2019-12-13 17:12:44 +08:00
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(1));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
cpi.Add(1000, new SampleControlPoint { SampleVolume = 50 }); // is not redundant
|
|
|
|
|
|
2019-12-13 17:12:44 +08:00
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.SamplePoints.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddRedundantEffect()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
cpi.Add(0, new EffectControlPoint()); // is redundant
|
|
|
|
|
cpi.Add(1000, new EffectControlPoint()); // is redundant
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(0));
|
2019-12-13 17:13:24 +08:00
|
|
|
|
Assert.That(cpi.EffectPoints.Count, Is.EqualTo(0));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(0));
|
|
|
|
|
|
2023-02-28 18:27:46 +08:00
|
|
|
|
cpi.Add(1000, new EffectControlPoint { KiaiMode = true }); // is not redundant
|
|
|
|
|
cpi.Add(1400, new EffectControlPoint { KiaiMode = true }); // is redundant
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
2023-02-28 18:27:46 +08:00
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.EffectPoints.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(1));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddGroup()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
var group2 = cpi.GroupAt(1000, true);
|
|
|
|
|
|
|
|
|
|
Assert.That(group, Is.EqualTo(group2));
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGroupAtLookupOnly()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(5000, true);
|
|
|
|
|
Assert.That(group, Is.Not.Null);
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.GroupAt(1000), Is.Null);
|
|
|
|
|
Assert.That(cpi.GroupAt(5000), Is.Not.Null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddRemoveGroup()
|
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
cpi.RemoveGroup(group);
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 14:28:08 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRemoveGroupAlsoRemovedControlPoints()
|
|
|
|
|
{
|
2021-08-25 17:00:57 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2020-10-02 14:28:08 +08:00
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
|
|
|
|
|
group.Add(new SampleControlPoint());
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.SamplePoints.Count, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
cpi.RemoveGroup(group);
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.SamplePoints.Count, Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-28 10:34:41 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddControlPointToGroup()
|
|
|
|
|
{
|
2021-08-31 15:31:48 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
// usually redundant, but adding to group forces it to be added
|
|
|
|
|
group.Add(new DifficultyControlPoint());
|
|
|
|
|
|
|
|
|
|
Assert.That(group.ControlPoints.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAddDuplicateControlPointToGroup()
|
|
|
|
|
{
|
2021-08-31 15:31:48 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
group.Add(new DifficultyControlPoint());
|
2021-08-31 22:59:36 +08:00
|
|
|
|
group.Add(new DifficultyControlPoint { SliderVelocity = 2 });
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
Assert.That(group.ControlPoints.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(1));
|
2021-08-31 22:59:36 +08:00
|
|
|
|
Assert.That(cpi.DifficultyPoints.First().SliderVelocity, Is.EqualTo(2));
|
2019-10-28 10:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestRemoveControlPointFromGroup()
|
|
|
|
|
{
|
2021-08-31 15:31:48 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
var group = cpi.GroupAt(1000, true);
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
var difficultyPoint = new DifficultyControlPoint();
|
|
|
|
|
|
|
|
|
|
group.Add(difficultyPoint);
|
|
|
|
|
group.Remove(difficultyPoint);
|
|
|
|
|
|
|
|
|
|
Assert.That(group.ControlPoints.Count, Is.EqualTo(0));
|
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(0));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count, Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestOrdering()
|
|
|
|
|
{
|
2021-09-06 21:04:51 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
cpi.Add(0, new TimingControlPoint());
|
|
|
|
|
cpi.Add(1000, new TimingControlPoint { BeatLength = 500 });
|
|
|
|
|
cpi.Add(10000, new TimingControlPoint { BeatLength = 200 });
|
|
|
|
|
cpi.Add(5000, new TimingControlPoint { BeatLength = 100 });
|
2021-08-31 22:59:36 +08:00
|
|
|
|
cpi.Add(3000, new DifficultyControlPoint { SliderVelocity = 2 });
|
|
|
|
|
cpi.GroupAt(7000, true).Add(new DifficultyControlPoint { SliderVelocity = 4 });
|
2019-10-28 10:34:41 +08:00
|
|
|
|
cpi.GroupAt(1000).Add(new SampleControlPoint { SampleVolume = 0 });
|
|
|
|
|
cpi.GroupAt(8000, true).Add(new EffectControlPoint { KiaiMode = true });
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count, Is.EqualTo(8));
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups, Is.Ordered.Ascending.By(nameof(ControlPointGroup.Time)));
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.AllControlPoints, Is.Ordered.Ascending.By(nameof(ControlPoint.Time)));
|
|
|
|
|
Assert.That(cpi.TimingPoints, Is.Ordered.Ascending.By(nameof(ControlPoint.Time)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestClear()
|
|
|
|
|
{
|
2021-08-31 15:31:48 +08:00
|
|
|
|
var cpi = new LegacyControlPointInfo();
|
2019-10-28 10:34:41 +08:00
|
|
|
|
|
|
|
|
|
cpi.Add(0, new TimingControlPoint());
|
|
|
|
|
cpi.Add(1000, new TimingControlPoint { BeatLength = 500 });
|
|
|
|
|
cpi.Add(10000, new TimingControlPoint { BeatLength = 200 });
|
|
|
|
|
cpi.Add(5000, new TimingControlPoint { BeatLength = 100 });
|
2021-08-31 22:59:36 +08:00
|
|
|
|
cpi.Add(3000, new DifficultyControlPoint { SliderVelocity = 2 });
|
|
|
|
|
cpi.GroupAt(7000, true).Add(new DifficultyControlPoint { SliderVelocity = 4 });
|
2019-10-28 10:34:41 +08:00
|
|
|
|
cpi.GroupAt(1000).Add(new SampleControlPoint { SampleVolume = 0 });
|
|
|
|
|
cpi.GroupAt(8000, true).Add(new EffectControlPoint { KiaiMode = true });
|
|
|
|
|
|
|
|
|
|
cpi.Clear();
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(0));
|
|
|
|
|
Assert.That(cpi.DifficultyPoints.Count, Is.EqualTo(0));
|
|
|
|
|
Assert.That(cpi.AllControlPoints.Count, Is.EqualTo(0));
|
|
|
|
|
}
|
2021-01-05 12:14:16 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
2021-07-19 11:38:22 +08:00
|
|
|
|
public void TestDeepClone()
|
2021-01-05 12:14:16 +08:00
|
|
|
|
{
|
|
|
|
|
var cpi = new ControlPointInfo();
|
|
|
|
|
|
|
|
|
|
cpi.Add(1000, new TimingControlPoint { BeatLength = 500 });
|
|
|
|
|
|
2021-07-19 11:38:22 +08:00
|
|
|
|
var cpiCopy = cpi.DeepClone();
|
2021-01-05 12:14:16 +08:00
|
|
|
|
|
|
|
|
|
cpiCopy.Add(2000, new TimingControlPoint { BeatLength = 500 });
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.Groups.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpiCopy.Groups.Count, Is.EqualTo(2));
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(1));
|
|
|
|
|
Assert.That(cpiCopy.TimingPoints.Count, Is.EqualTo(2));
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.TimingPoints[0], Is.Not.SameAs(cpiCopy.TimingPoints[0]));
|
|
|
|
|
Assert.That(cpi.TimingPoints[0].BeatLengthBindable, Is.Not.SameAs(cpiCopy.TimingPoints[0].BeatLengthBindable));
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.TimingPoints[0].BeatLength, Is.EqualTo(cpiCopy.TimingPoints[0].BeatLength));
|
|
|
|
|
|
|
|
|
|
cpi.TimingPoints[0].BeatLength = 800;
|
|
|
|
|
|
|
|
|
|
Assert.That(cpi.TimingPoints[0].BeatLength, Is.Not.EqualTo(cpiCopy.TimingPoints[0].BeatLength));
|
|
|
|
|
}
|
2019-10-28 10:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|