1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 09:32:56 +08:00

Code cleanup and added tests for the spinner check

This commit is contained in:
Darius Wattimena 2021-11-10 00:16:29 +01:00
parent fbfed16756
commit 5d8f35f3c9
3 changed files with 137 additions and 14 deletions

View File

@ -0,0 +1,118 @@
// 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.Rulesets.Catch.Edit.Checks;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Rulesets.Catch.Tests.Editor.Checks
{
[TestFixture]
public class TestCheckBananaShowerGap
{
private CheckBananaShowerGap check;
[SetUp]
public void Setup()
{
check = new CheckBananaShowerGap();
}
[Test]
public void TestAllowedSpinnerGaps()
{
assertOk(mockBeatmap(250, 1000, 1250), DifficultyRating.Easy);
assertOk(mockBeatmap(250, 1000, 1250), DifficultyRating.Normal);
assertOk(mockBeatmap(125, 1000, 1250), DifficultyRating.Hard);
assertOk(mockBeatmap(125, 1000, 1125), DifficultyRating.Insane);
assertOk(mockBeatmap(62, 1000, 1125), DifficultyRating.Expert);
assertOk(mockBeatmap(62, 1000, 1125), DifficultyRating.ExpertPlus);
}
[Test]
public void TestDisallowedSpinnerGapStart()
{
assertTooShortSpinnerStart(mockBeatmap(249, 1000, 1250), DifficultyRating.Easy);
assertTooShortSpinnerStart(mockBeatmap(249, 1000, 1250), DifficultyRating.Normal);
assertTooShortSpinnerStart(mockBeatmap(124, 1000, 1250), DifficultyRating.Hard);
assertTooShortSpinnerStart(mockBeatmap(124, 1000, 1250), DifficultyRating.Insane);
assertTooShortSpinnerStart(mockBeatmap(61, 1000, 1250), DifficultyRating.Expert);
assertTooShortSpinnerStart(mockBeatmap(61, 1000, 1250), DifficultyRating.ExpertPlus);
}
[Test]
public void TestDisallowedSpinnerGapEnd()
{
assertTooShortSpinnerEnd(mockBeatmap(250, 1000, 1249), DifficultyRating.Easy);
assertTooShortSpinnerEnd(mockBeatmap(250, 1000, 1249), DifficultyRating.Normal);
assertTooShortSpinnerEnd(mockBeatmap(125, 1000, 1249), DifficultyRating.Hard);
assertTooShortSpinnerEnd(mockBeatmap(125, 1000, 1124), DifficultyRating.Insane);
assertTooShortSpinnerEnd(mockBeatmap(62, 1000, 1124), DifficultyRating.Expert);
assertTooShortSpinnerEnd(mockBeatmap(62, 1000, 1124), DifficultyRating.ExpertPlus);
}
[Test]
public void TestConsecutiveSpinners()
{
var spinnerConsecutiveBeatmap = new Beatmap<HitObject>
{
HitObjects = new List<HitObject>
{
new BananaShower { StartTime = 0, EndTime = 100, X = 0 },
new BananaShower { StartTime = 101, EndTime = 200, X = 0 },
new BananaShower { StartTime = 201, EndTime = 300, X = 0 }
}
};
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.Easy);
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.Normal);
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.Hard);
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.Insane);
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.Expert);
assertOk(spinnerConsecutiveBeatmap, DifficultyRating.ExpertPlus);
}
private Beatmap<HitObject> mockBeatmap(double bananaShowerStart, double bananaShowerEnd, double nextFruitStart)
{
return new Beatmap<HitObject>
{
HitObjects = new List<HitObject>
{
new Fruit { StartTime = 0, X = 0 },
new BananaShower { StartTime = bananaShowerStart, EndTime = bananaShowerEnd, X = 0 },
new Fruit { StartTime = nextFruitStart, X = 0 }
}
};
}
private void assertOk(IBeatmap beatmap, DifficultyRating difficultyRating)
{
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap), difficultyRating);
Assert.That(check.Run(context), Is.Empty);
}
private void assertTooShortSpinnerStart(IBeatmap beatmap, DifficultyRating difficultyRating)
{
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap), difficultyRating);
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.All(issue => issue.Template is CheckBananaShowerGap.IssueTemplateBananaShowerStartGap));
}
private void assertTooShortSpinnerEnd(IBeatmap beatmap, DifficultyRating difficultyRating)
{
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap), difficultyRating);
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.All(issue => issue.Template is CheckBananaShowerGap.IssueTemplateBananaShowerEndGap));
}
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Catch.Edit
{
private readonly List<ICheck> checks = new List<ICheck>
{
new CheckTooShortSpinnerGap()
new CheckBananaShowerGap()
};
public IEnumerable<Issue> Run(BeatmapVerifierContext context)

View File

@ -10,7 +10,10 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Catch.Edit.Checks
{
public class CheckTooShortSpinnerGap : ICheck
/// <summary>
/// Check the spinner/banana shower gaps specified in the osu!catch difficulty specific ranking criteria.
/// </summary>
public class CheckBananaShowerGap : ICheck
{
private static readonly int[] spinner_start_delta_threshold = { 250, 250, 125, 125, 62, 62 };
private static readonly int[] spinner_end_delta_threshold = { 250, 250, 250, 125, 125, 125 };
@ -19,8 +22,8 @@ namespace osu.Game.Rulesets.Catch.Edit.Checks
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateSpinnerStartGap(this),
new IssueTemplateSpinnerEndGap(this)
new IssueTemplateBananaShowerStartGap(this),
new IssueTemplateBananaShowerEndGap(this)
};
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
@ -35,33 +38,35 @@ namespace osu.Game.Rulesets.Catch.Edit.Checks
if (!(hitObjects[i] is BananaShower bananaShower))
continue;
// Skip if the previous hitobject is a banana shower, consecutive spinners are allowed
if (i != 0 && hitObjects[i - 1] is CatchHitObject previousHitObject && !(previousHitObject is BananaShower))
{
double spinnerStartDelta = bananaShower.StartTime - previousHitObject.GetEndTime();
if (spinnerStartDelta < expectedStartDelta)
{
yield return new IssueTemplateSpinnerStartGap(this)
yield return new IssueTemplateBananaShowerStartGap(this)
.Create(spinnerStartDelta, expectedStartDelta, bananaShower, previousHitObject);
}
}
// Skip if the next hitobject is a banana shower, consecutive spinners are allowed
if (hitObjects[i + 1] is CatchHitObject nextHitObject && !(nextHitObject is BananaShower))
{
double spinnerEndDelta = nextHitObject.StartTime - bananaShower.EndTime;
if (spinnerEndDelta < expectedEndDelta)
{
yield return new IssueTemplateSpinnerEndGap(this)
yield return new IssueTemplateBananaShowerEndGap(this)
.Create(spinnerEndDelta, expectedEndDelta, bananaShower, nextHitObject);
}
}
}
}
public abstract class IssueTemplateSpinnerGap : IssueTemplate
public abstract class IssueTemplateBananaShowerGap : IssueTemplate
{
protected IssueTemplateSpinnerGap(ICheck check, IssueType issueType, string unformattedMessage)
protected IssueTemplateBananaShowerGap(ICheck check, IssueType issueType, string unformattedMessage)
: base(check, issueType, unformattedMessage)
{
}
@ -72,18 +77,18 @@ namespace osu.Game.Rulesets.Catch.Edit.Checks
}
}
public class IssueTemplateSpinnerStartGap : IssueTemplateSpinnerGap
public class IssueTemplateBananaShowerStartGap : IssueTemplateBananaShowerGap
{
public IssueTemplateSpinnerStartGap(ICheck check)
: base(check, IssueType.Problem, "There is only {0} ms apart between the start of the spinner and the last object, there should be {1} ms or more.")
public IssueTemplateBananaShowerStartGap(ICheck check)
: base(check, IssueType.Problem, "There is only {0} ms apart between the start of the spinner and the last object, it should not be less than {1} ms.")
{
}
}
public class IssueTemplateSpinnerEndGap : IssueTemplateSpinnerGap
public class IssueTemplateBananaShowerEndGap : IssueTemplateBananaShowerGap
{
public IssueTemplateSpinnerEndGap(ICheck check)
: base(check, IssueType.Problem, "There is only {0} ms apart between the end of the spinner and the next object, there should be {1} ms or more.")
public IssueTemplateBananaShowerEndGap(ICheck check)
: base(check, IssueType.Problem, "There is only {0} ms apart between the end of the spinner and the next object, it should not be less than {1} ms.")
{
}
}