From dbdbfc472307caa185da783894dc5b46981e6be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 11 Nov 2021 16:10:33 +0100 Subject: [PATCH] Add failing test case for PP counter not initially updating --- .../TestScenePerformancePointsCounter.cs | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs index 4c48d52acd..84c7f611af 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs @@ -1,9 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Diagnostics; using NUnit.Framework; -using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Rulesets; @@ -20,16 +21,17 @@ namespace osu.Game.Tests.Visual.Gameplay { public class TestScenePerformancePointsCounter : OsuTestScene { - [Cached] - private GameplayState gameplayState; + private DependencyProvidingContainer dependencyContainer; - [Cached] + private GameplayState gameplayState; private ScoreProcessor scoreProcessor; private int iteration; + private Bindable lastJudgementResult = new Bindable(); private PerformancePointsCounter counter; - public TestScenePerformancePointsCounter() + [SetUpSteps] + public void SetUpSteps() => AddStep("create components", () => { var ruleset = CreateRuleset(); @@ -38,32 +40,43 @@ namespace osu.Game.Tests.Visual.Gameplay var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo) .GetPlayableBeatmap(ruleset.RulesetInfo); + lastJudgementResult = new Bindable(); + gameplayState = new GameplayState(beatmap, ruleset); + gameplayState.LastJudgementResult.BindTo(lastJudgementResult); + scoreProcessor = new ScoreProcessor(); - } + + Child = dependencyContainer = new DependencyProvidingContainer + { + RelativeSizeAxes = Axes.Both, + CachedDependencies = new (Type, object)[] + { + (typeof(GameplayState), gameplayState), + (typeof(ScoreProcessor), scoreProcessor) + } + }; + + iteration = 0; + }); protected override Ruleset CreateRuleset() => new OsuRuleset(); - [SetUpSteps] - public void SetUpSteps() + private void createCounter() => AddStep("Create counter", () => { - AddStep("Create counter", () => + dependencyContainer.Child = counter = new PerformancePointsCounter { - iteration = 0; - - Child = counter = new PerformancePointsCounter - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(5), - }; - }); - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(5), + }; + }); [Test] public void TestBasicCounting() { int previousValue = 0; + createCounter(); AddAssert("counter displaying zero", () => counter.Current.Value == 0); @@ -86,6 +99,17 @@ namespace osu.Game.Tests.Visual.Gameplay AddUntilStep("counter non-zero", () => counter.Current.Value > 0); } + [Test] + public void TestCounterUpdatesWithJudgementsBeforeCreation() + { + AddRepeatStep("Add judgement", applyOneJudgement, 10); + + createCounter(); + + AddUntilStep("counter non-zero", () => counter.Current.Value > 0); + AddUntilStep("counter opaque", () => counter.Child.Alpha == 1); + } + private void applyOneJudgement() { var scoreInfo = gameplayState.Score.ScoreInfo; @@ -94,13 +118,14 @@ namespace osu.Game.Tests.Visual.Gameplay scoreInfo.Accuracy = 1; scoreInfo.Statistics[HitResult.Great] = iteration * 1000; - scoreProcessor.ApplyResult(new OsuJudgementResult(new HitObject + lastJudgementResult.Value = new OsuJudgementResult(new HitObject { StartTime = iteration * 10000, }, new OsuJudgement()) { Type = HitResult.Perfect, - }); + }; + scoreProcessor.ApplyResult(lastJudgementResult.Value); iteration++; }