1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Fix test not always checking the final bonus value

Due to the previous logic not waiting until the spinner had completed,
there could be false negatives as the check runs too early, with a
potential additional bonus spin occurring afterwards.
This commit is contained in:
Dean Herbert 2022-02-22 14:11:22 +09:00
parent 692ddd5f52
commit 0d56693b7a

View File

@ -8,13 +8,15 @@ using NUnit.Framework;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Skinning.Default; using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Screens.Play; using osu.Game.Rulesets.Scoring;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.Tests.Mods namespace osu.Game.Rulesets.Osu.Tests.Mods
@ -66,25 +68,45 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
} }
[Test] [Test]
public void TestSpinnerOnlyComplete() => CreateModTest(new ModTestData public void TestSpinnerGetsNoBonusScore()
{
DrawableSpinner spinner = null;
List<JudgementResult> results = new List<JudgementResult>();
CreateModTest(new ModTestData
{ {
Mod = new OsuModSpunOut(), Mod = new OsuModSpunOut(),
Autoplay = false, Autoplay = false,
Beatmap = singleSpinnerBeatmap, Beatmap = singleSpinnerBeatmap,
PassCondition = () => PassCondition = () =>
{ {
var spinner = Player.ChildrenOfType<DrawableSpinner>().SingleOrDefault(); // Bind to the first spinner's results for further tracking.
var gameplayClockContainer = Player.ChildrenOfType<GameplayClockContainer>().SingleOrDefault(); if (spinner == null)
{
// We only care about the first spinner we encounter for this test.
var nextSpinner = Player.ChildrenOfType<DrawableSpinner>().SingleOrDefault();
if (spinner == null || gameplayClockContainer == null) if (nextSpinner == null)
return false; return false;
if (!Precision.AlmostEquals(gameplayClockContainer.CurrentTime, spinner.HitObject.StartTime + spinner.HitObject.Duration, 200.0f)) spinner = nextSpinner;
spinner.OnNewResult += (o, result) => results.Add(result);
results.Clear();
}
// we should only be checking the bonus/progress after the spinner has fully completed.
if (!results.OfType<OsuSpinnerJudgementResult>().Any(r => r.TimeCompleted != null))
return false; return false;
return Precision.AlmostEquals(spinner.Progress, 1.0f, 0.05f) && Precision.AlmostEquals(spinner.GainedBonus.Value, 0, 1); return
results.Any(r => r.Type == HitResult.SmallTickHit)
&& !results.Any(r => r.Type == HitResult.LargeTickHit)
&& Precision.AlmostEquals(spinner.Progress, 1.0f, 0.05f)
&& Precision.AlmostEquals(spinner.GainedBonus.Value, 0, 1);
} }
}); });
}
private Beatmap singleSpinnerBeatmap => new Beatmap private Beatmap singleSpinnerBeatmap => new Beatmap
{ {