mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Add unsnap check tests
This commit is contained in:
parent
6fd77e536d
commit
9178aa1d7d
160
osu.Game.Tests/Editing/Checks/CheckUnsnapsTest.cs
Normal file
160
osu.Game.Tests/Editing/Checks/CheckUnsnapsTest.cs
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Game.Rulesets.Edit.Checks;
|
||||||
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Editing.Checks
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class CheckUnsnapsTest
|
||||||
|
{
|
||||||
|
private CheckUnsnaps check;
|
||||||
|
private ControlPointInfo cpi;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
check = new CheckUnsnaps();
|
||||||
|
|
||||||
|
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.
|
||||||
|
var mockSlider = new Mock<Slider>();
|
||||||
|
mockSlider.SetupGet(s => s.StartTime).Returns(100);
|
||||||
|
mockSlider.As<IHasRepeats>().Setup(r => r.RepeatCount).Returns(0);
|
||||||
|
mockSlider.As<IHasDuration>().Setup(d => d.Duration).Returns(400.75d);
|
||||||
|
|
||||||
|
assertOk(new List<HitObject>
|
||||||
|
{
|
||||||
|
mockSlider.Object
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[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.
|
||||||
|
var hitobjects = new List<HitObject>
|
||||||
|
{
|
||||||
|
getSliderMock(startTime: 98, endTime: 398.75d).Object
|
||||||
|
};
|
||||||
|
|
||||||
|
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckUnsnaps.IssueTemplate1MsOrMore));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckUnsnaps.IssueTemplate2MsOrMore));
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertOk(List<HitObject> hitobjects)
|
||||||
|
{
|
||||||
|
Assert.That(check.Run(getPlayableBeatmap(hitobjects), null), Is.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assert1Ms(List<HitObject> hitobjects, int count = 1)
|
||||||
|
{
|
||||||
|
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(count));
|
||||||
|
Assert.That(issues.All(issue => issue.Template is CheckUnsnaps.IssueTemplate1MsOrMore));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assert2Ms(List<HitObject> hitobjects, int count = 1)
|
||||||
|
{
|
||||||
|
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(count));
|
||||||
|
Assert.That(issues.All(issue => issue.Template is CheckUnsnaps.IssueTemplate2MsOrMore));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IBeatmap getPlayableBeatmap(List<HitObject> hitobjects)
|
||||||
|
{
|
||||||
|
return new Beatmap<HitObject>
|
||||||
|
{
|
||||||
|
ControlPointInfo = cpi,
|
||||||
|
HitObjects = hitobjects
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user