1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 05:02:55 +08:00
osu-lazer/osu.Game.Tests/Editing/Checks/CheckUnsnappedObjectsTest.cs

160 lines
4.9 KiB
C#
Raw Normal View History

2021-04-26 10:48:56 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2021-05-13 17:24:22 +08:00
using osu.Game.Rulesets.Edit;
2021-04-26 10:48:56 +08:00
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
2021-04-26 10:48:56 +08:00
namespace osu.Game.Tests.Editing.Checks
{
[TestFixture]
public class CheckUnsnappedObjectsTest
2021-04-26 10:48:56 +08:00
{
private CheckUnsnappedObjects check;
2021-04-26 10:48:56 +08:00
private ControlPointInfo cpi;
[SetUp]
public void Setup()
{
check = new CheckUnsnappedObjects();
2021-04-26 10:48:56 +08:00
cpi = new ControlPointInfo();
cpi.Add(100, new TimingControlPoint { BeatLength = 100 });
}
[Test]
public void TestCircleSnapped()
{
assertOk(new List<HitObject>
{
new HitCircle { StartTime = 100 }
});
}
[Test]
public void TestCircleUnsnapped1Ms()
{
assert1Ms(new List<HitObject>
{
new HitCircle { StartTime = 101 }
});
assert1Ms(new List<HitObject>
{
new HitCircle { StartTime = 99 }
});
}
[Test]
public void TestCircleUnsnapped2Ms()
{
assert2Ms(new List<HitObject>
{
new HitCircle { StartTime = 102 }
});
assert2Ms(new List<HitObject>
{
new HitCircle { StartTime = 98 }
});
}
[Test]
public void TestSliderSnapped()
{
// Slider ends are naturally < 1 ms unsnapped because of how SV works.
assertOk(new List<HitObject>
{
2021-04-26 23:44:46 +08:00
getSliderMock(startTime: 100, endTime: 400.75d).Object
2021-04-26 10:48:56 +08:00
});
}
[Test]
public void TestSliderUnsnapped1Ms()
{
assert1Ms(new List<HitObject>
{
getSliderMock(startTime: 101, endTime: 401.75d).Object
}, count: 2);
// End is only off by 0.25 ms, hence count 1.
assert1Ms(new List<HitObject>
{
getSliderMock(startTime: 99, endTime: 399.75d).Object
}, count: 1);
}
[Test]
public void TestSliderUnsnapped2Ms()
{
assert2Ms(new List<HitObject>
{
getSliderMock(startTime: 102, endTime: 402.75d).Object
}, count: 2);
// Start and end are 2 ms and 1.25 ms off respectively, hence two different issues in one object.
2021-05-14 15:22:19 +08:00
var hitObjects = new List<HitObject>
2021-04-26 10:48:56 +08:00
{
getSliderMock(startTime: 98, endTime: 398.75d).Object
};
2021-05-14 15:22:19 +08:00
var issues = check.Run(getContext(hitObjects)).ToList();
2021-04-26 10:48:56 +08:00
Assert.That(issues, Has.Count.EqualTo(2));
2021-04-27 19:56:05 +08:00
Assert.That(issues.Any(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateSmallUnsnap));
Assert.That(issues.Any(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateLargeUnsnap));
2021-04-26 10:48:56 +08:00
}
private Mock<Slider> getSliderMock(double startTime, double endTime, int repeats = 0)
{
var mockSlider = new Mock<Slider>();
mockSlider.SetupGet(s => s.StartTime).Returns(startTime);
mockSlider.As<IHasRepeats>().Setup(r => r.RepeatCount).Returns(repeats);
mockSlider.As<IHasDuration>().Setup(d => d.EndTime).Returns(endTime);
return mockSlider;
}
2021-05-14 15:22:19 +08:00
private void assertOk(List<HitObject> hitObjects)
2021-04-26 10:48:56 +08:00
{
2021-05-14 15:22:19 +08:00
Assert.That(check.Run(getContext(hitObjects)), Is.Empty);
2021-04-26 10:48:56 +08:00
}
2021-05-14 15:22:19 +08:00
private void assert1Ms(List<HitObject> hitObjects, int count = 1)
2021-04-26 10:48:56 +08:00
{
2021-05-14 15:22:19 +08:00
var issues = check.Run(getContext(hitObjects)).ToList();
2021-04-26 10:48:56 +08:00
Assert.That(issues, Has.Count.EqualTo(count));
2021-04-27 19:56:05 +08:00
Assert.That(issues.All(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateSmallUnsnap));
2021-04-26 10:48:56 +08:00
}
2021-05-14 15:22:19 +08:00
private void assert2Ms(List<HitObject> hitObjects, int count = 1)
2021-04-26 10:48:56 +08:00
{
2021-05-14 15:22:19 +08:00
var issues = check.Run(getContext(hitObjects)).ToList();
2021-04-26 10:48:56 +08:00
Assert.That(issues, Has.Count.EqualTo(count));
2021-04-27 19:56:05 +08:00
Assert.That(issues.All(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateLargeUnsnap));
2021-04-26 10:48:56 +08:00
}
2021-05-14 15:22:19 +08:00
private BeatmapVerifierContext getContext(List<HitObject> hitObjects)
2021-04-26 10:48:56 +08:00
{
var beatmap = new Beatmap<HitObject>
2021-04-26 10:48:56 +08:00
{
ControlPointInfo = cpi,
2021-05-14 15:22:19 +08:00
HitObjects = hitObjects
};
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
2021-04-26 10:48:56 +08:00
}
}
}