1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +08:00

Add too short sliders check and tests

This commit is contained in:
Naxess 2021-07-13 10:50:41 +02:00
parent 6da2a3d51f
commit fec9448301
2 changed files with 193 additions and 0 deletions

View File

@ -0,0 +1,145 @@
// 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 NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Edit.Checks;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
{
[TestFixture]
public class CheckTooShortSlidersTest
{
private CheckTooShortSliders check;
[SetUp]
public void Setup()
{
check = new CheckTooShortSliders();
}
[Test]
public void TestLongSlider()
{
Slider slider = new Slider
{
StartTime = 0,
RepeatCount = 0,
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0)),
new PathControlPoint(new Vector2(100, 0))
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
assertOk(new List<HitObject> { slider });
}
[Test]
public void TestShortSlider()
{
Slider slider = new Slider
{
StartTime = 0,
RepeatCount = 0,
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0)),
new PathControlPoint(new Vector2(25, 0))
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
assertOk(new List<HitObject> { slider });
}
[Test]
public void TestTooShortSliderExpert()
{
Slider slider = new Slider
{
StartTime = 0,
RepeatCount = 0,
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0)),
new PathControlPoint(new Vector2(10, 0))
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
assertOk(new List<HitObject> { slider }, DifficultyRating.Expert);
}
[Test]
public void TestTooShortSlider()
{
Slider slider = new Slider
{
StartTime = 0,
RepeatCount = 0,
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0)),
new PathControlPoint(new Vector2(10, 0))
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
assertTooShort(new List<HitObject> { slider });
}
[Test]
public void TestTooShortSliderWithRepeats()
{
// Would be ok if we looked at the duration, but not if we look at the span duration.
Slider slider = new Slider
{
StartTime = 0,
RepeatCount = 2,
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0)),
new PathControlPoint(new Vector2(10, 0))
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
assertTooShort(new List<HitObject> { slider });
}
private void assertOk(List<HitObject> hitObjects, DifficultyRating difficultyRating = DifficultyRating.Easy)
{
Assert.That(check.Run(getContext(hitObjects, difficultyRating)), Is.Empty);
}
private void assertTooShort(List<HitObject> hitObjects, DifficultyRating difficultyRating = DifficultyRating.Easy)
{
var issues = check.Run(getContext(hitObjects, difficultyRating)).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.First().Template is CheckTooShortSliders.IssueTemplateTooShort);
}
private BeatmapVerifierContext getContext(List<HitObject> hitObjects, DifficultyRating difficultyRating)
{
var beatmap = new Beatmap<HitObject> { HitObjects = hitObjects };
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap), difficultyRating);
}
}
}

View File

@ -0,0 +1,48 @@
// 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 osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Edit.Checks
{
public class CheckTooShortSliders : ICheck
{
/// <summary>
/// The shortest acceptable duration between the head and tail of the slider (so ignoring repeats).
/// </summary>
private const double span_duration_threshold = 125; // 240 BPM 1/2
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Spread, "Too short sliders");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateTooShort(this)
};
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
if (context.InterpretedDifficulty > DifficultyRating.Easy)
yield break;
foreach (var hitObject in context.Beatmap.HitObjects)
{
if (hitObject is Slider slider && slider.SpanDuration < span_duration_threshold)
yield return new IssueTemplateTooShort(this).Create(slider);
}
}
public class IssueTemplateTooShort : IssueTemplate
{
public IssueTemplateTooShort(ICheck check)
: base(check, IssueType.Problem, "This slider is too short ({0:0} ms), expected at least {1:0} ms.")
{
}
public Issue Create(Slider slider) => new Issue(slider, this, slider.SpanDuration, span_duration_threshold);
}
}
}